As I stated in another thread, I believe that I had developed the fastest bitboard move generator for either 32 bit or 64 bit machines and that I would post about them. The last bitboard generator that I posted about was to just get a 'read' on that method before I had completly made up my mind on which was fastest.
This is the bishop generator. The rook will follow later.
Code: Select all
typedef union {
u32 u;
u08 1;
u08 2;
u08 3;
u08 4;
} split32;
typedef union {
u64 u;
u32 lo;
u32 hi;
} split64;
Code: Select all
17, 19, 19, 17, 17, 18, 18, 16,
17, 17, 17, 17, 18, 18, 16, 17,
17, 17, 17, 17, 17, 15, 17, 17,
16, 16, 16, 16, 16, 16, 18, 18,
16, 18, 16, 16, 16, 16, 19, 20,
15, 17, 15, 17, 17, 17, 19, 17,
18, 18, 20, 20, 17, 17, 17, 17,
16, 17, 16, 16, 17, 17, 17, 17
Code: Select all
u64 BishopAttacks(square * sq, split64 * occ) {
sq->blockers.u = occ.u & sq->bishopBits;
sq->index = sq->blockers.lo + (sq->blockers.hi >> 1);
sq->index |= (sq->index >> sq->bishopShifts);
return bishopAttacks[sq->bMinimal1[sq->index.1] | sq->bMinimal2[sq->index.2]];
}
also, because of the split 32 union. The bishopAttacks subtable address is also
pre computed and part of the sq->bMinimal1 array.
Features:
* Very fast (maybe fastest) on 64 bit machines as well !
* Code will work as is for both 32 bit and 64 bit machines !!
* Only one dimentional array indexing calculations !!!
* For 32 bit machines, very few 64 bit accesses !!!!
* Most data accessed with one pointer !!!!!
* Very small memory footprint compared to magic !!!!!!
* No need for slow imul machine instructions !!!!!!!
Ofcourse mistakes are possible and optimizations are possible too.