summaryrefslogtreecommitdiff
path: root/src/chess.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/chess.h')
-rwxr-xr-xsrc/chess.h43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/chess.h b/src/chess.h
index 5e1d4a5..1f874b9 100755
--- a/src/chess.h
+++ b/src/chess.h
@@ -647,6 +647,17 @@ typedef struct _POSITION
// 0 and 1 are the sum,
// 2..6 are per PIECE_TYPE
+ // Per-color, per-piece-type location bitboards -- "where are my
+ // knights/bishops/rooks/queens" -- indexed by PIECE_TYPE exactly
+ // like uNonPawnCount above (slots 0/1/PAWN/KING unused, same
+ // convention). Maintained incrementally in move.c at every site
+ // that already updates cNonPawns[]/uNonPawnCount[] (see
+ // board_representation/MIGRATION.md), not rebuilt -- O(1) per
+ // move. Pawns use pHash->bbPawnLocations[2] (pawn-hash-keyed,
+ // already established) instead; king is a single square
+ // (cNonPawns[color][0]), a bitboard adds nothing.
+ BITBOARD bbPieces[2][8];
+
ULONG uWhiteSqBishopCount[2]; // num bishops on white squares
SCORE iMaterialBalance[2]; // material balance
@@ -1318,7 +1329,16 @@ _assert(CHAR *szFile, ULONG uLine);
#define TO64(x) ((x) & 0x7) + ((0x7 - ((x)>>4)) << 3)
#define COOR_TO_BIT_NUMBER(c) (((((c) & 0x70) >> 1) | ((c) & 0x7)))
#define SLOWCOOR_TO_BB(c) (1ULL << COOR_TO_BIT_NUMBER(c))
-#define COOR_TO_BB(c) (BBSQUARE[COOR_TO_BIT_NUMBER(c)])
+// Was BBSQUARE[COOR_TO_BIT_NUMBER(c)] (an L1 load off a 64-entry table)
+// -- measured (testbitboard.c's TestBitboards, fixed to use a volatile
+// sink so the comparison isn't dead-code-eliminated) consistently ~5-7%
+// slower than the pure-ALU shift on this hardware, so switched to match
+// SLOWCOOR_TO_BB's expression. "SLOW" in that macro's name reflects a
+// stale assumption (variable-count shifts being slow) that doesn't hold
+// on modern silicon; BBSQUARE itself stays -- still used directly (not
+// via this macro) where callers already have a bit index in hand and
+// indexing it avoids recomputing COOR_TO_BIT_NUMBER redundantly.
+#define COOR_TO_BB(c) (1ULL << COOR_TO_BIT_NUMBER(c))
#define SLOW_BIT_NUMBER_TO_COOR(b) ((((b) / 8) << 4) + ((b) & 7))
#define BIT_NUMBER_TO_COOR(b) ((((b) & 0xF8) << 1) | ((b) & 7))
@@ -2002,6 +2022,18 @@ extern BITBOARD BBPRECEEDING_RANKS[8][2];
extern BITBOARD BBADJACENT_FILES[8];
extern BITBOARD BBADJACENT_RANKS[9];
+// Ray-to-edge / knight-attack occupancy tables (data.c) -- built once
+// at startup, consumed by ray-walk mobility code and (per
+// board_representation/MIGRATION.md) the planned bbPieces-backed
+// GetAttacks/CountKingSafetyDefects primitive.
+extern BITBOARD g_RookRayToEdge[4][128];
+extern const int g_RookRayDeltas[4];
+extern const FLAG g_RookRayPositiveDir[4];
+extern BITBOARD g_BishopRayToEdge[4][128];
+extern const int g_BishopRayDeltas[4];
+extern const FLAG g_BishopRayPositiveDir[4];
+extern BITBOARD g_KnightAttacksBB[128];
+
void
InitializeWhiteSquaresTable(void);
@@ -2014,6 +2046,15 @@ InitializeSwapTable(void);
void
InitializeDistanceTable(void);
+void
+InitializeRookRayTables(void);
+
+void
+InitializeBishopRayTables(void);
+
+void
+InitializeKnightAttackTables(void);
+
#ifdef DEBUG
ULONG CheckVectorWithIndex(int i, ULONG uColor);
#define CHECK_VECTOR_WITH_INDEX(i, color) \