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