aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid CARLIER <devnexen@gmail.com>2024-03-15 04:43:47 +0000
committerGitHub <noreply@github.com>2024-03-14 21:43:47 -0700
commit9b3edb592debc00a5c3fbf7a71f63e07d6af44be (patch)
treeb0594c3ed1e5852851a38d774a2e71725699f540
parent600f7f2ba28f871a7e31a69252e51e01822572cd (diff)
downloadllvm-9b3edb592debc00a5c3fbf7a71f63e07d6af44be.zip
llvm-9b3edb592debc00a5c3fbf7a71f63e07d6af44be.tar.gz
llvm-9b3edb592debc00a5c3fbf7a71f63e07d6af44be.tar.bz2
release/18.x: [openmp] __kmp_x86_cpuid fix for i386/PIC builds. (#84626) (#85053)
-rw-r--r--openmp/runtime/src/kmp.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index e3a1e20..d51ec88 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -1403,9 +1403,19 @@ extern void __kmp_query_cpuid(kmp_cpuinfo_t *p);
// subleaf is only needed for cache and topology discovery and can be set to
// zero in most cases
static inline void __kmp_x86_cpuid(int leaf, int subleaf, struct kmp_cpuid *p) {
+#if KMP_ARCH_X86 && (defined(__pic__) || defined(__PIC__))
+ // on i386 arch, the ebx reg. is used by pic, thus we need to preserve from
+ // being trashed beforehand
+ __asm__ __volatile__("mov %%ebx, %%edi\n"
+ "cpuid\n"
+ "xchg %%edi, %%ebx\n"
+ : "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
+ : "a"(leaf), "c"(subleaf));
+#else
__asm__ __volatile__("cpuid"
: "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
: "a"(leaf), "c"(subleaf));
+#endif
}
// Load p into FPU control word
static inline void __kmp_load_x87_fpu_control_word(const kmp_int16 *p) {