-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract away platform details from samples.
- Loading branch information
Showing
5 changed files
with
83 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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> | ||
|
||
#elif defined(__GNUC__) | ||
|
||
#include <x86intrin.h> | ||
|
||
#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> | ||
|
||
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 | ||
|