[Mesa-dev] [PATCH 2/4] fix maybe uninitialized regs2 variable in avx detection

Marc Dietrich marvin24 at gmx.de
Fri Mar 23 13:32:56 UTC 2018


This seems to be unlikely to hit, but it is cleaner to move the check
into the block where regs2 gets filled.

Signed-off-by: Marc Dietrich <marvin24 at gmx.de>
---
 src/gallium/auxiliary/util/u_cpu_detect.c | 35 ++++++++++++++++---------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_cpu_detect.c b/src/gallium/auxiliary/util/u_cpu_detect.c
index 6a59f271a8..adbc55ff8b 100644
--- a/src/gallium/auxiliary/util/u_cpu_detect.c
+++ b/src/gallium/auxiliary/util/u_cpu_detect.c
@@ -442,6 +442,24 @@ util_cpu_detect(void)
          cacheline = ((regs2[1] >> 8) & 0xFF) * 8;
          if (cacheline > 0)
             util_cpu_caps.cacheline = cacheline;
+
+         // check for avx512
+         if (((regs2[2] >> 27) & 1) && // OSXSAVE
+             (xgetbv() & (0x7 << 5)) && // OPMASK: upper-256 enabled by OS
+             ((xgetbv() & 6) == 6)) { // XMM/YMM enabled by OS
+            uint32_t regs3[4];
+            cpuid_count(0x00000007, 0x00000000, regs3);
+            util_cpu_caps.has_avx512f    = (regs3[1] >> 16) & 1;
+            util_cpu_caps.has_avx512dq   = (regs3[1] >> 17) & 1;
+            util_cpu_caps.has_avx512ifma = (regs3[1] >> 21) & 1;
+            util_cpu_caps.has_avx512pf   = (regs3[1] >> 26) & 1;
+            util_cpu_caps.has_avx512er   = (regs3[1] >> 27) & 1;
+            util_cpu_caps.has_avx512cd   = (regs3[1] >> 28) & 1;
+            util_cpu_caps.has_avx512bw   = (regs3[1] >> 30) & 1;
+            util_cpu_caps.has_avx512vl   = (regs3[1] >> 31) & 1;
+            util_cpu_caps.has_avx512vbmi = (regs3[2] >>  1) & 1;
+         }
+
       }
       if (util_cpu_caps.has_avx && regs[0] >= 0x00000007) {
          uint32_t regs7[4];
@@ -449,23 +467,6 @@ util_cpu_detect(void)
          util_cpu_caps.has_avx2 = (regs7[1] >> 5) & 1;
       }
 
-      // check for avx512
-      if (((regs2[2] >> 27) & 1) && // OSXSAVE
-          (xgetbv() & (0x7 << 5)) && // OPMASK: upper-256 enabled by OS
-          ((xgetbv() & 6) == 6)) { // XMM/YMM enabled by OS
-         uint32_t regs3[4];
-         cpuid_count(0x00000007, 0x00000000, regs3);
-         util_cpu_caps.has_avx512f    = (regs3[1] >> 16) & 1;
-         util_cpu_caps.has_avx512dq   = (regs3[1] >> 17) & 1;
-         util_cpu_caps.has_avx512ifma = (regs3[1] >> 21) & 1;
-         util_cpu_caps.has_avx512pf   = (regs3[1] >> 26) & 1;
-         util_cpu_caps.has_avx512er   = (regs3[1] >> 27) & 1;
-         util_cpu_caps.has_avx512cd   = (regs3[1] >> 28) & 1;
-         util_cpu_caps.has_avx512bw   = (regs3[1] >> 30) & 1;
-         util_cpu_caps.has_avx512vl   = (regs3[1] >> 31) & 1;
-         util_cpu_caps.has_avx512vbmi = (regs3[2] >>  1) & 1;
-      }
-
       if (regs[1] == 0x756e6547 && regs[2] == 0x6c65746e && regs[3] == 0x49656e69) {
          /* GenuineIntel */
          util_cpu_caps.has_intel = 1;
-- 
2.16.2



More information about the mesa-dev mailing list