Not everything is possible to do at all efficiently in C. You may have noticed that C has no rotate operator f.ex., no byte swap function, no bit scan functions etc.
As for working with bitboards (sets of squares) the MMX registers and instructions are indispensable on a 32 bit computer. Does your compiler produce them as appropriate? If so, on what C code? I'd like to see the following code implemented in pure C. It computes the pawn captures as the set of destination squares:
Code: Select all
#include <stdio.h>
char occ[8] = {4,0x40,0x40,0x40,0x40,0x40,0x40,4};
char pawns[8] = {2,2,2,2,2,2,2,2};
char cap[8] = {0,0,0,0,0,0,0,0};
void pawn_caps()
{
__asm { movq mm0, pawns
movq mm1, mm0
psllq mm0, 9
psrlq mm1, 7
por mm0, mm1
pand mm0, occ
movq cap, mm0
}
}
int main(int argc, char* argv[])
{
pawn_caps();
int i;
for (i = 7; i >= 0; i--) printf("%2X\n", cap[i]);
return 0;
}