60 lines
1.4 KiB
Plaintext
60 lines
1.4 KiB
Plaintext
// ARM64 outside macOS, which uses timing_macos.jai. The compiler cannot emit ARM64 assembly yet,
|
|
// so there is no direct read of the generic timer (CNTVCT_EL0 / CNTFRQ_EL0); each OS's clock
|
|
// stands in for it.
|
|
|
|
#if OS == .WINDOWS {
|
|
|
|
// #TODO: Use the ARM64 performance counters directly once the compiler can emit ARM64 assembly.
|
|
|
|
TIMING_SUPPORTED :: true;
|
|
|
|
timing_read_ticks :: () -> u64 #expand {
|
|
counter: W.LARGE_INTEGER;
|
|
W.QueryPerformanceCounter(*counter);
|
|
return cast,no_check(u64) counter.QuadPart;
|
|
}
|
|
|
|
timing_read_tick_frequency_hz :: () -> u64 {
|
|
frequency: W.LARGE_INTEGER;
|
|
if W.QueryPerformanceFrequency(*frequency) == .FALSE return 0;
|
|
return cast,no_check(u64) frequency.QuadPart;
|
|
}
|
|
|
|
} else #if OS == .LINUX {
|
|
|
|
// Nanoseconds from CLOCK_MONOTONIC_RAW, which is unaffected by NTP slewing.
|
|
|
|
TIMING_SUPPORTED :: true;
|
|
|
|
timing_read_ticks :: () -> u64 #expand {
|
|
ts: P.timespec;
|
|
P.clock_gettime(.MONOTONIC_RAW, *ts);
|
|
return cast,no_check(u64) ts.tv_sec * 1_000_000_000 + cast,no_check(u64) ts.tv_nsec;
|
|
}
|
|
|
|
timing_read_tick_frequency_hz :: () -> u64 {
|
|
return 1_000_000_000;
|
|
}
|
|
|
|
} else {
|
|
|
|
// Stub. TIMING_SUPPORTED is false, so timing.jai compiles its timers to nothing here and these
|
|
// are never called.
|
|
|
|
TIMING_SUPPORTED :: false;
|
|
|
|
timing_read_ticks :: () -> u64 #expand {
|
|
return 0;
|
|
}
|
|
|
|
timing_read_tick_frequency_hz :: () -> u64 {
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
#scope_file
|
|
|
|
#if OS == .WINDOWS W :: #import "Windows";
|
|
#if OS == .LINUX P :: #import "POSIX";
|