-
Notifications
You must be signed in to change notification settings - Fork 149
Open
Description
This code doesn't compile with MSVC:
Lines 1916 to 1923 in 277470b
| void get_time_ns(sail_int *rop, const unit u) | |
| { | |
| struct timespec t; | |
| clock_gettime(CLOCK_REALTIME, &t); | |
| mpz_set_si(*rop, t.tv_sec); | |
| mpz_mul_ui(*rop, *rop, 1000000000); | |
| mpz_add_ui(*rop, *rop, t.tv_nsec); | |
| } |
ChatGPT suggested this which probably needs a bit of tweaking but looks pretty close:
#ifdef _WIN32
#include <windows.h>
#else
#include <time.h>
#endif
void get_time_ns(sail_int *rop, const unit u)
{
#ifdef _WIN32
static LARGE_INTEGER freq;
static int freq_initialized = 0;
LARGE_INTEGER counter;
if (!freq_initialized) {
QueryPerformanceFrequency(&freq);
freq_initialized = 1;
}
QueryPerformanceCounter(&counter);
// Convert to nanoseconds:
// (counter * 1e9) / freq
mpz_set_ui(*rop, counter.QuadPart);
mpz_mul_ui(*rop, *rop, 1000000000ULL);
mpz_tdiv_q_ui(*rop, *rop, freq.QuadPart);
#else
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
mpz_set_si(*rop, t.tv_sec);
mpz_mul_ui(*rop, *rop, 1000000000);
mpz_add_ui(*rop, *rop, t.tv_nsec);
#endif
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels