Michael Sherwin wrote:Thanks Gerd,
It keeps getting better and better for the bishop! Still the rook is requireing 4 shifts. Would it be better to do one shift followed by a 32 bit multiply and then just using the indexs from the upper 32 bits with out shifting them back down?
Mike
Yes, 32-bit imul seems preferable on K8.
Your index splitting idea is really marvelous. I took me some time to get that!
I think to pre-shift-and the upper 16 bits of the folded 32-bit word is not necessary. The intended 16-bit sum might still > 0xffff, therefor a post-shift-and seems necessary. Also with your index splitting the Java array might be obsolete :
- Code: Select all
u64 BishopAttacks(u64 occ, u32 sq) {
u32 index;
u64 bb1, bb2;
occ &= bishopBits[sq];
index = (u32) occ;
index += (u32)(occ >> 32) >> 1;
index += index >> loBishopShifts[sq]; // assuming shifting >= 16
bb1 = loBishopAttacks[sq][index & 0xff];
bb2 = hiBishopAttacks[sq][(index >> 8) & 0xff];
return bb1 & bb2;
}
Gerd