Platform.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //-----------------------------------------------------------------------------
  2. // Platform-specific functions and macros
  3. #pragma once
  4. void SetAffinity ( int cpu );
  5. //-----------------------------------------------------------------------------
  6. // Microsoft Visual Studio
  7. #if defined(_MSC_VER)
  8. #define FORCE_INLINE __forceinline
  9. #define NEVER_INLINE __declspec(noinline)
  10. #include <stdlib.h>
  11. #include <math.h> // Has to be included before intrin.h or VC complains about 'ceil'
  12. #include <intrin.h> // for __rdtsc
  13. #include <stdint.h>
  14. #define ROTL32(x,y) _rotl(x,y)
  15. #define ROTL64(x,y) _rotl64(x,y)
  16. #define ROTR32(x,y) _rotr(x,y)
  17. #define ROTR64(x,y) _rotr64(x,y)
  18. #pragma warning(disable : 4127) // "conditional expression is constant" in the if()s for avalanchetest
  19. #pragma warning(disable : 4100)
  20. #pragma warning(disable : 4702)
  21. #define BIG_CONSTANT(x) (x)
  22. // RDTSC == Read Time Stamp Counter
  23. #define rdtsc() __rdtsc()
  24. //-----------------------------------------------------------------------------
  25. // Other compilers
  26. #else // defined(_MSC_VER)
  27. #include <stdlib.h>
  28. #include <stdint.h>
  29. #define FORCE_INLINE inline __attribute__((always_inline))
  30. #define NEVER_INLINE __attribute__((noinline))
  31. inline uint32_t rotl32 ( uint32_t x, int8_t r )
  32. {
  33. return (x << r) | (x >> (32 - r));
  34. }
  35. inline uint64_t rotl64 ( uint64_t x, int8_t r )
  36. {
  37. return (x << r) | (x >> (64 - r));
  38. }
  39. inline uint32_t rotr32 ( uint32_t x, int8_t r )
  40. {
  41. return (x >> r) | (x << (32 - r));
  42. }
  43. inline uint64_t rotr64 ( uint64_t x, int8_t r )
  44. {
  45. return (x >> r) | (x << (64 - r));
  46. }
  47. #define ROTL32(x,y) rotl32(x,y)
  48. #define ROTL64(x,y) rotl64(x,y)
  49. #define ROTR32(x,y) rotr32(x,y)
  50. #define ROTR64(x,y) rotr64(x,y)
  51. #define BIG_CONSTANT(x) (x##LLU)
  52. __inline__ unsigned long long int rdtsc()
  53. {
  54. #ifdef __x86_64__
  55. unsigned int a, d;
  56. __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
  57. return (unsigned long)a | ((unsigned long)d << 32);
  58. #elif defined(__i386__)
  59. unsigned long long int x;
  60. __asm__ volatile ("rdtsc" : "=A" (x));
  61. return x;
  62. #else
  63. #define NO_CYCLE_COUNTER
  64. return 0;
  65. #endif
  66. }
  67. #include <strings.h>
  68. #define _stricmp strcasecmp
  69. #endif // !defined(_MSC_VER)
  70. //-----------------------------------------------------------------------------