[Bf-blender-cvs] [dcf2c6e2250] blender-v2.93-release: Fix build error after recent changes to CPU name detection

Brecht Van Lommel noreply at git.blender.org
Thu Apr 29 16:23:52 CEST 2021


Commit: dcf2c6e225083b3e6145f8dc2b3116ef37d5827f
Author: Brecht Van Lommel
Date:   Thu Apr 29 16:21:30 2021 +0200
Branches: blender-v2.93-release
https://developer.blender.org/rBdcf2c6e225083b3e6145f8dc2b3116ef37d5827f

Fix build error after recent changes to CPU name detection

===================================================================

M	intern/cycles/util/util_system.cpp

===================================================================

diff --git a/intern/cycles/util/util_system.cpp b/intern/cycles/util/util_system.cpp
index 8971867b736..03bc5aea1dd 100644
--- a/intern/cycles/util/util_system.cpp
+++ b/intern/cycles/util/util_system.cpp
@@ -145,7 +145,8 @@ int system_cpu_num_active_group_processors()
   return numaAPI_GetNumCurrentNodesProcessors();
 }
 
-#if !defined(__APPLE__) && (!defined(_WIN32) || defined(FREE_WINDOWS))
+/* Equivalent of Windows __cpuid for x86 processors on other platforms. */
+#if (!defined(_WIN32) || defined(FREE_WINDOWS)) && (defined(__x86_64__) || defined(__i386__))
 static void __cpuid(int data[4], int selector)
 {
 #  if defined(__x86_64__)
@@ -167,12 +168,33 @@ static void __cpuid(int data[4], int selector)
 string system_cpu_brand_string()
 {
 #if defined(__APPLE__)
+  /* Get from system on macOS. */
   char modelname[512] = "";
   size_t bufferlen = 512;
   if (sysctlbyname("machdep.cpu.brand_string", &modelname, &bufferlen, NULL, 0) == 0) {
     return modelname;
   }
-#elif !defined(WIN32) && !defined(__x86_64__) && !defined(__i386__)
+#elif defined(WIN32) || defined(__x86_64__) || defined(__i386__)
+  /* Get from intrinsics on Windows and x86. */
+  char buf[49] = {0};
+  int result[4] = {0};
+
+  __cpuid(result, 0x80000000);
+
+  if (result[0] != 0 && result[0] >= (int)0x80000004) {
+    __cpuid((int *)(buf + 0), 0x80000002);
+    __cpuid((int *)(buf + 16), 0x80000003);
+    __cpuid((int *)(buf + 32), 0x80000004);
+
+    string brand = buf;
+
+    /* Make it a bit more presentable. */
+    brand = string_remove_trademark(brand);
+
+    return brand;
+  }
+#else
+  /* Get from /proc/cpuinfo on Unix systems. */
   FILE *cpuinfo = fopen("/proc/cpuinfo", "r");
   if (cpuinfo != nullptr) {
     char cpuinfo_buf[513] = "";
@@ -192,24 +214,6 @@ string system_cpu_brand_string()
       }
     }
   }
-#else
-  char buf[49] = {0};
-  int result[4] = {0};
-
-  __cpuid(result, 0x80000000);
-
-  if (result[0] != 0 && result[0] >= (int)0x80000004) {
-    __cpuid((int *)(buf + 0), 0x80000002);
-    __cpuid((int *)(buf + 16), 0x80000003);
-    __cpuid((int *)(buf + 32), 0x80000004);
-
-    string brand = buf;
-
-    /* make it a bit more presentable */
-    brand = string_remove_trademark(brand);
-
-    return brand;
-  }
 #endif
   return "Unknown CPU";
 }
@@ -219,7 +223,7 @@ int system_cpu_bits()
   return (sizeof(void *) * 8);
 }
 
-#if defined(__x86_64__) || defined(_M_X64) || defined(i386) || defined(_M_IX86)
+#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
 
 struct CPUCapabilities {
   bool x64;



More information about the Bf-blender-cvs mailing list