File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ edition = "2018"
1111
1212[dependencies ]
1313libc = " 0.2"
14+ time = " 0.1.42"
15+ chrono = " *"
1416
1517[build-dependencies ]
1618cc = " 1"
Original file line number Diff line number Diff line change 11#include <stdint.h>
22
3+ #if defined(__x86_64__ ) || defined(__amd64__ )
34uint64_t cpucounter (void )
45{
56 uint64_t low , high ;
67 __asm__ __volatile__ ("rdtscp" : "=a" (low ), "=d" (high ) : : "%ecx" );
78 return (high << 32 ) | low ;
89}
10+ #elif defined(__aarch64__ )
11+ uint64_t cpucounter (void )
12+ {
13+ uint64_t virtual_timer_value ;
14+ __asm__ __volatile__ ("mrs %0, cntvct_el0" : "=r" (virtual_timer_value ));
15+ return virtual_timer_value ;
16+ }
17+ #endif
Original file line number Diff line number Diff line change 11use super :: timestamp:: * ;
2-
32pub ( crate ) struct CPUCounter ;
43
54#[ cfg( asm) ]
65#[ inline]
6+ #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
77unsafe fn cpucounter ( ) -> u64 {
88 let ( low, high) : ( u64 , u64 ) ;
99 asm ! ( "rdtscp" : "={eax}" ( low) , "={edx}" ( high) : : "ecx" ) ;
1010 ( high << 32 ) | low
1111}
1212
13+
14+ // https://github.com/google/benchmark/blob/v1.1.0/src/cycleclock.h#L116
15+ #[ cfg( asm) ]
16+ #[ inline]
17+ #[ cfg( any( target_arch = "aarch64" ) ) ]
18+ unsafe fn cpucounter ( ) -> u64 {
19+ let ( vtm) : ( u64 ) ;
20+ asm ! ( "mrs %0, cntvct_el0" : "=r" ( vtm) ) ;
21+ vtm
22+ }
23+
1324#[ cfg( not( asm) ) ]
1425extern "C" {
1526 fn cpucounter ( ) -> u64 ;
You can’t perform that action at this time.
0 commit comments