Skip to content

Commit 66ca663

Browse files
committed
Reorder win-checks to improve performance
Reorder win-check logic to favor row-wise over column-wise checks. This aligns better with C’s row-major memory layout, enhancing spatial locality. It reduces cache line crossings, cuts down total instruction count, and improves sequential memory access— especially useful for large boards or frequent evaluations. Benchmark on a 5×5 board (1M iterations): - Instructions: 20,042,179,354 → 9,528,171,690 (-52.5%) - Cache refs: 205,075 → 115,548 (-43.65%) - Cache misses: 28,503 → 20,176 (-29.23%) - Time elapsed: 0.971s → 0.597s (-38.5%) Despite a minor rise in miss rate, total misses declined due to fewer cache references.
1 parent 46ad350 commit 66ca663

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

game.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55

66
const line_t lines[4] = {
7-
{1, 0, 0, 0, BOARD_SIZE - GOAL + 1, BOARD_SIZE}, // COL
87
{0, 1, 0, 0, BOARD_SIZE, BOARD_SIZE - GOAL + 1}, // ROW
8+
{1, 0, 0, 0, BOARD_SIZE - GOAL + 1, BOARD_SIZE}, // COL
99
{1, 1, 0, 0, BOARD_SIZE - GOAL + 1, BOARD_SIZE - GOAL + 1}, // PRIMARY
1010
{1, -1, 0, GOAL - 1, BOARD_SIZE - GOAL + 1, BOARD_SIZE}, // SECONDARY
1111
};

0 commit comments

Comments
 (0)