arch.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Copyright (C) 2013-2014 Povilas Kanapickas <[email protected]>
  2. Distributed under the Boost Software License, Version 1.0.
  3. (See accompanying file LICENSE_1_0.txt or copy at
  4. http://www.boost.org/LICENSE_1_0.txt)
  5. */
  6. #ifndef LIBSIMDPP_DISPATCH_ARCH_H
  7. #define LIBSIMDPP_DISPATCH_ARCH_H
  8. #include <cstdint>
  9. namespace simdpp {
  10. /** Identifies supported instruction set. This type is a bitmask type
  11. Note: the exact values may change release to release.
  12. */
  13. /* The values are assigned in such a way that the result of comparison of two
  14. ORed flag sets is likely identify which instruction set the binary is more
  15. likely to run faster on.
  16. detail::select_version depends on this.
  17. */
  18. enum class Arch : std::uint32_t {
  19. /// Indicates that no SIMD instructions are supported
  20. NONE_NULL = 0,
  21. /// Indicates x86 SSE2 support
  22. X86_SSE2 = 1 << 1,
  23. /// Indicates x86 SSE3 support
  24. X86_SSE3 = 1 << 2,
  25. /// Indicates x86 SSSE3 support
  26. X86_SSSE3 = 1 << 3,
  27. /// Indicates x86 SSE4.1 support
  28. X86_SSE4_1 = 1 << 4,
  29. /// Indicates x86 popcnt instruction support (Note: this is not equivalent
  30. /// to the ABM CPUID flag, Intel includes the instruction into SSE 4.2)
  31. X86_POPCNT_INSN = 1 << 5,
  32. /// Indicates x86 AVX support
  33. X86_AVX = 1 << 6,
  34. /// Indicates x86 AVX2 support
  35. X86_AVX2 = 1 << 7,
  36. /// Indicates x86 FMA3 (Intel) support
  37. X86_FMA3 = 1 << 8,
  38. /// Indicates x86 FMA4 (AMD) support
  39. X86_FMA4 = 1 << 9,
  40. /// Indicates x86 XOP (AMD) support
  41. X86_XOP = 1 << 10,
  42. /// Indicates x86 AVX-512F suppotr
  43. X86_AVX512F = 1 << 11,
  44. /// Indicates x86 AVX-512BW suppotr
  45. X86_AVX512BW = 1 << 12,
  46. /// Indicates x86 AVX-512DQ suppotr
  47. X86_AVX512DQ = 1 << 13,
  48. /// Indicates x86 AVX-512VL suppotr
  49. X86_AVX512VL = 1 << 14,
  50. /// Indicates ARM NEON support (SP and DP floating-point math is executed
  51. /// on VFP)
  52. ARM_NEON = 1 << 0,
  53. /// Indicates ARM NEON support (SP floating-point math is executed on NEON,
  54. /// DP floating-point math is executed on VFP)
  55. ARM_NEON_FLT_SP = 1 << 1,
  56. /// Indicates POWER ALTIVEC support.
  57. POWER_ALTIVEC = 1 << 0,
  58. /// Indicates POWER VSX support available since Power ISA 2.06
  59. POWER_VSX_206 = 1 << 1,
  60. /// Indicates POWER VSX support available since Power ISA 2.07
  61. POWER_VSX_207 = 1 << 2,
  62. /// Indicates MIPS MSA support
  63. MIPS_MSA = 1 << 0
  64. };
  65. /// Bitwise operators for @c Arch
  66. inline Arch& operator|=(Arch& x, const Arch& y)
  67. {
  68. using T = std::uint32_t;
  69. x = static_cast<Arch>(static_cast<T>(x) | static_cast<T>(y));
  70. return x;
  71. }
  72. inline Arch& operator&=(Arch& x, const Arch& y)
  73. {
  74. using T = std::uint32_t;
  75. x = static_cast<Arch>(static_cast<T>(x) & static_cast<T>(y));
  76. return x;
  77. }
  78. inline Arch operator|(const Arch& x, const Arch& y)
  79. {
  80. using T = std::uint32_t;
  81. return static_cast<Arch>(static_cast<T>(x) | static_cast<T>(y));
  82. }
  83. inline Arch operator&(const Arch& x, const Arch& y)
  84. {
  85. using T = std::uint32_t;
  86. return static_cast<Arch>(static_cast<T>(x) & static_cast<T>(y));
  87. }
  88. inline Arch operator~(const Arch& x)
  89. {
  90. using T = std::uint32_t;
  91. return static_cast<Arch>(~static_cast<T>(x));
  92. }
  93. /// Checks if the bits set in @a required is a subset of bits set in @a current.
  94. inline bool test_arch_subset(Arch current, Arch required)
  95. {
  96. if ((~current & required) == Arch::NONE_NULL) {
  97. return true;
  98. }
  99. return false;
  100. }
  101. } // namespace simdpp
  102. #endif