]> git.sesse.net Git - narabu/blob - ryg_rans/platform.h
More fixes of hard-coded values.
[narabu] / ryg_rans / platform.h
1 // Just some platform utilities.
2 #ifndef PLATFORM_H_INCLUDED
3 #define PLATFORM_H_INCLUDED
4
5 // x86 intrinsics (__rdtsc etc.)
6
7 #if defined(_MSC_VER)
8
9 #define _CRT_SECURE_NO_DEPRECATE
10 #include <intrin.h>
11 #define ALIGNSPEC(type,name,alignment) __declspec(align(alignment)) type name
12
13 #elif defined(__GNUC__)
14
15 #include <x86intrin.h>
16 #define ALIGNSPEC(type,name,alignment) type name __attribute__((aligned(alignment)))
17
18 #else
19 #error Unknown compiler!
20 #endif
21
22 // Timer
23
24 #if defined(_WIN32)
25
26 #define WIN32_LEAN_AND_MEAN
27 #define NOMINMAX
28 #include <Windows.h>
29
30 #define PRIu64 "llu"
31
32 double timer()
33 {
34     LARGE_INTEGER ctr, freq;
35     QueryPerformanceCounter(&ctr);
36     QueryPerformanceFrequency(&freq);
37     return 1.0 * ctr.QuadPart / freq.QuadPart;
38 }
39
40 #elif defined(__linux__)
41
42 #define __STDC_FORMAT_MACROS
43 #include <time.h>
44 #include <inttypes.h>
45 #include <assert.h>
46
47 static inline double timer()
48 {
49     timespec ts;
50     ts.tv_sec = 0;
51     ts.tv_nsec = 0;
52     int status = clock_gettime(CLOCK_MONOTONIC, &ts);
53     assert(status == 0);
54     return double(ts.tv_sec) + 1.0e-9 * double(ts.tv_nsec);
55 }
56
57 #else
58
59 #error Unknown platform!
60
61 #endif
62
63 #endif // PLATFORM_H_INCLUDED
64