diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-09-14 17:44:42 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-09-14 17:45:22 +0300 |
commit | 71f28db1b8e26377d56f0eb0aef01f6c6c3afbd0 (patch) | |
tree | 0e7ad0fd5a6e1c5df73c9d9b34e68d67d9a449d1 /src/bitboard.c | |
parent | 1373e30387bf5e8e7858e10c9dee4413bf20d71c (diff) | |
download | j1chess-71f28db1b8e26377d56f0eb0aef01f6c6c3afbd0.tar.gz |
feat: implement bitscanAndReset
Diffstat (limited to 'src/bitboard.c')
-rw-r--r-- | src/bitboard.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/bitboard.c b/src/bitboard.c index e9a7d53..cffe40f 100644 --- a/src/bitboard.c +++ b/src/bitboard.c @@ -25,6 +25,13 @@ inline Bitboard ls1b(Bitboard bb) { /* Log base 2 (aka Trailing Zero Count) * Only works for SINGLE Bitboards * Useful for calculating bit-index of LS1B */ -inline Bitboard bitscan(Bitboard bb) { +inline int bitscan(Bitboard bb) { return pop_count(ls1b(bb) - 1); } + +/* Bitscan forward with LS1B reset */ +inline int bitscanAndReset(Bitboard* bb) { + int idx = bitscan(*bb); + *bb &= *bb - 1; + return idx; +} |