1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mozglue/build/arm.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,163 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +/* compile-time and runtime tests for whether to use SSE instructions */ 1.9 + 1.10 +#ifndef mozilla_arm_h_ 1.11 +#define mozilla_arm_h_ 1.12 + 1.13 +// for definition of MFBT_DATA 1.14 +#include "mozilla/Types.h" 1.15 + 1.16 +/* This is patterned after SSE.h, but provides ARMv5E, ARMv6, and NEON 1.17 + detection. For reasons similar to the SSE code, code using NEON (even just 1.18 + in inline asm) needs to be in a separate compilation unit from the regular 1.19 + code, because it requires an ".fpu neon" directive which can't be undone. 1.20 + ARMv5E and ARMv6 code may also require an .arch directive, since by default 1.21 + the assembler refuses to generate code for opcodes outside of its current 1.22 + .arch setting. 1.23 + 1.24 + TODO: Add Thumb, Thumb2, VFP, iwMMX, etc. detection, if we need it. */ 1.25 + 1.26 +#if defined(__GNUC__) && defined(__arm__) 1.27 + 1.28 +# define MOZILLA_ARM_ARCH 3 1.29 + 1.30 +# if defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) \ 1.31 + || defined(_ARM_ARCH_4) 1.32 +# undef MOZILLA_ARM_ARCH 1.33 +# define MOZILLA_ARM_ARCH 4 1.34 +# endif 1.35 + 1.36 +# if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \ 1.37 + || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \ 1.38 + || defined(__ARM_ARCH_5TEJ__) || defined(_ARM_ARCH_5) 1.39 +# undef MOZILLA_ARM_ARCH 1.40 +# define MOZILLA_ARM_ARCH 5 1.41 +# endif 1.42 + 1.43 +# if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \ 1.44 + || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \ 1.45 + || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \ 1.46 + || defined(__ARM_ARCH_6M__) || defined(_ARM_ARCH_6) 1.47 +# undef MOZILLA_ARM_ARCH 1.48 +# define MOZILLA_ARM_ARCH 6 1.49 +# endif 1.50 + 1.51 +# if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \ 1.52 + || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \ 1.53 + || defined(__ARM_ARCH_7EM__) || defined(_ARM_ARCH_7) 1.54 +# undef MOZILLA_ARM_ARCH 1.55 +# define MOZILLA_ARM_ARCH 7 1.56 +# endif 1.57 + 1.58 + 1.59 +# ifdef __GNUC__ 1.60 +# define MOZILLA_MAY_SUPPORT_EDSP 1 1.61 + 1.62 +# if defined(HAVE_ARM_SIMD) 1.63 +# define MOZILLA_MAY_SUPPORT_ARMV6 1 1.64 +# endif 1.65 + 1.66 +# if defined(HAVE_ARM_NEON) 1.67 +# define MOZILLA_MAY_SUPPORT_NEON 1 1.68 +# endif 1.69 + 1.70 +# if defined(HAVE_ARM_SIMD) 1.71 +# define MOZILLA_MAY_SUPPORT_ARMV7 1 1.72 +# endif 1.73 +# endif 1.74 + 1.75 + // When using -mfpu=neon, gcc generates neon instructions. 1.76 + 1.77 +# if defined(__ARM_NEON__) 1.78 +# define MOZILLA_PRESUME_NEON 1 1.79 +# endif 1.80 + 1.81 + // Currently we only have CPU detection for Linux via /proc/cpuinfo 1.82 +# if defined(__linux__) || defined(ANDROID) 1.83 +# define MOZILLA_ARM_HAVE_CPUID_DETECTION 1 1.84 +# endif 1.85 + 1.86 +#elif defined(_MSC_VER) && defined(_M_ARM) 1.87 + 1.88 +# define MOZILLA_ARM_HAVE_CPUID_DETECTION 1 1.89 + // _M_ARM on MSVC has current cpu architecture. 1.90 +# define MOZILLA_ARM_ARCH _M_ARM 1.91 + 1.92 + // MSVC only allows external asm for ARM, so we don't have to rely on 1.93 + // compiler support. 1.94 +# define MOZILLA_MAY_SUPPORT_EDSP 1 1.95 +# if defined(HAVE_ARM_SIMD) 1.96 +# define MOZILLA_MAY_SUPPORT_ARMV6 1 1.97 +# define MOZILLA_MAY_SUPPORT_ARMV7 1 1.98 +# endif 1.99 +# if defined(HAVE_ARM_NEON) 1.100 +# define MOZILLA_MAY_SUPPORT_NEON 1 1.101 +# endif 1.102 + 1.103 +#endif 1.104 + 1.105 +namespace mozilla { 1.106 + 1.107 + namespace arm_private { 1.108 +#if defined(MOZILLA_ARM_HAVE_CPUID_DETECTION) 1.109 +#if !defined(MOZILLA_PRESUME_EDSP) 1.110 + extern bool MFBT_DATA edsp_enabled; 1.111 +#endif 1.112 +#if !defined(MOZILLA_PRESUME_ARMV6) 1.113 + extern bool MFBT_DATA armv6_enabled; 1.114 +#endif 1.115 +#if !defined(MOZILLA_PRESUME_ARMV7) 1.116 + extern bool MFBT_DATA armv7_enabled; 1.117 +#endif 1.118 +#if !defined(MOZILLA_PRESUME_NEON) 1.119 + extern bool MFBT_DATA neon_enabled; 1.120 +#endif 1.121 +#endif 1.122 + } 1.123 + 1.124 +#if defined(MOZILLA_PRESUME_EDSP) 1.125 +# define MOZILLA_MAY_SUPPORT_EDSP 1 1.126 + inline bool supports_edsp() { return true; } 1.127 +#elif defined(MOZILLA_MAY_SUPPORT_EDSP) \ 1.128 + && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION) 1.129 + inline bool supports_edsp() { return arm_private::edsp_enabled; } 1.130 +#else 1.131 + inline bool supports_edsp() { return false; } 1.132 +#endif 1.133 + 1.134 +#if defined(MOZILLA_PRESUME_ARMV6) 1.135 +# define MOZILLA_MAY_SUPPORT_ARMV6 1 1.136 + inline bool supports_armv6() { return true; } 1.137 +#elif defined(MOZILLA_MAY_SUPPORT_ARMV6) \ 1.138 + && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION) 1.139 + inline bool supports_armv6() { return arm_private::armv6_enabled; } 1.140 +#else 1.141 + inline bool supports_armv6() { return false; } 1.142 +#endif 1.143 + 1.144 +#if defined(MOZILLA_PRESUME_ARMV7) 1.145 +# define MOZILLA_MAY_SUPPORT_ARMV7 1 1.146 + inline bool supports_armv7() { return true; } 1.147 +#elif defined(MOZILLA_MAY_SUPPORT_ARMV7) \ 1.148 + && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION) 1.149 + inline bool supports_armv7() { return arm_private::armv7_enabled; } 1.150 +#else 1.151 + inline bool supports_armv7() { return false; } 1.152 +#endif 1.153 + 1.154 +#if defined(MOZILLA_PRESUME_NEON) 1.155 +# define MOZILLA_MAY_SUPPORT_NEON 1 1.156 + inline bool supports_neon() { return true; } 1.157 +#elif defined(MOZILLA_MAY_SUPPORT_NEON) \ 1.158 + && defined(MOZILLA_ARM_HAVE_CPUID_DETECTION) 1.159 + inline bool supports_neon() { return arm_private::neon_enabled; } 1.160 +#else 1.161 + inline bool supports_neon() { return false; } 1.162 +#endif 1.163 + 1.164 +} 1.165 + 1.166 +#endif /* !defined(mozilla_arm_h_) */