quanta/clocks/
counter.rs
1#[derive(Clone, Debug, Default)]
2pub struct Counter;
3
4#[cfg(all(target_arch = "x86_64", target_feature = "sse2"))]
5impl Counter {
6 pub fn now(&self) -> u64 {
7 unsafe { ::core::arch::x86_64::_rdtsc() }
8 }
9}
10
11#[cfg(target_arch = "aarch64")]
12impl Counter {
13 pub fn now(&self) -> u64 {
14 let count: u64;
15
16 unsafe {
17 ::core::arch::asm!("mrs {}, cntvct_el0", out(reg) count);
18 }
19
20 count
21 }
22}
23
24#[cfg(not(any(
25 all(target_arch = "x86_64", target_feature = "sse2"),
26 target_arch = "aarch64",
27)))]
28impl Counter {
29 pub fn now(&self) -> u64 {
30 panic!("can't use counter without TSC (x86_64) or system counter (ARM) support");
31 }
32}