summaryrefslogtreecommitdiffstats
path: root/clang/test/Headers/cpuid.c
diff options
context:
space:
mode:
authorAkira Hatanaka <ahatanaka@apple.com>2014-09-20 01:31:09 +0000
committerAkira Hatanaka <ahatanaka@apple.com>2014-09-20 01:31:09 +0000
commit416efb5f909e45f67ee81d382a708fc41666c5c6 (patch)
treedd2f864444150562aa4002e6e377329aab82cd54 /clang/test/Headers/cpuid.c
parentf4dc456eef596bbc7ea281454f34c2dd80ddd2f3 (diff)
downloadbcm5719-llvm-416efb5f909e45f67ee81d382a708fc41666c5c6.tar.gz
bcm5719-llvm-416efb5f909e45f67ee81d382a708fc41666c5c6.zip
Fix bugs in cpuid.h.
This commit makes two changes: - Remove the push and pop instructions that were saving and restoring %ebx before and after cpuid in 32-bit pic mode. We were doing this to ensure we don't lose the GOT address in pic register %ebx, but this isn't necessary because the GOT address is kept in a virtual register. - In 64-bit mode, preserve base register %rbx around cpuid. This fixes PR20311 and rdar://problem/17686779. llvm-svn: 218173
Diffstat (limited to 'clang/test/Headers/cpuid.c')
-rw-r--r--clang/test/Headers/cpuid.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/test/Headers/cpuid.c b/clang/test/Headers/cpuid.c
new file mode 100644
index 00000000000..b0ba07af2f2
--- /dev/null
+++ b/clang/test/Headers/cpuid.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-64
+// RUN: %clang_cc1 %s -ffreestanding -triple i386 -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-32
+
+#include <cpuid.h>
+
+// CHECK-64: {{.*}} call { i32, i32, i32, i32 } asm " xchgq %rbx,${1:q}\0A cpuid\0A xchgq %rbx,${1:q}", "={ax},=r,={cx},={dx},0,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}})
+// CHECK-64: {{.*}} call { i32, i32, i32, i32 } asm " xchgq %rbx,${1:q}\0A cpuid\0A xchgq %rbx,${1:q}", "={ax},=r,={cx},={dx},0,2,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}}, i32 %{{[a-z0-9]+}})
+
+// CHECK-32: {{.*}} call { i32, i32, i32, i32 } asm "cpuid", "={ax},={bx},={cx},={dx},0,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}})
+// CHECK-32: {{.*}} call { i32, i32, i32, i32 } asm "cpuid", "={ax},={bx},={cx},={dx},0,2,~{dirflag},~{fpsr},~{flags}"(i32 %{{[a-z0-9]+}}, i32 %{{[a-z0-9]+}})
+
+unsigned eax0, ebx0, ecx0, edx0;
+unsigned eax1, ebx1, ecx1, edx1;
+
+void test_cpuid(unsigned level, unsigned count) {
+ __cpuid(level, eax1, ebx1, ecx1, edx1);
+ __cpuid_count(level, count, eax0, ebx0, ecx0, edx0);
+}
OpenPOWER on IntegriCloud