blob: 6d0f0df9fa1b274d078b35bb64cfb3cabec9f8fa [file] [log] [blame]
tanjent@gmail.comf3b78972012-03-01 03:38:55 +00001//-----------------------------------------------------------------------------
2// Platform-specific functions and macros
3
4#pragma once
5
6void SetAffinity ( int cpu );
7
8//-----------------------------------------------------------------------------
9// Microsoft Visual Studio
10
11#if defined(_MSC_VER)
12
13#define FORCE_INLINE __forceinline
14#define NEVER_INLINE __declspec(noinline)
15
16#include <stdlib.h>
17#include <math.h> // Has to be included before intrin.h or VC complains about 'ceil'
18#include <intrin.h> // for __rdtsc
19#include "pstdint.h"
20
21#define ROTL32(x,y) _rotl(x,y)
22#define ROTL64(x,y) _rotl64(x,y)
23#define ROTR32(x,y) _rotr(x,y)
24#define ROTR64(x,y) _rotr64(x,y)
25
26#pragma warning(disable : 4127) // "conditional expression is constant" in the if()s for avalanchetest
27#pragma warning(disable : 4100)
28#pragma warning(disable : 4702)
29
30#define BIG_CONSTANT(x) (x)
31
32// RDTSC == Read Time Stamp Counter
33
34#define rdtsc() __rdtsc()
35
36//-----------------------------------------------------------------------------
37// Other compilers
38
39#else // defined(_MSC_VER)
40
41#include <stdint.h>
42
tanjent@gmail.com6f63a482013-05-10 18:34:06 +000043#define FORCE_INLINE inline __attribute__((always_inline))
tanjent@gmail.comf3b78972012-03-01 03:38:55 +000044#define NEVER_INLINE __attribute__((noinline))
45
46inline uint32_t rotl32 ( uint32_t x, int8_t r )
47{
48 return (x << r) | (x >> (32 - r));
49}
50
51inline uint64_t rotl64 ( uint64_t x, int8_t r )
52{
53 return (x << r) | (x >> (64 - r));
54}
55
56inline uint32_t rotr32 ( uint32_t x, int8_t r )
57{
58 return (x >> r) | (x << (32 - r));
59}
60
61inline uint64_t rotr64 ( uint64_t x, int8_t r )
62{
63 return (x >> r) | (x << (64 - r));
64}
65
66#define ROTL32(x,y) rotl32(x,y)
67#define ROTL64(x,y) rotl64(x,y)
68#define ROTR32(x,y) rotr32(x,y)
69#define ROTR64(x,y) rotr64(x,y)
70
71#define BIG_CONSTANT(x) (x##LLU)
72
73__inline__ unsigned long long int rdtsc()
74{
75#ifdef __x86_64__
76 unsigned int a, d;
77 __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
78 return (unsigned long)a | ((unsigned long)d << 32);
tanjent@gmail.come813f9b2012-05-11 06:19:58 +000079#elif defined(__i386__)
tanjent@gmail.comf3b78972012-03-01 03:38:55 +000080 unsigned long long int x;
81 __asm__ volatile ("rdtsc" : "=A" (x));
82 return x;
tanjent@gmail.come813f9b2012-05-11 06:19:58 +000083#else
84#define NO_CYCLE_COUNTER
85 return 0;
tanjent@gmail.comf3b78972012-03-01 03:38:55 +000086#endif
87}
88
89#include <strings.h>
90#define _stricmp strcasecmp
91
92#endif // !defined(_MSC_VER)
93
94//-----------------------------------------------------------------------------