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"
11
11
12
12
[dependencies ]
13
13
libc = " 0.2"
14
+ time = " 0.1.42"
15
+ chrono = " *"
14
16
15
17
[build-dependencies ]
16
18
cc = " 1"
Original file line number Diff line number Diff line change 1
1
#include <stdint.h>
2
2
3
+ #if defined(__x86_64__ ) || defined(__amd64__ )
3
4
uint64_t cpucounter (void )
4
5
{
5
6
uint64_t low , high ;
6
7
__asm__ __volatile__ ("rdtscp" : "=a" (low ), "=d" (high ) : : "%ecx" );
7
8
return (high << 32 ) | low ;
8
9
}
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 1
1
use super :: timestamp:: * ;
2
-
3
2
pub ( crate ) struct CPUCounter ;
4
3
5
4
#[ cfg( asm) ]
6
5
#[ inline]
6
+ #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
7
7
unsafe fn cpucounter ( ) -> u64 {
8
8
let ( low, high) : ( u64 , u64 ) ;
9
9
asm ! ( "rdtscp" : "={eax}" ( low) , "={edx}" ( high) : : "ecx" ) ;
10
10
( high << 32 ) | low
11
11
}
12
12
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
+
13
24
#[ cfg( not( asm) ) ]
14
25
extern "C" {
15
26
fn cpucounter ( ) -> u64 ;
You can’t perform that action at this time.
0 commit comments