Commit e0e5eb84 by Jamie Madill Committed by Commit Bot

Fix ScanReverse on posix/32-bit.

The use of the __builtin_clz intrinsic and the associated math were incorrect. Bug: angleproject:5736 Change-Id: I9627c7fc179c0e1bffeecaee39f7a88d9c62d079 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2845232 Commit-Queue: Yuly Novikov <ynovikov@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent e167d453
...@@ -1194,10 +1194,15 @@ inline unsigned long ScanReverse(uint64_t bits) ...@@ -1194,10 +1194,15 @@ inline unsigned long ScanReverse(uint64_t bits)
# if defined(ANGLE_IS_64_BIT_CPU) # if defined(ANGLE_IS_64_BIT_CPU)
return static_cast<unsigned long>(sizeof(uint64_t) * CHAR_BIT - 1 - __builtin_clzll(bits)); return static_cast<unsigned long>(sizeof(uint64_t) * CHAR_BIT - 1 - __builtin_clzll(bits));
# else # else
int tempResult = static_cast<uint32_t>(bits >> 32) == 0 if (static_cast<uint32_t>(bits >> 32) == 0)
? __builtin_clzll(static_cast<int32_t>(bits)) {
: (__builtin_clzll(static_cast<int32_t>(bits >> 32)) + 32); return sizeof(uint32_t) * CHAR_BIT - 1 - __builtin_clz(static_cast<uint32_t>(bits));
return static_cast<unsigned long>(sizeof(uint64_t) * CHAR_BIT - 1 - tempResult); }
else
{
return sizeof(uint32_t) * CHAR_BIT - 1 - __builtin_clz(static_cast<uint32_t>(bits >> 32)) +
32;
}
# endif // defined(ANGLE_IS_64_BIT_CPU) # endif // defined(ANGLE_IS_64_BIT_CPU)
} }
#endif // defined(ANGLE_PLATFORM_POSIX) #endif // defined(ANGLE_PLATFORM_POSIX)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment