summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/GNUmakefile7
-rw-r--r--src/board_representation/MIGRATION.md66
-rwxr-xr-xsrc/chess.h21
-rw-r--r--src/testsee.c13
4 files changed, 86 insertions, 21 deletions
diff --git a/src/GNUmakefile b/src/GNUmakefile
index 289f8bd..601a362 100644
--- a/src/GNUmakefile
+++ b/src/GNUmakefile
@@ -14,6 +14,9 @@
# USE_READLINE=1: link against the GNU readline library
# SIXTYFOUR=1: make an X64 binary
# CROUTINES=1: use the C versions of the asm routines [slower]
+# GETATTACKS_BITBOARD=1: use the bbPieces/bbPawns-backed _GetAttacksBB
+# instead of the asm/CROUTINES GetAttacks -- see
+# board_representation/MIGRATION.md section 6
# EVERYTHING=1: everything everything everything everything
#
# $Id$
@@ -96,6 +99,10 @@ ifdef CROUTINES
PROFILE += -DCROUTINES
endif
+ifdef GETATTACKS_BITBOARD
+ PROFILE += -DGETATTACKS_BITBOARD
+endif
+
ifdef EVERYTHING
PROFILE += -DEVAL_DUMP -DEVAL_TIME -DPERF_COUNTERS -DMP -DSMP -DTEST_NULL -DDUMP_TREE -fbounds-checking
else
diff --git a/src/board_representation/MIGRATION.md b/src/board_representation/MIGRATION.md
index f8bccb1..57ca7f9 100644
--- a/src/board_representation/MIGRATION.md
+++ b/src/board_representation/MIGRATION.md
@@ -14,10 +14,14 @@ references accordingly; where useful, dropped content is preserved
inline as a note rather than deleted, so a future session designing
the separate migration doesn't have to rediscover it from git history.
-**Status: sections 1-2 (`bbPieces`) and section 3 (`bbPieces`/`bbPawns`-backed
-`_WhoAttacksSquareBB`/`_GetAttacksBB`, not yet wired into the
-`GetAttacks` macro) implemented, verified, and committed. Sections 4
-(partially done, folded into section 3's own testing)-8 not started.**
+**Status: sections 1-3 (`bbPieces`/`bbPawns`-backed
+`_WhoAttacksSquareBB`/`_GetAttacksBB`) and section 6 (the
+`GETATTACKS_BITBOARD` toggle, `_GetAttacksBB` now reachable from real
+search when enabled) implemented, verified, and committed. Section 4
+items 1-3 done (folded into sections 3/6's own testing); items 4-5 and
+sections 5's second half/7 -- the whole-engine curated-suite and
+`match_play.py` gates -- not started, now genuinely unblocked since
+section 6 exists. Section 8 not started.**
See the per-section status notes below for specifics.
Context: a prior pass of this session added occupancy-bitboard-driven
@@ -444,10 +448,10 @@ sequence.
above -- also fixed a latent `bbPieces`/`bbPawns` maintenance gap in
`GenerateRandomLegalPosition` found while running this.
3. **`precommit_check.sh`** as always, for the crash/assert layer.
- **DONE** for `_GetAttacksBB`'s current (not-yet-wired-in) state --
- clean. Should be re-run once section 6's toggle actually flips
- `GetAttacks` to the bitboard implementation, since nothing has
- exercised that live yet.
+ **DONE**, both without and with section 6's toggle
+ (`GETATTACKS_BITBOARD=1`) -- clean in both configurations, the
+ latter run confirming `_GetAttacksBB` live end-to-end in real
+ search, not just the isolated harness.
4. **SEE-value diffing at the position level**: since `SEE()` returns a
single integer per move (not a board eval), the equivalent of the
Eval work's "150-position score-identity diff" is a diagnostic
@@ -503,16 +507,46 @@ visible in isolation. Two tiers, both required before wiring in:
to production wiring again. Not started -- requires section 6's
toggle to exist first.
-## 6. Dual-support / toggle strategy
+## 6. Dual-support / toggle strategy -- DONE
Same `#define` pattern already established for the Eval occupancy work
-(`ROOK_OCCUPANCY_EVAL` et al.): `GETATTACKS_BITBOARD`, flipping which
-implementation `chess.h`'s `GetAttacks` macro/prototype resolves to
-(alongside the existing `CROUTINES` old/new(asm) switch -- this becomes a
-three-way choice: `SlowGetAttacks` (C mailbox), asm `GetAttacks` (x86/x64
-mailbox), `_GetAttacksBB` (new)). Not started -- `_GetAttacksBB` is
-still a side-by-side PoC, called only from the test/bench harness, not
-reachable from the `GetAttacks` macro yet.
+(`ROOK_OCCUPANCY_EVAL` et al.): `GETATTACKS_BITBOARD` (`GNUmakefile`
+build flag, `-DGETATTACKS_BITBOARD`), flipping which implementation
+`chess.h`'s `GetAttacks` macro resolves to -- a three-way choice
+alongside the existing `CROUTINES` switch: `_GetAttacksBB` (new,
+bitboard) if `GETATTACKS_BITBOARD` is defined, else `SlowGetAttacks`
+(C mailbox) if `CROUTINES` is defined, else the real asm `GetAttacks`
+(x86/x64 mailbox, the default). `_GetAttacksBB` is now reachable from
+every real `GetAttacks` call site (`generate.c`'s check-detection
+call, `see.c`'s `SEE()`, `searchsup.c`) when the flag is set, not just
+the test/bench harness.
+
+**Found and fixed while wiring this up**: `testsee.c`'s own
+`TestGetAttacks`/benchmark code calls the identifier `GetAttacks` to
+mean "the real asm/CROUTINES baseline" -- but once the macro can
+resolve to `_GetAttacksBB`, those same calls would silently become
+`_GetAttacksBB` compared against itself, turning the correctness sweep
+and the "asm vs. new" benchmark into false-positive no-ops. Fixed with
+a local `#undef GetAttacks` right after `#include "chess.h"` in
+`testsee.c`, so the harness always reaches the true baseline
+implementation regardless of which implementation is live in
+production -- the harness's job is validating the new implementation
+against a fixed reference, not testing the engine's current
+configuration against itself.
+
+**Verified with the toggle live**: `gmake TEST=1 GETATTACKS_BITBOARD=1`
+-- self-test suite passes (including the corrected benchmark, still
+reporting real asm vs. `_GetAttacksBB` correctly, same ~0.52-0.92x
+numbers as section 3), and a real `Search()` call in the self-test
+suite completed normally with `_GetAttacksBB` live in `SEE()`/move
+generation's check-detection path, not just the isolated harness.
+`precommit_check.sh GETATTACKS_BITBOARD=1` (env-var propagation into
+`gmake` verified directly by grepping the resulting build logs for
+`-DGETATTACKS_BITBOARD`) -- both the `TEST=1` self-test and `DEBUG=1`
+smoke test (10 random ECM positions, `sd 4`) pass clean with the
+bitboard implementation live end-to-end. Default build (no flag)
+confirmed unaffected -- `GetAttacks` still resolves to the real asm
+function unless the flag is explicitly passed.
`bbPieces`/`bbPawns` maintenance itself is **always on** regardless of
this toggle -- it's cheap enough that gating it adds complexity for no
diff --git a/src/chess.h b/src/chess.h
index 5c5bbf2..4bc3464 100755
--- a/src/chess.h
+++ b/src/chess.h
@@ -2894,18 +2894,29 @@ SlowGetAttacks(SEE_LIST *pList,
POSITION *pos,
COOR cSquare,
ULONG uSide);
-#ifdef CROUTINES
-#define GetAttacks SlowGetAttacks
-#endif
-// board_representation/MIGRATION.md section 3: bbPieces-backed
-// GetAttacks PoC -- not wired into the GetAttacks macro above yet.
+// board_representation/MIGRATION.md section 3: bbPieces/bbPawns-backed
+// GetAttacks primitive, verified correct (20,000-position sweep) and
+// faster than asm GetAttacks (0.53-0.89x cycles/call across
+// opening/middlegame/endgame -- see section 3's benchmark writeup).
void CDECL
_GetAttacksBB(SEE_LIST *pList,
POSITION *pos,
COOR cSquare,
ULONG uSide);
+// Three-way choice for which GetAttacks implementation is actually
+// live -- see MIGRATION.md section 6:
+// GETATTACKS_BITBOARD defined -> _GetAttacksBB (bitboard, new)
+// else CROUTINES defined -> SlowGetAttacks (C mailbox)
+// else (default) -> GetAttacks (asm x86/x64 mailbox,
+// the literal function declared above)
+#if defined(GETATTACKS_BITBOARD)
+#define GetAttacks _GetAttacksBB
+#elif defined(CROUTINES)
+#define GetAttacks SlowGetAttacks
+#endif
+
#ifdef _X86_
//
// Note: this is most of the stuff that x86.asm assumes about the
diff --git a/src/testsee.c b/src/testsee.c
index 77fd706..2106494 100644
--- a/src/testsee.c
+++ b/src/testsee.c
@@ -26,6 +26,19 @@ Revision History:
#include "chess.h"
+// This harness's job is to validate _GetAttacksBB against a fixed
+// baseline (the real asm/CROUTINES implementation), not to compare
+// the engine's own current GetAttacks macro target against itself --
+// but chess.h's GETATTACKS_BITBOARD toggle (board_representation/
+// MIGRATION.md section 6) can make that macro resolve to
+// _GetAttacksBB. Undefine it here so every "GetAttacks(...)" call
+// below always reaches the real asm/CROUTINES function (still
+// declared under that name in chess.h, just no longer macro-routed),
+// regardless of which implementation is live in production.
+#ifdef GetAttacks
+#undef GetAttacks
+#endif
+
#ifdef TEST_BROKEN
ULONG g_uRootOnMove;