ArchitectureDetection.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. // Detect 64/32bit if not user defined.
  3. #if !defined(PLATFORM_ARCH_64) && !defined(PLATFORM_ARCH_32)
  4. #if defined(_AMD64_) || defined(__LP64__) || defined(_WIN64) || defined(_M_ARM64)
  5. #define PLATFORM_ARCH_64 1
  6. #define PLATFORM_ARCH_32 0
  7. #else
  8. #define PLATFORM_ARCH_64 0
  9. #define PLATFORM_ARCH_32 1
  10. #endif
  11. #elif !defined(PLATFORM_ARCH_64)
  12. #define PLATFORM_ARCH_64 (PLATFORM_ARCH_32 ? 0 : 1)
  13. #elif !defined(PLATFORM_ARCH_32)
  14. #define PLATFORM_ARCH_32 (PLATFORM_ARCH_64 ? 0 : 1)
  15. #endif
  16. // Cache line size in bytes
  17. #ifndef PLATFORM_CACHE_LINE_SIZE
  18. #define PLATFORM_CACHE_LINE_SIZE 64
  19. #endif
  20. // Detect endianess if not user defined.
  21. #if !defined(PLATFORM_ARCH_BIG_ENDIAN) && !defined(PLATFORM_ARCH_LITTLE_ENDIAN)
  22. #if defined(__BIG_ENDIAN__)
  23. #define PLATFORM_ARCH_BIG_ENDIAN 1
  24. #define PLATFORM_ARCH_LITTLE_ENDIAN 0
  25. #else
  26. #define PLATFORM_ARCH_BIG_ENDIAN 0
  27. #define PLATFORM_ARCH_LITTLE_ENDIAN 1
  28. #endif
  29. #elif !defined(PLATFORM_ARCH_BIG_ENDIAN)
  30. #define PLATFORM_ARCH_BIG_ENDIAN (PLATFORM_ARCH_LITTLE_ENDIAN ? 0 : 1)
  31. #elif !defined(PLATFORM_ARCH_LITTLE_ENDIAN)
  32. #define PLATFORM_ARCH_LITTLE_ENDIAN (PLATFORM_ARCH_BIG_ENDIAN ? 0 : 1)
  33. #endif
  34. // Detect SIMD features.
  35. // SSE2
  36. // Naming is inherited from Unity and indicates full SSE2 support.
  37. #ifndef PLATFORM_SUPPORTS_SSE
  38. #if (defined(_M_IX86_FP) && _M_IX86_FP == 2) || defined(_M_AMD64) || defined(_M_X64) || defined(__SSE2__)
  39. #define PLATFORM_SUPPORTS_SSE 1
  40. #else
  41. #define PLATFORM_SUPPORTS_SSE 0
  42. #endif
  43. #endif
  44. // NEON
  45. // Indicates general availability. Note that there can be some differences in the exact instructions available.
  46. #ifndef PLATFORM_SUPPORTS_NEON
  47. #if defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(__ARM_NEON_FP) || \
  48. (defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64)))
  49. #define PLATFORM_SUPPORTS_NEON 1
  50. #else
  51. #define PLATFORM_SUPPORTS_NEON 0
  52. #endif
  53. #endif