Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Micro-optimize pop_lsb() for 64bit case

On Intel, perhaps due to 'lea' instruction this way of
zeroing the lsb of *b seems faster than a shift+negate.

On perft (where any speed difference is magnified) I
got a 6% speed up on my Intel i5 64bit.

Suggested by Hongzhi Cheng.

No functional change.
  • Loading branch information...
commit 94ecdef8ac7855e7a44efd7890c7e8f8d5819397 1 parent e3b0327
@mcostalba authored
Showing with 1 addition and 1 deletion.
  1. +1 −1  src/bitboard.h
View
2  src/bitboard.h
@@ -280,7 +280,7 @@ FORCE_INLINE Square msb(Bitboard b) {
FORCE_INLINE Square pop_lsb(Bitboard* b) {
const Square s = lsb(*b);
- *b &= ~(1ULL << s);
+ *b &= *b - 1;
return s;
}

2 comments on commit 94ecdef

@hongzhicheng

Very nice!

Here is another issue that might need your attention, which is quite similar to one of those issues I pointed out before.

In function connected_moves(), Stockfish has

// Case 4: The destination square for m2 is defended by the moving piece in m1
p1 = pos.piece_on(t1);
if (pos.attacks_from(p1, t1) & t2)
    return true;

It is possible that square f2 will block an x-ray attack from p1, so it would be correct if we modify the above code as:

// Case 4: The destination square for m2 is defended by the moving piece in m1
p1 = pos.piece_on(t1);
if (pos.attacks_from(p1, t1, pos.pieces() ^ f2) & t2)
    return true;

Thanks a lot

Hongzhi

@mcostalba
Owner
Please sign in to comment.
Something went wrong with that request. Please try again.