diff options
| author | Colin Davidson <colrdavidson@gmail.com> | 2023-02-19 20:33:48 -0800 |
|---|---|---|
| committer | Colin Davidson <colrdavidson@gmail.com> | 2023-02-19 20:33:48 -0800 |
| commit | fb735883be43a62ed707d2f7ef56acaa5ccb76fa (patch) | |
| tree | 96c705b90f982792e02d3a38c6fc31f2bc1f3d9e | |
| parent | 6a2ef1f4f3dccaccafd6d28eb9096741e95fb734 (diff) | |
add a tsc frequency get for windows
| -rw-r--r-- | core/time/tsc_windows.odin | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/core/time/tsc_windows.odin b/core/time/tsc_windows.odin new file mode 100644 index 000000000..635aac2c1 --- /dev/null +++ b/core/time/tsc_windows.odin @@ -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 +} |