1 //-----------------------------------------------------------------------------
2 // Platform-specific functions and macros
3
4 #pragma once
5
6 void 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
43 #define FORCE_INLINE inline __attribute__((always_inline))
44 #define NEVER_INLINE __attribute__((noinline))
45
rotl32(uint32_t x,int8_t r)46 inline uint32_t rotl32 ( uint32_t x, int8_t r )
47 {
48 return (x << r) | (x >> (32 - r));
49 }
50
rotl64(uint64_t x,int8_t r)51 inline uint64_t rotl64 ( uint64_t x, int8_t r )
52 {
53 return (x << r) | (x >> (64 - r));
54 }
55
rotr32(uint32_t x,int8_t r)56 inline uint32_t rotr32 ( uint32_t x, int8_t r )
57 {
58 return (x >> r) | (x << (32 - r));
59 }
60
rotr64(uint64_t x,int8_t r)61 inline 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
rdtsc()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);
79 #elif defined(__i386__)
80 unsigned long long int x;
81 __asm__ volatile ("rdtsc" : "=A" (x));
82 return x;
83 #else
84 #define NO_CYCLE_COUNTER
85 return 0;
86 #endif
87 }
88
89 #include <strings.h>
90 #define _stricmp strcasecmp
91
92 #endif // !defined(_MSC_VER)
93
94 //-----------------------------------------------------------------------------
95