htmlaccelEnabled.h (1897B)
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 5 #ifndef mozilla_htmlaccel_htmlaccelEnabled_h 6 #define mozilla_htmlaccel_htmlaccelEnabled_h 7 8 #include "mozilla/Assertions.h" 9 #if defined(__x86_64__) 10 # include "mozilla/SSE.h" 11 #endif 12 13 namespace mozilla::htmlaccel { 14 15 // MOZ_MAY_HAVE_HTMLACCEL gets defined iff `htmlaccelEnabled()` may return 16 // `true`. The purpose is this define is to accommodate builds that don't 17 // link `htmlaccelNotInline.cpp` and have even the most basic constant 18 // propagation turned off so that `htmlaccelEnabled()` statically returning 19 // false isn't enough to remove calls to functions whose definitions are 20 // missing. 21 22 /// This function is appropriate to call when the SIMD path is compiled 23 /// with `HTML_ACCEL_FLAGS`. 24 /// 25 /// Keep this in sync with `HTML_ACCEL_FLAGS` in `toolchain.configure`. 26 inline bool htmlaccelEnabled() { 27 #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 12 28 // __GNUC__ is stuck at 4 in clang, so we need to check __clang__ above. 29 // GCC 12 or newer is required for __builtin_shuffle. 30 return false; 31 #elif defined(__aarch64__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 32 # define MOZ_MAY_HAVE_HTMLACCEL 1 33 return true; 34 #elif defined(__x86_64__) 35 # define MOZ_MAY_HAVE_HTMLACCEL 1 36 bool ret = mozilla::supports_bmi(); 37 if (ret) { 38 // As a micro optimization for the innerHTML getter, don't bother 39 // calling `supports_avx` in release builds, since the implementation 40 // of SSE.h supports_bmi implies supports_avx anyway. 41 MOZ_ASSERT(mozilla::supports_avx(), 42 "supports_bmi is supposed to imply supports_avx"); 43 } 44 return ret; 45 #else 46 return false; 47 #endif 48 } 49 50 } // namespace mozilla::htmlaccel 51 52 #endif // mozilla_htmlaccel_htmlaccelEnabled_h