[Openmp-commits] [openmp] [openmp] __kmp_x86_cpuid fix for i386/PIC builds. (PR #84626)

David CARLIER via Openmp-commits openmp-commits at lists.llvm.org
Sat Mar 9 04:31:08 PST 2024


https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/84626

>From f6d36acf8f68df5ffd63d4b7f746a5153c3d65cf Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Sat, 9 Mar 2024 12:19:36 +0000
Subject: [PATCH] [openmp] __kmp_x86_cpuid fix for i386/PIC builds.

---
 openmp/runtime/src/kmp.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index 1fc31779a217e5..406435af83c628 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -1404,9 +1404,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) {



More information about the Openmp-commits mailing list