mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-29 01:14:40 +00:00
add a tsc frequency get for windows
This commit is contained in:
28
core/time/tsc_windows.odin
Normal file
28
core/time/tsc_windows.odin
Normal file
@@ -0,0 +1,28 @@
|
||||
//+private
|
||||
//+build windows
|
||||
package time
|
||||
|
||||
import win32 "core:sys/windows"
|
||||
|
||||
_get_tsc_frequency :: proc "contextless" () -> u64 {
|
||||
@(static) frequency : u64 = 0
|
||||
if frequency > 0 {
|
||||
return frequency
|
||||
}
|
||||
|
||||
qpc_begin: win32.LARGE_INTEGER
|
||||
win32.QueryPerformanceCounter(&qpc_begin)
|
||||
tsc_begin := intrinsics.read_cycle_counter()
|
||||
|
||||
win32.Sleep(2)
|
||||
|
||||
qpc_end: win32.LARGE_INTEGER
|
||||
win32.QueryPerformanceCounter(&qpc_end)
|
||||
tsc_end := intrinsics.read_cycle_counter()
|
||||
|
||||
qpc_frequency: win32.LARGE_INTEGER
|
||||
win32.QueryPerformanceFrequency(&qpc_frequency)
|
||||
|
||||
frequency = ((tsc_end - tsc_begin) * qpc_frequency) / (qpc_end - qpc_begin)
|
||||
return frequency
|
||||
}
|
||||
Reference in New Issue
Block a user