Bug 1359333 - detect aes-ni support, r?froydnj draft
authorFranziskus Kiefer <franziskuskiefer@gmail.com>
Fri, 31 Mar 2017 18:59:56 +0200
changeset 573027 f225cd3894ef4398940626e8170ec07922456613
parent 572730 0b255199db9d6a6f189b89b7906f99155bde3726
child 627203 f3367bf63af903014e81f74a8020646bdeecaf29
push id57277
push userfranziskuskiefer@gmail.com
push dateFri, 05 May 2017 07:37:17 +0000
reviewersfroydnj
bugs1359333
milestone55.0a1
Bug 1359333 - detect aes-ni support, r?froydnj MozReview-Commit-ID: 4cCVIntG9bD
mozglue/build/SSE.cpp
mozglue/build/SSE.h
--- a/mozglue/build/SSE.cpp
+++ b/mozglue/build/SSE.cpp
@@ -195,12 +195,16 @@ namespace sse_private {
 #if !defined(MOZILLA_PRESUME_AVX)
   bool avx_enabled = has_avx();
 #endif
 
 #if !defined(MOZILLA_PRESUME_AVX2)
   bool avx2_enabled = has_avx() && has_cpuid_bits(7u, ebx, (1u<<5));
 #endif
 
+#if !defined(MOZILLA_PRESUME_AES)
+  bool aes_enabled = has_cpuid_bits(1u, ecx, (1u<<25));
+#endif
+
 #endif
 
 } // namespace sse_private
 } // namespace mozilla
--- a/mozglue/build/SSE.h
+++ b/mozglue/build/SSE.h
@@ -26,16 +26,17 @@
  *    mozilla::supports_sse2
  *    mozilla::supports_sse3
  *    mozilla::supports_ssse3
  *    mozilla::supports_sse4a
  *    mozilla::supports_sse4_1
  *    mozilla::supports_sse4_2
  *    mozilla::supports_avx
  *    mozilla::supports_avx2
+ *    mozilla::supports_aes
  *
  * If you're writing code using inline assembly, you should guard it with a
  * call to one of these functions.  For instance:
  *
  *   if (mozilla::supports_sse2()) {
  *     asm(" ... ");
  *   }
  *   else {
@@ -131,16 +132,17 @@
 #ifdef __AVX__
   // It's ok to use AVX instructions based on the -march option.
   #define MOZILLA_PRESUME_AVX 1
 #endif
 #ifdef __AVX2__
   // It's ok to use AVX instructions based on the -march option.
   #define MOZILLA_PRESUME_AVX2 1
 #endif
+// There's no preprocessor symbol for __AES__
 
 
 
 #ifdef HAVE_CPUID_H
   #define MOZILLA_SSE_HAVE_CPUID_DETECTION
 #endif
 
 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64))
@@ -212,16 +214,19 @@ namespace mozilla {
     extern bool MFBT_DATA sse4_2_enabled;
 #endif
 #if !defined(MOZILLA_PRESUME_AVX)
     extern bool MFBT_DATA avx_enabled;
 #endif
 #if !defined(MOZILLA_PRESUME_AVX2)
     extern bool MFBT_DATA avx2_enabled;
 #endif
+#if !defined(MOZILLA_PRESUME_AES)
+    extern bool MFBT_DATA aes_enabled;
+#endif
 
 
 #endif
   } // namespace sse_private
 
 #if defined(MOZILLA_PRESUME_MMX)
 #define MOZILLA_MAY_SUPPORT_MMX 1
   inline bool supports_mmx() { return true; }
@@ -321,12 +326,22 @@ namespace mozilla {
   inline bool supports_avx2() { return true; }
 #elif defined(MOZILLA_SSE_HAVE_CPUID_DETECTION)
 #define MOZILLA_MAY_SUPPORT_AVX2 1
   inline bool supports_avx2() { return sse_private::avx2_enabled; }
 #else
   inline bool supports_avx2() { return false; }
 #endif
 
+#if defined(MOZILLA_PRESUME_AES)
+#define MOZILLA_MAY_SUPPORT_AES 1
+  inline bool supports_aes() { return true; }
+#elif defined(MOZILLA_SSE_HAVE_CPUID_DETECTION)
+#define MOZILLA_MAY_SUPPORT_AES 1
+  inline bool supports_aes() { return sse_private::aes_enabled; }
+#else
+  inline bool supports_aes() { return false; }
+#endif
+
 
 } // namespace mozilla
 
 #endif /* !defined(mozilla_SSE_h_) */