We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 678a241 + fb25877 commit 5aa0d1eCopy full SHA for 5aa0d1e
src/be_mem.c
@@ -40,10 +40,15 @@
40
#elif defined(_MSC_VER)
41
#define popcount(v) __popcnt(v)
42
43
+// Find a free slot in the space bitmask
44
+// Find the least significant 1-bit in x and return its 1-based index.
45
static int ffs(unsigned x)
46
{
47
unsigned long i;
- return _BitScanForward(&i, x) ? i : 0;
48
+ // NOTE: _BitScanForward is 0-based, see:
49
+ // https://learn.microsoft.com/en-us/cpp/intrinsics/bitscanforward-bitscanforward64?view=msvc-170
50
+ // _BitScanForward(&index, 12) populates index with 2
51
+ return _BitScanForward(&i, x) ? i + 1 : 0;
52
}
53
#else
54
/* https://github.com/hcs0/Hackers-Delight/blob/master/pop.c.txt - count number of 1-bits */
0 commit comments