Skip to content

Commit 783bda1

Browse files
committed
[openmp] __kmp_x86_cpuid fix for i386/PIC builds. (llvm#84626)
1 parent fcc33dc commit 783bda1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

openmp/runtime/src/kmp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,9 +1403,19 @@ extern void __kmp_query_cpuid(kmp_cpuinfo_t *p);
14031403
// subleaf is only needed for cache and topology discovery and can be set to
14041404
// zero in most cases
14051405
static inline void __kmp_x86_cpuid(int leaf, int subleaf, struct kmp_cpuid *p) {
1406+
#if KMP_ARCH_X86 && (defined(__pic__) || defined(__PIC__))
1407+
// on i386 arch, the ebx reg. is used by pic, thus we need to preserve from
1408+
// being trashed beforehand
1409+
__asm__ __volatile__("mov %%ebx, %%edi\n"
1410+
"cpuid\n"
1411+
"xchg %%edi, %%ebx\n"
1412+
: "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
1413+
: "a"(leaf), "c"(subleaf));
1414+
#else
14061415
__asm__ __volatile__("cpuid"
14071416
: "=a"(p->eax), "=b"(p->ebx), "=c"(p->ecx), "=d"(p->edx)
14081417
: "a"(leaf), "c"(subleaf));
1418+
#endif
14091419
}
14101420
// Load p into FPU control word
14111421
static inline void __kmp_load_x87_fpu_control_word(const kmp_int16 *p) {

0 commit comments

Comments
 (0)