michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* compile-time and runtime tests for whether to use SSE instructions */ michael@0: michael@0: #ifndef mozilla_arm_h_ michael@0: #define mozilla_arm_h_ michael@0: michael@0: // for definition of MFBT_DATA michael@0: #include "mozilla/Types.h" michael@0: michael@0: /* This is patterned after SSE.h, but provides ARMv5E, ARMv6, and NEON michael@0: detection. For reasons similar to the SSE code, code using NEON (even just michael@0: in inline asm) needs to be in a separate compilation unit from the regular michael@0: code, because it requires an ".fpu neon" directive which can't be undone. michael@0: ARMv5E and ARMv6 code may also require an .arch directive, since by default michael@0: the assembler refuses to generate code for opcodes outside of its current michael@0: .arch setting. michael@0: michael@0: TODO: Add Thumb, Thumb2, VFP, iwMMX, etc. detection, if we need it. */ michael@0: michael@0: #if defined(__GNUC__) && defined(__arm__) michael@0: michael@0: # define MOZILLA_ARM_ARCH 3 michael@0: michael@0: # if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) \ michael@0: || defined(_ARM_ARCH_4) michael@0: # undef MOZILLA_ARM_ARCH michael@0: # define MOZILLA_ARM_ARCH 4 michael@0: # endif michael@0: michael@0: # if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \ michael@0: || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \ michael@0: || defined(__ARM_ARCH_5TEJ__) || defined(_ARM_ARCH_5) michael@0: # undef MOZILLA_ARM_ARCH michael@0: # define MOZILLA_ARM_ARCH 5 michael@0: # endif michael@0: michael@0: # if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \ michael@0: || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \ michael@0: || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \ michael@0: || defined(__ARM_ARCH_6M__) || defined(_ARM_ARCH_6) michael@0: # undef MOZILLA_ARM_ARCH michael@0: # define MOZILLA_ARM_ARCH 6 michael@0: # endif michael@0: michael@0: # if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \ michael@0: || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \ michael@0: || defined(__ARM_ARCH_7EM__) || defined(_ARM_ARCH_7) michael@0: # undef MOZILLA_ARM_ARCH michael@0: # define MOZILLA_ARM_ARCH 7 michael@0: # endif michael@0: michael@0: michael@0: # ifdef __GNUC__ michael@0: # define MOZILLA_MAY_SUPPORT_EDSP 1 michael@0: michael@0: # if defined(HAVE_ARM_SIMD) michael@0: # define MOZILLA_MAY_SUPPORT_ARMV6 1 michael@0: # endif michael@0: michael@0: # if defined(HAVE_ARM_NEON) michael@0: # define MOZILLA_MAY_SUPPORT_NEON 1 michael@0: # endif michael@0: michael@0: # if defined(HAVE_ARM_SIMD) michael@0: # define MOZILLA_MAY_SUPPORT_ARMV7 1 michael@0: # endif michael@0: # endif michael@0: michael@0: // When using -mfpu=neon, gcc generates neon instructions. michael@0: michael@0: # if defined(__ARM_NEON__) michael@0: # define MOZILLA_PRESUME_NEON 1 michael@0: # endif michael@0: michael@0: // Currently we only have CPU detection for Linux via /proc/cpuinfo michael@0: # if defined(__linux__) || defined(ANDROID) michael@0: # define MOZILLA_ARM_HAVE_CPUID_DETECTION 1 michael@0: # endif michael@0: michael@0: #elif defined(_MSC_VER) && defined(_M_ARM) michael@0: michael@0: # define MOZILLA_ARM_HAVE_CPUID_DETECTION 1 michael@0: // _M_ARM on MSVC has current cpu architecture. michael@0: # define MOZILLA_ARM_ARCH _M_ARM michael@0: michael@0: // MSVC only allows external asm for ARM, so we don't have to rely on michael@0: // compiler support. michael@0: # define MOZILLA_MAY_SUPPORT_EDSP 1 michael@0: # if defined(HAVE_ARM_SIMD) michael@0: # define MOZILLA_MAY_SUPPORT_ARMV6 1 michael@0: # define MOZILLA_MAY_SUPPORT_ARMV7 1 michael@0: # endif michael@0: # if defined(HAVE_ARM_NEON) michael@0: # define MOZILLA_MAY_SUPPORT_NEON 1 michael@0: # endif michael@0: michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace arm_private { michael@0: #if defined(MOZILLA_ARM_HAVE_CPUID_DETECTION) michael@0: #if !defined(MOZILLA_PRESUME_EDSP) michael@0: extern bool MFBT_DATA edsp_enabled; michael@0: #endif michael@0: #if !defined(MOZILLA_PRESUME_ARMV6) michael@0: extern bool MFBT_DATA armv6_enabled; michael@0: #endif michael@0: #if !defined(MOZILLA_PRESUME_ARMV7) michael@0: extern bool MFBT_DATA armv7_enabled; michael@0: #endif michael@0: #if !defined(MOZILLA_PRESUME_NEON) michael@0: extern bool MFBT_DATA neon_enabled; michael@0: #endif michael@0: #endif michael@0: } michael@0: michael@0: #if defined(MOZILLA_PRESUME_EDSP) michael@0: # define MOZILLA_MAY_SUPPORT_EDSP 1 michael@0: inline bool supports_edsp() { return true; } michael@0: #elif defined(MOZILLA_MAY_SUPPORT_EDSP) \ michael@0: && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION) michael@0: inline bool supports_edsp() { return arm_private::edsp_enabled; } michael@0: #else michael@0: inline bool supports_edsp() { return false; } michael@0: #endif michael@0: michael@0: #if defined(MOZILLA_PRESUME_ARMV6) michael@0: # define MOZILLA_MAY_SUPPORT_ARMV6 1 michael@0: inline bool supports_armv6() { return true; } michael@0: #elif defined(MOZILLA_MAY_SUPPORT_ARMV6) \ michael@0: && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION) michael@0: inline bool supports_armv6() { return arm_private::armv6_enabled; } michael@0: #else michael@0: inline bool supports_armv6() { return false; } michael@0: #endif michael@0: michael@0: #if defined(MOZILLA_PRESUME_ARMV7) michael@0: # define MOZILLA_MAY_SUPPORT_ARMV7 1 michael@0: inline bool supports_armv7() { return true; } michael@0: #elif defined(MOZILLA_MAY_SUPPORT_ARMV7) \ michael@0: && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION) michael@0: inline bool supports_armv7() { return arm_private::armv7_enabled; } michael@0: #else michael@0: inline bool supports_armv7() { return false; } michael@0: #endif michael@0: michael@0: #if defined(MOZILLA_PRESUME_NEON) michael@0: # define MOZILLA_MAY_SUPPORT_NEON 1 michael@0: inline bool supports_neon() { return true; } michael@0: #elif defined(MOZILLA_MAY_SUPPORT_NEON) \ michael@0: && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION) michael@0: inline bool supports_neon() { return arm_private::neon_enabled; } michael@0: #else michael@0: inline bool supports_neon() { return false; } michael@0: #endif michael@0: michael@0: } michael@0: michael@0: #endif /* !defined(mozilla_arm_h_) */