mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Greatly speed up SEE
Simply reshuffling the code inverting the condition in next_attacker() yields a miraculous speed up of more than 3% under gcc! On my laptop a bench run goes from 320Knps to 330Knps No functional change.
This commit is contained in:
parent
9cdca7516c
commit
e6d8e74152
1 changed files with 17 additions and 17 deletions
|
@ -106,15 +106,12 @@ void init() {
|
||||||
/// valuable attacker for the side to move, remove the attacker we just found
|
/// valuable attacker for the side to move, remove the attacker we just found
|
||||||
/// from the 'occupied' bitboard and scan for new X-ray attacks behind it.
|
/// from the 'occupied' bitboard and scan for new X-ray attacks behind it.
|
||||||
|
|
||||||
template<PieceType Pt> static FORCE_INLINE
|
template<int Pt> static FORCE_INLINE
|
||||||
PieceType next_attacker(const Bitboard* bb, const Square& to, const Bitboard& stmAttackers,
|
PieceType next_attacker(const Bitboard* bb, const Square& to, const Bitboard& stmAttackers,
|
||||||
Bitboard& occupied, Bitboard& attackers) {
|
Bitboard& occupied, Bitboard& attackers) {
|
||||||
|
|
||||||
const PieceType NextPt = PieceType((int)Pt + 1);
|
if (stmAttackers & bb[Pt])
|
||||||
|
{
|
||||||
if (!(stmAttackers & bb[Pt]))
|
|
||||||
return next_attacker<NextPt>(bb, to, stmAttackers, occupied, attackers);
|
|
||||||
|
|
||||||
Bitboard b = stmAttackers & bb[Pt];
|
Bitboard b = stmAttackers & bb[Pt];
|
||||||
occupied ^= b & ~(b - 1);
|
occupied ^= b & ~(b - 1);
|
||||||
|
|
||||||
|
@ -124,7 +121,9 @@ PieceType next_attacker(const Bitboard* bb, const Square& to, const Bitboard& st
|
||||||
if (Pt == ROOK || Pt == QUEEN)
|
if (Pt == ROOK || Pt == QUEEN)
|
||||||
attackers |= attacks_bb<ROOK>(to, occupied) & (bb[ROOK] | bb[QUEEN]);
|
attackers |= attacks_bb<ROOK>(to, occupied) & (bb[ROOK] | bb[QUEEN]);
|
||||||
|
|
||||||
return Pt;
|
return (PieceType)Pt;
|
||||||
|
}
|
||||||
|
return next_attacker<Pt+1>(bb, to, stmAttackers, occupied, attackers);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> FORCE_INLINE
|
template<> FORCE_INLINE
|
||||||
|
@ -1312,11 +1311,12 @@ int Position::see(Move m) const {
|
||||||
stm = ~stm;
|
stm = ~stm;
|
||||||
stmAttackers = attackers & pieces(stm);
|
stmAttackers = attackers & pieces(stm);
|
||||||
|
|
||||||
// Stop before processing a king capture
|
if (captured == KING)
|
||||||
if (captured == KING && stmAttackers)
|
|
||||||
{
|
{
|
||||||
assert(slIndex < 32);
|
// Stop before processing a king capture
|
||||||
|
if (stmAttackers)
|
||||||
swapList[slIndex++] = QueenValueMg * 16;
|
swapList[slIndex++] = QueenValueMg * 16;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue