From 8c3d2e549cff4d9c369c68936e0fce6b7ddc495f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 30 Aug 2018 12:50:36 +0200 Subject: [PATCH] Cycles: Fix detection of CPU brand string on 32 bit platforms The assembler template was backing up and restoring ebx, which is fair enough. However, this did not prevent compiler for putting result variables to ebx. This was causing data corruption. In order to prevent this easiest solution is to list ebx in clobbers for the assembly. --- intern/cycles/util/util_system.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/intern/cycles/util/util_system.cpp b/intern/cycles/util/util_system.cpp index 2428b0b2989..1b039888452 100644 --- a/intern/cycles/util/util_system.cpp +++ b/intern/cycles/util/util_system.cpp @@ -107,25 +107,26 @@ unsigned short system_cpu_process_groups(unsigned short max_groups, #if !defined(_WIN32) || defined(FREE_WINDOWS) static void __cpuid(int data[4], int selector) { -#ifdef __x86_64__ +#if defined(__x86_64__) asm("cpuid" : "=a" (data[0]), "=b" (data[1]), "=c" (data[2]), "=d" (data[3]) : "a"(selector)); -#else -#ifdef __i386__ +#elif defined(__i386__) asm("pushl %%ebx \n\t" - "cpuid \n\t" - "movl %%ebx, %1 \n\t" - "popl %%ebx \n\t" : "=a" (data[0]), "=r" (data[1]), "=c" (data[2]), "=d" (data[3]) : "a"(selector)); + "cpuid \n\t" + "movl %%ebx, %1 \n\t" + "popl %%ebx \n\t" + : "=a" (data[0]), "=r" (data[1]), "=c" (data[2]), "=d" (data[3]) + : "a"(selector) + : "ebx"); #else data[0] = data[1] = data[2] = data[3] = 0; #endif -#endif } #endif string system_cpu_brand_string() { - char buf[48]; - int result[4]; + char buf[48] = {0}; + int result[4] = {0}; __cpuid(result, 0x80000000);