swr: fix win32 intrinsics
authorMichel Zou <xantares09@hotmail.com>
Wed, 10 Mar 2021 20:25:05 +0000 (21:25 +0100)
committerMarge Bot <eric+marge@anholt.net>
Mon, 15 Mar 2021 13:19:09 +0000 (13:19 +0000)
The doc doesnt mention Index is altered when mask is null.
This is consistent with both llvm & migw implementations.

Reviewed-by: Jan Zielinski <jan.zielinski@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9502>

src/gallium/drivers/swr/rasterizer/common/os.h

index b949625..ed42e1e 100644 (file)
@@ -109,6 +109,8 @@ static inline void AlignedFree(void* p)
 extern "C" {
 inline unsigned char _BitScanForward64(unsigned long* Index, uint64_t Mask)
 {
+    if (Mask == 0)
+      return 0;
 #ifdef __GNUC__
     *Index = __builtin_ctzll(Mask);
 #else
@@ -117,11 +119,13 @@ inline unsigned char _BitScanForward64(unsigned long* Index, uint64_t Mask)
       if ((1ULL << i) & Mask)
         *Index = i;
 #endif
-    return (Mask != 0);
+    return 1;
 }
 
 inline unsigned char _BitScanReverse64(unsigned long* Index, uint64_t Mask)
 {
+    if (Mask == 0)
+      return 0;
 #ifdef __GNUC__
     *Index = 63 - __builtin_clzll(Mask);
 #else
@@ -130,7 +134,7 @@ inline unsigned char _BitScanReverse64(unsigned long* Index, uint64_t Mask)
       if ((1ULL << i) & Mask)
         *Index = i;
 #endif
-    return (Mask != 0);
+    return 1;
 }
 }
 #endif
@@ -230,26 +234,34 @@ static INLINE void _mm256_storeu2_m128i(__m128i* hi, __m128i* lo, __m256i a)
 
 inline unsigned char _BitScanForward64(unsigned long* Index, uint64_t Mask)
 {
+    if (Mask == 0)
+      return 0;
     *Index = __builtin_ctzll(Mask);
-    return (Mask != 0);
+    return 1;
 }
 
 inline unsigned char _BitScanForward(unsigned long* Index, uint32_t Mask)
 {
+    if (Mask == 0)
+      return 0;
     *Index = __builtin_ctz(Mask);
-    return (Mask != 0);
+    return 1;
 }
 
 inline unsigned char _BitScanReverse64(unsigned long* Index, uint64_t Mask)
 {
+    if (Mask == 0)
+      return 0;
     *Index = 63 - __builtin_clzll(Mask);
-    return (Mask != 0);
+    return 1;
 }
 
 inline unsigned char _BitScanReverse(unsigned long* Index, uint32_t Mask)
 {
+    if (Mask == 0)
+      return 0;
     *Index = 31 - __builtin_clz(Mask);
-    return (Mask != 0);
+    return 1;
 }
 
 inline void* AlignedMalloc(size_t size, size_t alignment)