]> git.sesse.net Git - stockfish/blobdiff - src/bitboard.h
Refactor pawns shelter and storm
[stockfish] / src / bitboard.h
index 7a39a5009c5571ccf0ef68b5d90792acc353de9b..6dd07d5407f85bc431328915c8c459e3a043d7f7 100644 (file)
@@ -57,11 +57,19 @@ inline Bitboard operator&(Bitboard b, Square s) {
 }
 
 inline Bitboard& operator|=(Bitboard& b, Square s) {
-  return b |= SquareBB[s], b;
+  return b |= SquareBB[s];
 }
 
 inline Bitboard& operator^=(Bitboard& b, Square s) {
-  return b ^= SquareBB[s], b;
+  return b ^= SquareBB[s];
+}
+
+inline Bitboard operator|(Bitboard b, Square s) {
+  return b | SquareBB[s];
+}
+
+inline Bitboard operator^(Bitboard b, Square s) {
+  return b ^ SquareBB[s];
 }
 
 
@@ -199,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.
@@ -208,9 +224,15 @@ inline Bitboard same_color_squares(Square s) {
 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
 
 FORCE_INLINE Square first_1(Bitboard b) {
-   unsigned long index;
-   _BitScanForward64(&index, b);
-   return (Square) index;
+  unsigned long index;
+  _BitScanForward64(&index, b);
+  return (Square) index;
+}
+
+FORCE_INLINE Square last_1(Bitboard b) {
+  unsigned long index;
+  _BitScanReverse64(&index, b);
+  return (Square) index;
 }
 #else
 
@@ -219,6 +241,12 @@ FORCE_INLINE Square first_1(Bitboard b) { // Assembly code by Heinz van Saanen
   __asm__("bsfq %1, %0": "=r"(dummy): "rm"(b) );
   return (Square) dummy;
 }
+
+FORCE_INLINE Square last_1(Bitboard b) {
+  Bitboard dummy;
+  __asm__("bsrq %1, %0": "=r"(dummy): "rm"(b) );
+  return (Square) dummy;
+}
 #endif
 
 FORCE_INLINE Square pop_1st_bit(Bitboard* b) {
@@ -230,11 +258,11 @@ FORCE_INLINE Square pop_1st_bit(Bitboard* b) {
 #else // if !defined(USE_BSFQ)
 
 extern Square first_1(Bitboard b);
+extern Square last_1(Bitboard b);
 extern Square pop_1st_bit(Bitboard* b);
 
 #endif
 
-
 extern void print_bitboard(Bitboard b);
 extern void bitboards_init();