Skip to content

Commit 295941f

Browse files
KazAppsPikaCat-OuO
authored andcommitted
Make enums unsigned
Speed up by using unsigned enums. No functional change
1 parent ee11e80 commit 295941f

File tree

7 files changed

+30
-20
lines changed

7 files changed

+30
-20
lines changed

src/bitboard.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ std::string Bitboards::pretty(Bitboard b) {
5858

5959
std::string s = "+---+---+---+---+---+---+---+---+---+\n";
6060

61-
for (Rank r = RANK_9; r >= RANK_0; --r)
61+
for (Rank r = RANK_9;; --r)
6262
{
6363
for (File f = FILE_A; f <= FILE_I; ++f)
6464
s += b & make_square(f, r) ? "| X " : "| ";
6565

6666
s += "| " + std::to_string(r) + "\n+---+---+---+---+---+---+---+---+---+\n";
67+
68+
if (r == RANK_0)
69+
break;
6770
}
6871
s += " a b c d e f g h i\n";
6972

src/movegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ inline Move* write_moves(Move* moveList, uint32_t mask, __m512i vector) {
4545
inline Move* splat_moves(Move* moveList, Square from, Bitboard to_bb) {
4646
alignas(64) static constexpr auto SPLAT_TABLE = [] {
4747
std::array<Move, 90> table{};
48-
for (int8_t i = 0; i < 90; i++)
48+
for (uint8_t i = 0; i < 90; i++)
4949
table[i] = {Move(SQUARE_ZERO, Square{i})};
5050
return table;
5151
}();

src/nnue/features/full_threats.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ auto ThreatOffsets = []() {
5454
// clang-format on
5555

5656
// Initialize threat offsets to be all Dimension
57-
for (size_t i = 0; i < PIECE_NB; ++i)
58-
for (size_t j = 0; j < SQUARE_NB; ++j)
59-
for (size_t k = 0; k < SQUARE_NB; ++k)
60-
for (size_t l = 0; l < PIECE_NB; ++l)
57+
for (uint8_t i = 0; i < PIECE_NB; ++i)
58+
for (uint8_t j = 0; j < SQUARE_NB; ++j)
59+
for (uint8_t k = 0; k < SQUARE_NB; ++k)
60+
for (uint8_t l = 0; l < PIECE_NB; ++l)
6161
ThreatOffsets[i][j][k][l] = FullThreats::Dimensions;
6262

6363
int cumulativeOffset = 0;

src/position.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ std::ostream& operator<<(std::ostream& os, const Position& pos) {
6060

6161
os << "\n +---+---+---+---+---+---+---+---+---+\n";
6262

63-
for (Rank r = RANK_9; r >= RANK_0; --r)
63+
for (Rank r = RANK_9;; --r)
6464
{
6565
for (File f = FILE_A; f <= FILE_I; ++f)
6666
os << " | " << PieceToChar[pos.piece_on(make_square(f, r))];
6767

6868
os << " | " << int(r) << "\n +---+---+---+---+---+---+---+---+---+\n";
69+
70+
if (r == RANK_0)
71+
break;
6972
}
7073

7174
os << " a b c d e f g h i\n"
@@ -256,7 +259,7 @@ string Position::fen() const {
256259
int emptyCnt;
257260
std::ostringstream ss;
258261

259-
for (Rank r = RANK_9; r >= RANK_0; --r)
262+
for (Rank r = RANK_9;; --r)
260263
{
261264
for (File f = FILE_A; f <= FILE_I; ++f)
262265
{
@@ -270,8 +273,9 @@ string Position::fen() const {
270273
ss << PieceToChar[piece_on(make_square(f, r))];
271274
}
272275

273-
if (r > RANK_0)
274-
ss << '/';
276+
if (r == RANK_0)
277+
break;
278+
ss << '/';
275279
}
276280

277281
ss << (sideToMove == WHITE ? " w " : " b ");
@@ -1304,10 +1308,13 @@ void Position::flip() {
13041308
string f, token;
13051309
std::stringstream ss(fen());
13061310

1307-
for (Rank r = RANK_9; r >= RANK_0; --r) // Piece placement
1311+
for (Rank r = RANK_9;; --r) // Piece placement
13081312
{
13091313
std::getline(ss, token, r > RANK_0 ? '/' : ' ');
13101314
f.insert(0, token + (f.empty() ? " " : "/"));
1315+
1316+
if (r == RANK_0)
1317+
break;
13111318
}
13121319

13131320
ss >> token; // Active color

src/timeman.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
namespace Stockfish {
2727

2828
class OptionsMap;
29-
enum Color : int8_t;
29+
enum Color : uint8_t;
3030

3131
namespace Search {
3232
struct LimitsType;

src/types.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ using Bitboard = __uint128_t;
127127
constexpr int MAX_MOVES = 128;
128128
constexpr int MAX_PLY = 246;
129129

130-
enum Color : int8_t {
130+
enum Color : uint8_t {
131131
WHITE,
132132
BLACK,
133133
COLOR_NB = 2
134134
};
135135

136-
enum Bound : int8_t {
136+
enum Bound : uint8_t {
137137
BOUND_NONE,
138138
BOUND_UPPER,
139139
BOUND_LOWER,
@@ -176,13 +176,13 @@ constexpr Value KnightValue = 720;
176176
constexpr Value BishopValue = 187;
177177

178178
// clang-format off
179-
enum PieceType : std::int8_t {
179+
enum PieceType : std::uint8_t {
180180
NO_PIECE_TYPE, ROOK, ADVISOR, CANNON, PAWN, KNIGHT, BISHOP, KING, KNIGHT_TO, PAWN_TO,
181181
ALL_PIECES = 0,
182182
PIECE_TYPE_NB = 8
183183
};
184184

185-
enum Piece : std::int8_t {
185+
enum Piece : std::uint8_t {
186186
NO_PIECE,
187187
W_ROOK , W_ADVISOR, W_CANNON, W_PAWN, W_KNIGHT, W_BISHOP, W_KING,
188188
B_ROOK = ROOK + 8, B_ADVISOR, B_CANNON, B_PAWN, B_KNIGHT, B_BISHOP, B_KING,
@@ -214,7 +214,7 @@ constexpr Depth DEPTH_UNSEARCHED = -2;
214214
constexpr Depth DEPTH_ENTRY_OFFSET = -3;
215215

216216
// clang-format off
217-
enum Square : int8_t {
217+
enum Square : uint8_t {
218218
SQ_A0, SQ_B0, SQ_C0, SQ_D0, SQ_E0, SQ_F0, SQ_G0, SQ_H0, SQ_I0,
219219
SQ_A1, SQ_B1, SQ_C1, SQ_D1, SQ_E1, SQ_F1, SQ_G1, SQ_H1, SQ_I1,
220220
SQ_A2, SQ_B2, SQ_C2, SQ_D2, SQ_E2, SQ_F2, SQ_G2, SQ_H2, SQ_I2,
@@ -244,7 +244,7 @@ enum Direction : int8_t {
244244
NORTH_WEST = NORTH + WEST
245245
};
246246

247-
enum File : int8_t {
247+
enum File : uint8_t {
248248
FILE_A,
249249
FILE_B,
250250
FILE_C,
@@ -257,7 +257,7 @@ enum File : int8_t {
257257
FILE_NB
258258
};
259259

260-
enum Rank : int8_t {
260+
enum Rank : uint8_t {
261261
RANK_0,
262262
RANK_1,
263263
RANK_2,

src/uci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace Stockfish {
3333
class Position;
3434
class Move;
3535
class Score;
36-
enum Square : int8_t;
36+
enum Square : uint8_t;
3737
using Value = int;
3838

3939
class UCIEngine {

0 commit comments

Comments
 (0)