diff --git a/src/libsodium/sodium/runtime.c b/src/libsodium/sodium/runtime.c index f23959a6..d9baa541 100644 --- a/src/libsodium/sodium/runtime.c +++ b/src/libsodium/sodium/runtime.c @@ -46,19 +46,23 @@ _cpuid(unsigned int cpu_info[4U], const unsigned int cpu_info_type) #ifdef _MSC_VER __cpuidex((int *) cpu_info, cpu_info_type, 0); #elif defined(HAVE_CPUID) -# ifdef __x86_64__ - __asm__ __volatile__ ("xchgq %%rbx, %q1; cpuid; xchgq %%rbx, %q1" : - "=a" (cpu_info[0]), "=&r" (cpu_info[1]), - "=c" (cpu_info[2]), "=d" (cpu_info[3]) : - "a" (cpu_info_type), "c" (0U)); -# elif defined(__i386__) + cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; +# if defined(__i386__) && !defined(__x86_64__) + __asm__ __volatile__ ("pushfl; pushfl; " + "popl %0; " + "movl %0, %1; xorl %2, %0; " + "pushl %0; " + "popfl; pushfl; popl %0; popfl" : + "=&r" (cpu_info[0]), "=&r" (cpu_info[1]) : + "i" (0x200000)); + if (((cpu_info[0] ^ cpu_info[1]) & 0x200000) == 0x0) { + return; + } +# endif __asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" : "=a" (cpu_info[0]), "=&r" (cpu_info[1]), "=c" (cpu_info[2]), "=d" (cpu_info[3]) : "0" (cpu_info_type), "2" (0U)); -# else - cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; -# endif #else cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; #endif