mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
Make enums unsigned
Speed up by using unsigned enums. Passed STC: LLR: 2.98 (-2.94,2.94) <0.00,2.00> Total: 49248 W: 12894 L: 12568 D: 23786 Ptnml(0-2): 119, 5353, 13397, 5593, 16 https://tests.stockfishchess.org/tests/view/695e3e5002d0182a589fe965 closes https://github.com/official-stockfish/Stockfish/pull/6532 No functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
9b8c5c9f75
commit
d852a9195e
+4
-1
@@ -49,12 +49,15 @@ std::string Bitboards::pretty(Bitboard b) {
|
||||
|
||||
std::string s = "+---+---+---+---+---+---+---+---+\n";
|
||||
|
||||
for (Rank r = RANK_8; r >= RANK_1; --r)
|
||||
for (Rank r = RANK_8;; --r)
|
||||
{
|
||||
for (File f = FILE_A; f <= FILE_H; ++f)
|
||||
s += b & make_square(f, r) ? "| X " : "| ";
|
||||
|
||||
s += "| " + std::to_string(1 + r) + "\n+---+---+---+---+---+---+---+---+\n";
|
||||
|
||||
if (r == RANK_1)
|
||||
break;
|
||||
}
|
||||
s += " a b c d e f g h\n";
|
||||
|
||||
|
||||
+4
-4
@@ -47,10 +47,10 @@ template<Direction offset>
|
||||
inline Move* splat_pawn_moves(Move* moveList, Bitboard to_bb) {
|
||||
alignas(64) static constexpr auto SPLAT_TABLE = [] {
|
||||
std::array<Move, 64> table{};
|
||||
for (int8_t i = 0; i < 64; i++)
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
Square from{std::clamp<int8_t>(i - offset, 0, 63)};
|
||||
table[i] = {Move(from, Square{i})};
|
||||
Square from{uint8_t(std::clamp(i - offset, 0, 63))};
|
||||
table[i] = {Move(from, Square{uint8_t(i)})};
|
||||
}
|
||||
return table;
|
||||
}();
|
||||
@@ -68,7 +68,7 @@ inline Move* splat_pawn_moves(Move* moveList, Bitboard to_bb) {
|
||||
inline Move* splat_moves(Move* moveList, Square from, Bitboard to_bb) {
|
||||
alignas(64) static constexpr auto SPLAT_TABLE = [] {
|
||||
std::array<Move, 64> table{};
|
||||
for (int8_t i = 0; i < 64; i++)
|
||||
for (uint8_t i = 0; i < 64; i++)
|
||||
table[i] = {Move(SQUARE_ZERO, Square{i})};
|
||||
return table;
|
||||
}();
|
||||
|
||||
+12
-5
@@ -66,12 +66,15 @@ std::ostream& operator<<(std::ostream& os, const Position& pos) {
|
||||
|
||||
os << "\n +---+---+---+---+---+---+---+---+\n";
|
||||
|
||||
for (Rank r = RANK_8; r >= RANK_1; --r)
|
||||
for (Rank r = RANK_8;; --r)
|
||||
{
|
||||
for (File f = FILE_A; f <= FILE_H; ++f)
|
||||
os << " | " << PieceToChar[pos.piece_on(make_square(f, r))];
|
||||
|
||||
os << " | " << (1 + r) << "\n +---+---+---+---+---+---+---+---+\n";
|
||||
|
||||
if (r == RANK_1)
|
||||
break;
|
||||
}
|
||||
|
||||
os << " a b c d e f g h\n"
|
||||
@@ -416,7 +419,7 @@ string Position::fen() const {
|
||||
int emptyCnt;
|
||||
std::ostringstream ss;
|
||||
|
||||
for (Rank r = RANK_8; r >= RANK_1; --r)
|
||||
for (Rank r = RANK_8;; --r)
|
||||
{
|
||||
for (File f = FILE_A; f <= FILE_H; ++f)
|
||||
{
|
||||
@@ -430,8 +433,9 @@ string Position::fen() const {
|
||||
ss << PieceToChar[piece_on(make_square(f, r))];
|
||||
}
|
||||
|
||||
if (r > RANK_1)
|
||||
ss << '/';
|
||||
if (r == RANK_1)
|
||||
break;
|
||||
ss << '/';
|
||||
}
|
||||
|
||||
ss << (sideToMove == WHITE ? " w " : " b ");
|
||||
@@ -1477,10 +1481,13 @@ void Position::flip() {
|
||||
string f, token;
|
||||
std::stringstream ss(fen());
|
||||
|
||||
for (Rank r = RANK_8; r >= RANK_1; --r) // Piece placement
|
||||
for (Rank r = RANK_8;; --r) // Piece placement
|
||||
{
|
||||
std::getline(ss, token, r > RANK_1 ? '/' : ' ');
|
||||
f.insert(0, token + (f.empty() ? " " : "/"));
|
||||
|
||||
if (r == RANK_1)
|
||||
break;
|
||||
}
|
||||
|
||||
ss >> token; // Active color
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
namespace Stockfish {
|
||||
|
||||
class OptionsMap;
|
||||
enum Color : int8_t;
|
||||
enum Color : uint8_t;
|
||||
|
||||
namespace Search {
|
||||
struct LimitsType;
|
||||
|
||||
+9
-9
@@ -117,13 +117,13 @@ using Bitboard = uint64_t;
|
||||
constexpr int MAX_MOVES = 256;
|
||||
constexpr int MAX_PLY = 246;
|
||||
|
||||
enum Color : int8_t {
|
||||
enum Color : uint8_t {
|
||||
WHITE,
|
||||
BLACK,
|
||||
COLOR_NB = 2
|
||||
};
|
||||
|
||||
enum CastlingRights : int8_t {
|
||||
enum CastlingRights : uint8_t {
|
||||
NO_CASTLING,
|
||||
WHITE_OO,
|
||||
WHITE_OOO = WHITE_OO << 1,
|
||||
@@ -139,7 +139,7 @@ enum CastlingRights : int8_t {
|
||||
CASTLING_RIGHT_NB = 16
|
||||
};
|
||||
|
||||
enum Bound : int8_t {
|
||||
enum Bound : uint8_t {
|
||||
BOUND_NONE,
|
||||
BOUND_UPPER,
|
||||
BOUND_LOWER,
|
||||
@@ -190,13 +190,13 @@ constexpr Value QueenValue = 2538;
|
||||
|
||||
|
||||
// clang-format off
|
||||
enum PieceType : std::int8_t {
|
||||
enum PieceType : std::uint8_t {
|
||||
NO_PIECE_TYPE, PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING,
|
||||
ALL_PIECES = 0,
|
||||
PIECE_TYPE_NB = 8
|
||||
};
|
||||
|
||||
enum Piece : std::int8_t {
|
||||
enum Piece : std::uint8_t {
|
||||
NO_PIECE,
|
||||
W_PAWN = PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
|
||||
B_PAWN = PAWN + 8, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING,
|
||||
@@ -227,7 +227,7 @@ constexpr Depth DEPTH_UNSEARCHED = -2;
|
||||
constexpr Depth DEPTH_ENTRY_OFFSET = -3;
|
||||
|
||||
// clang-format off
|
||||
enum Square : int8_t {
|
||||
enum Square : uint8_t {
|
||||
SQ_A1, SQ_B1, SQ_C1, SQ_D1, SQ_E1, SQ_F1, SQ_G1, SQ_H1,
|
||||
SQ_A2, SQ_B2, SQ_C2, SQ_D2, SQ_E2, SQ_F2, SQ_G2, SQ_H2,
|
||||
SQ_A3, SQ_B3, SQ_C3, SQ_D3, SQ_E3, SQ_F3, SQ_G3, SQ_H3,
|
||||
@@ -255,7 +255,7 @@ enum Direction : int8_t {
|
||||
NORTH_WEST = NORTH + WEST
|
||||
};
|
||||
|
||||
enum File : int8_t {
|
||||
enum File : uint8_t {
|
||||
FILE_A,
|
||||
FILE_B,
|
||||
FILE_C,
|
||||
@@ -267,7 +267,7 @@ enum File : int8_t {
|
||||
FILE_NB
|
||||
};
|
||||
|
||||
enum Rank : int8_t {
|
||||
enum Rank : uint8_t {
|
||||
RANK_1,
|
||||
RANK_2,
|
||||
RANK_3,
|
||||
@@ -406,7 +406,7 @@ constexpr Key make_key(uint64_t seed) {
|
||||
}
|
||||
|
||||
|
||||
enum MoveType {
|
||||
enum MoveType : uint16_t {
|
||||
NORMAL,
|
||||
PROMOTION = 1 << 14,
|
||||
EN_PASSANT = 2 << 14,
|
||||
|
||||
Reference in New Issue
Block a user