begin adding tsc frequency getters

This commit is contained in:
Colin Davidson
2023-02-19 20:08:11 -08:00
parent a28699b42d
commit 051c9cb564
4 changed files with 221 additions and 3 deletions
+22 -1
View File
@@ -1,6 +1,7 @@
package time
import "core:runtime"
import "core:intrinsics"
Tick :: struct {
_nsec: i64, // relative amount
@@ -40,6 +41,26 @@ _tick_duration_end :: proc "contextless" (d: ^Duration, t: Tick) {
d^ = tick_since(t)
}
when ODIN_ARCH == .amd64 {
_has_invariant_tsc :: proc "contextless" () -> bool {
eax, _, _, _ := intrinsics.x86_cpuid(0x80_000_000, 0)
// Is this processor *really* ancient?
if eax < 0x80_000_007 {
return false
}
// check if the invariant TSC bit is set
_, _, _, edx := intrinsics.x86_cpuid(0x80_000_007, 0)
return (edx & (1 << 8)) != 0
}
} else {
_has_invariant_tsc :: proc "contextless" () -> bool {
return false
}
}
/*
Benchmark helpers
*/
@@ -94,4 +115,4 @@ benchmark :: proc(options: ^Benchmark_Options, allocator := context.allocator) -
options->teardown(allocator) or_return
}
return
}
}