mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
begin adding tsc frequency getters
This commit is contained in:
+22
-1
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user