quanta/
detection.rs

1#[allow(dead_code)]
2#[cfg(all(target_arch = "x86_64", target_feature = "sse2"))]
3pub fn has_counter_support() -> bool {
4    let cpuid = raw_cpuid::CpuId::new();
5    let has_invariant_tsc = cpuid
6        .get_advanced_power_mgmt_info()
7        .map_or(false, |apm| apm.has_invariant_tsc());
8    let has_rdtscp = cpuid
9        .get_extended_processor_and_feature_identifiers()
10        .map_or(false, |epf| epf.has_rdtscp());
11
12    has_invariant_tsc && has_rdtscp
13}
14
15#[cfg(all(target_arch = "aarch64", not(target_os = "ios")))]
16pub fn has_counter_support() -> bool {
17    // AArch64 implies ARMv8 or above, where the system counter is always present.
18    //
19    // However, the instruction necessary to read the raw counter (`mrs`) is not always available,
20    // specifically in the case of iOS.
21    true
22}
23
24#[allow(dead_code)]
25#[cfg(not(any(
26    all(target_arch = "x86_64", target_feature = "sse2"),
27    all(target_arch = "aarch64", not(target_os = "ios"))
28)))]
29pub fn has_counter_support() -> bool {
30    false
31}