[Mesa-dev] [PATCH 01/14] swr: [rasterizer common] workaround clang for windows __cpuid() bug

Tim Rowley timothy.o.rowley at intel.com
Fri Jun 17 19:25:41 UTC 2016


---
 src/gallium/drivers/swr/rasterizer/common/isa.hpp | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/swr/rasterizer/common/isa.hpp b/src/gallium/drivers/swr/rasterizer/common/isa.hpp
index ef38179..31ea787 100644
--- a/src/gallium/drivers/swr/rasterizer/common/isa.hpp
+++ b/src/gallium/drivers/swr/rasterizer/common/isa.hpp
@@ -30,7 +30,11 @@
 #include <string>
 #include <algorithm>
 
-#if defined(_WIN32)
+// Clang for Windows does supply an intrin.h with __cpuid intrinsics, however...
+// It seems to not realize that a write to "b" (ebx) will kill the value in rbx.
+// This attempts to use the "native" clang / gcc intrinsics instead of the windows
+// compatible ones.
+#if defined(_MSC_VER) && !defined(__clang__)
 #include <intrin.h>
 #else
 #include <string.h>
@@ -128,7 +132,7 @@ private:
 
             // Calling __cpuid with 0x0 as the function_id argument
             // gets the number of the highest valid function ID.
-#if defined(_WIN32)
+#if defined(_MSC_VER) && !defined(__clang__)
             __cpuid(cpui.data(), 0);
             nIds_ = cpui[0];
 #else
@@ -137,8 +141,8 @@ private:
 
             for (int i = 0; i <= nIds_; ++i)
             {
-#if defined(_WIN32)
-                __cpuidex(cpui.data(), i, 0);
+#if defined(_MSC_VER) && !defined(__clang__)
+				__cpuidex(cpui.data(), i, 0);
 #else
                 int *data = cpui.data();
                 __cpuid_count(i, 0, data[0], data[1], data[2], data[3]);
@@ -178,8 +182,8 @@ private:
 
             // Calling __cpuid with 0x80000000 as the function_id argument
             // gets the number of the highest valid extended ID.
-#if defined(_WIN32)
-            __cpuid(cpui.data(), 0x80000000);
+#if defined(_MSC_VER) && !defined(__clang__)
+			__cpuid(cpui.data(), 0x80000000);
             nExIds_ = cpui[0];
 #else
             nExIds_ = __get_cpuid_max(0x80000000, NULL);
@@ -190,8 +194,8 @@ private:
 
             for (unsigned i = 0x80000000; i <= nExIds_; ++i)
             {
-#if defined(_WIN32)
-                __cpuidex(cpui.data(), i, 0);
+#if defined(_MSC_VER) && !defined(__clang__)
+				__cpuidex(cpui.data(), i, 0);
 #else
                 int *data = cpui.data();
                 __cpuid_count(i, 0, data[0], data[1], data[2], data[3]);
-- 
1.9.1



More information about the mesa-dev mailing list