arm.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /* compile-time and runtime tests for whether to use SSE instructions */
  5. #ifndef mozilla_arm_h_
  6. #define mozilla_arm_h_
  7. // for definition of MFBT_DATA
  8. #include "mozilla/Types.h"
  9. /* This is patterned after SSE.h, but provides ARMv5E, ARMv6, and NEON
  10. detection. For reasons similar to the SSE code, code using NEON (even just
  11. in inline asm) needs to be in a separate compilation unit from the regular
  12. code, because it requires an ".fpu neon" directive which can't be undone.
  13. ARMv5E and ARMv6 code may also require an .arch directive, since by default
  14. the assembler refuses to generate code for opcodes outside of its current
  15. .arch setting.
  16. TODO: Add Thumb, Thumb2, VFP, iwMMX, etc. detection, if we need it. */
  17. #if defined(__GNUC__) && defined(__arm__)
  18. # define MOZILLA_ARM_ARCH 3
  19. # if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) \
  20. || defined(_ARM_ARCH_4)
  21. # undef MOZILLA_ARM_ARCH
  22. # define MOZILLA_ARM_ARCH 4
  23. # endif
  24. # if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
  25. || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
  26. || defined(__ARM_ARCH_5TEJ__) || defined(_ARM_ARCH_5)
  27. # undef MOZILLA_ARM_ARCH
  28. # define MOZILLA_ARM_ARCH 5
  29. # endif
  30. # if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
  31. || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
  32. || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \
  33. || defined(__ARM_ARCH_6M__) || defined(_ARM_ARCH_6)
  34. # undef MOZILLA_ARM_ARCH
  35. # define MOZILLA_ARM_ARCH 6
  36. # endif
  37. # if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
  38. || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
  39. || defined(__ARM_ARCH_7EM__) || defined(_ARM_ARCH_7)
  40. # undef MOZILLA_ARM_ARCH
  41. # define MOZILLA_ARM_ARCH 7
  42. # endif
  43. # ifdef __GNUC__
  44. # define MOZILLA_MAY_SUPPORT_EDSP 1
  45. # if defined(HAVE_ARM_SIMD)
  46. # define MOZILLA_MAY_SUPPORT_ARMV6 1
  47. # endif
  48. # if defined(HAVE_ARM_NEON)
  49. # define MOZILLA_MAY_SUPPORT_NEON 1
  50. # endif
  51. # if defined(HAVE_ARM_SIMD)
  52. # define MOZILLA_MAY_SUPPORT_ARMV7 1
  53. # endif
  54. # endif
  55. // When using -mfpu=neon, gcc generates neon instructions.
  56. # if defined(__ARM_NEON__)
  57. # define MOZILLA_PRESUME_NEON 1
  58. # endif
  59. // Currently we only have CPU detection for Linux via /proc/cpuinfo
  60. # if defined(__linux__)
  61. # define MOZILLA_ARM_HAVE_CPUID_DETECTION 1
  62. # endif
  63. #endif
  64. namespace mozilla {
  65. namespace arm_private {
  66. #if defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
  67. #if !defined(MOZILLA_PRESUME_EDSP)
  68. extern bool MFBT_DATA edsp_enabled;
  69. #endif
  70. #if !defined(MOZILLA_PRESUME_ARMV6)
  71. extern bool MFBT_DATA armv6_enabled;
  72. #endif
  73. #if !defined(MOZILLA_PRESUME_ARMV7)
  74. extern bool MFBT_DATA armv7_enabled;
  75. #endif
  76. #if !defined(MOZILLA_PRESUME_NEON)
  77. extern bool MFBT_DATA neon_enabled;
  78. #endif
  79. #endif
  80. } // namespace arm_private
  81. #if defined(MOZILLA_PRESUME_EDSP)
  82. # define MOZILLA_MAY_SUPPORT_EDSP 1
  83. inline bool supports_edsp() { return true; }
  84. #elif defined(MOZILLA_MAY_SUPPORT_EDSP) \
  85. && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
  86. inline bool supports_edsp() { return arm_private::edsp_enabled; }
  87. #else
  88. inline bool supports_edsp() { return false; }
  89. #endif
  90. #if defined(MOZILLA_PRESUME_ARMV6)
  91. # define MOZILLA_MAY_SUPPORT_ARMV6 1
  92. inline bool supports_armv6() { return true; }
  93. #elif defined(MOZILLA_MAY_SUPPORT_ARMV6) \
  94. && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
  95. inline bool supports_armv6() { return arm_private::armv6_enabled; }
  96. #else
  97. inline bool supports_armv6() { return false; }
  98. #endif
  99. #if defined(MOZILLA_PRESUME_ARMV7)
  100. # define MOZILLA_MAY_SUPPORT_ARMV7 1
  101. inline bool supports_armv7() { return true; }
  102. #elif defined(MOZILLA_MAY_SUPPORT_ARMV7) \
  103. && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
  104. inline bool supports_armv7() { return arm_private::armv7_enabled; }
  105. #else
  106. inline bool supports_armv7() { return false; }
  107. #endif
  108. #if defined(MOZILLA_PRESUME_NEON)
  109. # define MOZILLA_MAY_SUPPORT_NEON 1
  110. inline bool supports_neon() { return true; }
  111. #elif defined(MOZILLA_MAY_SUPPORT_NEON) \
  112. && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION)
  113. inline bool supports_neon() { return arm_private::neon_enabled; }
  114. #else
  115. inline bool supports_neon() { return false; }
  116. #endif
  117. } // namespace mozilla
  118. #endif /* !defined(mozilla_arm_h_) */