swr/rast: Flip BitScanReverse index calculation
authorAlok Hota <alok.hota@intel.com>
Tue, 14 Aug 2018 17:36:00 +0000 (12:36 -0500)
committerAlok Hota <alok.hota@intel.com>
Fri, 15 Feb 2019 20:53:58 +0000 (14:53 -0600)
The intrinsic returns the number of leading zeros, not the bit number of
the first nonzero, so just flip it based on the mask size

Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/common/os.h

index d685467906b2270294902c6389125986291ea4eb..314d8184374707659828ffb261fe2c09e4609eca 100644 (file)
@@ -202,13 +202,13 @@ inline unsigned char _BitScanForward(unsigned int* Index, unsigned int Mask)
 
 inline unsigned char _BitScanReverse(unsigned long* Index, unsigned long Mask)
 {
-    *Index = __builtin_clz(Mask);
+    *Index = 63 - __builtin_clz(Mask);
     return (Mask != 0);
 }
 
 inline unsigned char _BitScanReverse(unsigned int* Index, unsigned int Mask)
 {
-    *Index = __builtin_clz(Mask);
+    *Index = 31 - __builtin_clz(Mask);
     return (Mask != 0);
 }