From a2038c1a011552c3d56d3b318780f7f5eadaf05d Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 17 Jan 2023 21:30:50 -0700 Subject: [PATCH] apply if constexpr to additional instances as a form of documentation, and a hint to the compiler. closes https://github.com/official-stockfish/Stockfish/pull/4345 No functional change --- AUTHORS | 1 + src/evaluate.cpp | 10 +++++----- src/movegen.cpp | 16 ++++++++-------- src/movepick.cpp | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/AUTHORS b/AUTHORS index 87fed7b8..42ba5930 100644 --- a/AUTHORS +++ b/AUTHORS @@ -101,6 +101,7 @@ Jerry Donald Watson (jerrydonaldwatson) jjoshua2 Jonathan Calovski (Mysseno) Jonathan Buladas Dumale (SFisGOD) +Jonathan McDermid (jonathanmcdermid) Joost VandeVondele (vondele) Jörg Oster (joergoster) Joseph Ellis (jhellis3) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 6db977a4..8683182c 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -388,10 +388,10 @@ namespace { template template Score Evaluation::pieces() { - constexpr Color Them = ~Us; - constexpr Direction Down = -pawn_push(Us); - constexpr Bitboard OutpostRanks = (Us == WHITE ? Rank4BB | Rank5BB | Rank6BB - : Rank5BB | Rank4BB | Rank3BB); + constexpr Color Them = ~Us; + [[maybe_unused]] constexpr Direction Down = -pawn_push(Us); + [[maybe_unused]] constexpr Bitboard OutpostRanks = (Us == WHITE ? Rank4BB | Rank5BB | Rank6BB + : Rank5BB | Rank4BB | Rank3BB); Bitboard b1 = pos.pieces(Us, Pt); Bitboard b, bb; Score score = SCORE_ZERO; @@ -430,7 +430,7 @@ namespace { int mob = popcount(b & mobilityArea[Us]); mobility[Us] += MobilityBonus[Pt - 2][mob]; - if (Pt == BISHOP || Pt == KNIGHT) + if constexpr (Pt == BISHOP || Pt == KNIGHT) { // Bonus if the piece is on an outpost square or can reach one // Bonus for knights (UncontestedOutpost) if few relevant targets diff --git a/src/movegen.cpp b/src/movegen.cpp index a960f863..47154164 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -26,12 +26,12 @@ namespace Stockfish { namespace { template - ExtMove* make_promotions(ExtMove* moveList, Square to) { + ExtMove* make_promotions(ExtMove* moveList, [[maybe_unused]] Square to) { - if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS) + if constexpr (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS) *moveList++ = make(to - D, to, QUEEN); - if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS) + if constexpr (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS) { *moveList++ = make(to - D, to, ROOK); *moveList++ = make(to - D, to, BISHOP); @@ -60,18 +60,18 @@ namespace { Bitboard pawnsNotOn7 = pos.pieces(Us, PAWN) & ~TRank7BB; // Single and double pawn pushes, no promotions - if (Type != CAPTURES) + if constexpr (Type != CAPTURES) { Bitboard b1 = shift(pawnsNotOn7) & emptySquares; Bitboard b2 = shift(b1 & TRank3BB) & emptySquares; - if (Type == EVASIONS) // Consider only blocking squares + if constexpr (Type == EVASIONS) // Consider only blocking squares { b1 &= target; b2 &= target; } - if (Type == QUIET_CHECKS) + if constexpr (Type == QUIET_CHECKS) { // To make a quiet check, you either make a direct check by pushing a pawn // or push a blocker pawn that is not on the same file as the enemy king. @@ -102,7 +102,7 @@ namespace { Bitboard b2 = shift(pawnsOn7) & enemies; Bitboard b3 = shift(pawnsOn7) & emptySquares; - if (Type == EVASIONS) + if constexpr (Type == EVASIONS) b3 &= target; while (b1) @@ -116,7 +116,7 @@ namespace { } // Standard and en passant captures - if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS) + if constexpr (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS) { Bitboard b1 = shift(pawnsNotOn7) & enemies; Bitboard b2 = shift(pawnsNotOn7) & enemies; diff --git a/src/movepick.cpp b/src/movepick.cpp index dbe67357..65155a73 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -158,7 +158,7 @@ Move MovePicker::select(Pred filter) { while (cur < endMoves) { - if (T == Best) + if constexpr (T == Best) std::swap(*cur, *std::max_element(cur, endMoves)); if (*cur != ttMove && filter()) -- 2.39.2