|
1 | 1 | //! Architecture agnostic processor features
|
2 | 2 |
|
3 |
| -/// Read time counter using [`llvmint::readcyclecounter`] |
| 3 | +#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))] |
| 4 | +use crate::utils::current_nanos; |
| 5 | + |
| 6 | +// TODO: Add more architectures, using C code, see |
| 7 | +// https://github.com/google/benchmark/blob/master/src/cycleclock.h |
| 8 | +// Or using llvm intrinsics (if they ever should become available in stable rust?) |
| 9 | + |
| 10 | +/// Read a timestamp for measurements. |
4 | 11 | ///
|
5 |
| -/// This function is a wrapper around [`llvmint`] to make it easier to test various |
6 |
| -/// implementations of reading a cycle counter. In this way, an experiment only has to |
| 12 | +/// This function is a wrapper around different ways to get a timestamp, fast |
| 13 | +/// In this way, an experiment only has to |
7 | 14 | /// change this implementation rather than every instead of [`cpu::read_time_counter`]
|
8 |
| -#[cfg(target_arch = "x86_64")] |
| 15 | +/// It is using [`rdtsc`] on `x86_64` and `x86`. |
| 16 | +#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] |
9 | 17 | #[must_use]
|
10 | 18 | pub fn read_time_counter() -> u64 {
|
11 | 19 | unsafe { core::arch::x86_64::_rdtsc() }
|
12 | 20 | }
|
| 21 | + |
| 22 | +/// Read a timestamp for measurements. |
| 23 | +/// |
| 24 | +/// This function is a wrapper around different ways to get a timestamp, fast |
| 25 | +/// In this way, an experiment only has to |
| 26 | +/// change this implementation rather than every instead of [`cpu::read_time_counter`] |
| 27 | +/// On unsupported architectures, it's falling back to normal system time, in millis. |
| 28 | +#[cfg(not(any(target_arch = "x86_64", target_arch = "x86")))] |
| 29 | +pub fn read_time_counter() -> u64 { |
| 30 | + current_nanos() |
| 31 | +} |
0 commit comments