summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2026-10-05 22:20:27 -0700
committerScott Gasch <[email protected]>2026-10-05 22:20:27 -0700
commit36b6628fc7a7c481b3d00c3141a800d869c63dca (patch)
tree8a638db233ab986c9cb06fc549ac282f085bfbf0
parent5fbd9353fa9b1a80f37bcf0339f5546ac88091b8 (diff)
Benchmark the real FastCoorFromBitBoardRank8ToRank1 call-site shape
Measures the actual ctzll+BIT_NUMBER_TO_COOR+bit-clear chain generate.c's per-piece scan loops use, plus the bare BIT_NUMBER_TO_COOR macro alone, to isolate the conversion arithmetic from the bit-scan around it. Confirms (alongside an objdump check of the real binary) that LTO already inlines these across translation units, so eval.c's many remaining call sites against the "slow" extern CoorFromBitBoardRank8ToRank1 wrapper cost nothing extra in practice. Co-Authored-By: Claude Sonnet 5 <[email protected]>
-rw-r--r--src/testbitboard.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/testbitboard.c b/src/testbitboard.c
index c91f87c..f29c916 100644
--- a/src/testbitboard.c
+++ b/src/testbitboard.c
@@ -192,9 +192,57 @@ Return value:
b = FirstBit(bbSpeed[u]);
}
}
- printf(" FirstBit: %" COMPILER_LONGLONG_UNSIGNED_FORMAT
+ printf(" FirstBit: %" COMPILER_LONGLONG_UNSIGNED_FORMAT
" cycles/op\n",
(SystemReadTimeStampCounter() - u64) / (1000 * 1000));
+
+ // 2026-10-05: measuring the bitboard-bit -> 0x88 COOR conversion
+ // chain actually used in generate.c's per-piece scan loops
+ // (FastCoorFromBitBoardRank8ToRank1: ctzll + BIT_NUMBER_TO_COOR +
+ // bit-clear, all inlined) -- not the bare macro in isolation, the
+ // real call site shape, same rdtsc methodology as the other
+ // benchmarks in this function.
+ {
+ volatile COOR cSink;
+ BITBOARD bbScan;
+ UINT64 u64Ops = 0;
+ u64 = SystemReadTimeStampCounter();
+ for (v = 0; v < 1000; v++)
+ {
+ for (u = 0; u < 1000; u++)
+ {
+ bbScan = bbSpeed[u];
+ while (bbScan)
+ {
+ cSink = FastCoorFromBitBoardRank8ToRank1(&bbScan);
+ u64Ops++;
+ }
+ }
+ }
+ u64Ops += (0 == u64Ops);
+ printf(" FastCoorFromBitBoardRank8ToRank1 (per bit popped, "
+ "%" COMPILER_LONGLONG_UNSIGNED_FORMAT " total ops): %"
+ COMPILER_LONGLONG_UNSIGNED_FORMAT " cycles/op\n",
+ u64Ops,
+ (SystemReadTimeStampCounter() - u64) / u64Ops);
+ printf(" (cSink final value, just to use it: %u)\n", cSink);
+ }
+
+ // Bare BIT_NUMBER_TO_COOR macro alone, no bit-scan, to isolate the
+ // conversion arithmetic itself from the ctzll/bit-clear around it.
+ {
+ volatile COOR cSink2;
+ u64 = SystemReadTimeStampCounter();
+ for (u = 0; u < 1000000; u++)
+ {
+ b = u % 64;
+ cSink2 = BIT_NUMBER_TO_COOR(b);
+ }
+ printf(" BIT_NUMBER_TO_COOR (bare macro): %"
+ COMPILER_LONGLONG_UNSIGNED_FORMAT " cycles/op\n",
+ (SystemReadTimeStampCounter() - u64) / 1000000);
+ printf(" (cSink2 final value, just to use it: %u)\n", cSink2);
+ }
#endif
FOREACH_SQUARE(c)