Introduce single_bit() helper

Self-documenting code instead of a tricky
bitwise tweak, not known by everybody.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2012-03-04 23:26:08 +01:00
parent cf0561d31a
commit 19540c9ee8
4 changed files with 11 additions and 4 deletions

View File

@@ -207,6 +207,14 @@ inline Bitboard same_color_squares(Square s) {
}
/// single_bit() returns true if in the 'b' bitboard is set a single bit (or if
/// b == 0).
inline bool single_bit(Bitboard b) {
return !(b & (b - 1));
}
/// first_1() finds the least significant nonzero bit in a nonzero bitboard.
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
/// nonzero bitboard.