Skip to content

Commit facb89a

Browse files
authored
[openmp] __kmp_x86_cpuid fix for i386/PIC builds. (#84626)
1 parent 6f7e940 commit facb89a

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

0 commit comments

Comments
 (0)