diff --git a/ChangeLog b/ChangeLog index 26509c52..5a0f2cda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ Changes in primecount-7.14, 2024-06-19 * int128_t.hpp: Rename namespace port to pstd (portable std namespace). +* cpuid.hpp: Prevent memory reordering. * Sieve.hpp: Tune AVX512 code. * multiarch_avx512_vpopcnt.cmake: Tune AVX512 code. diff --git a/include/cpuid.hpp b/include/cpuid.hpp index 92b81002..87e85b13 100644 --- a/include/cpuid.hpp +++ b/include/cpuid.hpp @@ -28,19 +28,23 @@ inline void run_cpuid(int eax, int ecx, int* abcd) #if defined(__i386__) && \ defined(__PIC__) /* in case of PIC under 32-bit EBX cannot be clobbered */ - __asm__ ("movl %%ebx, %%edi;" - "cpuid;" - "xchgl %%ebx, %%edi;" - : "=D" (ebx), - "+a" (eax), - "+c" (ecx), - "=d" (edx)); + __asm__ __volatile__ ( + "movl %%ebx, %%edi;" + "cpuid;" + "xchgl %%ebx, %%edi;" + : "=D" (ebx), + "+a" (eax), + "+c" (ecx), + "=d" (edx) + : "memory" + ); #else - __asm__ ("cpuid;" - : "+b" (ebx), - "+a" (eax), - "+c" (ecx), - "=d" (edx)); + __asm__ __volatile__ ( + "cpuid" + : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) + : "0" (eax), "2" (ecx) + : "memory" + ); #endif abcd[0] = eax;