MSVC's _BitScan* functions return a boolean indicating whether any
bits were set in the input, and we were previously asserting that
they returned true, per our API. This is correct. However, other
platforms simply assert that the input is non-zero, so do that to be
more consistent.
Noted while investigating a hypothesis from Ranier Vilela about
undefined behavior, but this is not his proposed .
Discussion: https://www.postgresql.org/message-id/CAEudQAoDhUZyKGJ1vbMGcgVUOcsixe-%3DjcVaDWarqkUg163D2w%40mail.gmail.com
unsigned long result;
bool non_zero;
+ Assert(word != 0);
+
non_zero = _BitScanReverse(&result, word);
- Assert(non_zero);
return (int) result;
#else
int shift = 32 - 8;
unsigned long result;
bool non_zero;
+ Assert(word != 0);
+
non_zero = _BitScanReverse64(&result, word);
- Assert(non_zero);
return (int) result;
#else
int shift = 64 - 8;
unsigned long result;
bool non_zero;
+ Assert(word != 0);
+
non_zero = _BitScanForward(&result, word);
- Assert(non_zero);
return (int) result;
#else
int result = 0;
unsigned long result;
bool non_zero;
+ Assert(word != 0);
+
non_zero = _BitScanForward64(&result, word);
- Assert(non_zero);
return (int) result;
#else
int result = 0;