[compiler-rt] r274868 - Check cpuid supported for i386.

Alina Sbirlea via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 09:18:39 PDT 2016


Author: asbirlea
Date: Fri Jul  8 11:18:39 2016
New Revision: 274868

URL: http://llvm.org/viewvc/llvm-project?rev=274868&view=rev
Log:
Check cpuid supported for i386.

Summary:

Reviewers:

Subscribers:

Modified:
    compiler-rt/trunk/lib/builtins/cpu_model.c

Modified: compiler-rt/trunk/lib/builtins/cpu_model.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/cpu_model.c?rev=274868&r1=274867&r2=274868&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/cpu_model.c (original)
+++ compiler-rt/trunk/lib/builtins/cpu_model.c Fri Jul  8 11:18:39 2016
@@ -119,6 +119,31 @@ enum ProcessorFeatures {
   FEATURE_EM64T
 };
 
+static bool isCpuIdSupported() {
+#if defined(i386) || defined(__i386__)
+  int __cpuid_supported;
+  __asm("  pushfl\n"
+        "  popl   %%eax\n"
+        "  movl   %%eax,%%ecx\n"
+        "  xorl   $0x00200000,%%eax\n"
+        "  pushl  %%eax\n"
+        "  popfl\n"
+        "  pushfl\n"
+        "  popl   %%eax\n"
+        "  movl   $0,%0\n"
+        "  cmpl   %%eax,%%ecx\n"
+        "  je     1f\n"
+        "  movl   $1,%0\n"
+        "1:"
+        : "=r"(__cpuid_supported)
+        :
+        : "eax", "ecx");
+  if (!__cpuid_supported)
+    return 0;
+#endif
+  return 1;
+}
+
 #if defined(i386) || defined(__i386__) || defined(__x86__) ||                  \
     defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) ||            \
     defined(_M_X64)
@@ -706,7 +731,7 @@ struct __processor_model {
   unsigned int __cpu_type;
   unsigned int __cpu_subtype;
   unsigned int __cpu_features[1];
-} __cpu_model = { 0, 0, 0, { 0 } };
+} __cpu_model = {0, 0, 0, {0}};
 
 /* A constructor function that is sets __cpu_model and __cpu_features with
    the right values.  This needs to run only once.  This constructor is
@@ -726,6 +751,9 @@ __cpu_indicator_init(void) {
   if (__cpu_model.__cpu_vendor)
     return 0;
 
+  if (!isCpuIdSupported())
+    return -1;
+
   /* Assume cpuid insn present. Run in level 0 to get vendor id. */
   if (getX86CpuIDAndInfo(0, &MaxLeaf, &Vendor, &ECX, &EDX)) {
     __cpu_model.__cpu_vendor = VENDOR_OTHER;




More information about the llvm-commits mailing list