Code: Select all
class BB {
u32 u[3]; // u[0] the least significant
BB(u32 u0, u32 u1, u32 u2) {
u[0] = u0; u[1] = u1; u[2] = u2;
}
BB operator << (int n) const { // n in 0...89
if (n==0) {
return BB(*this); // copy
}
if (n>=64) {
return BB(0, 0, u[0] << (n - 64));
}
if (n>32) {
auto r = n - 32;
u32 u2 = (u[0] >> (32-r)) | (u[1] << r);
u32 u1 = u[0] << r;
return BB(0, u1, u2);
}
if (n==32) { // special case to avoid undefined results for both << 32 and >> 32
return BB(0, u[0], u[1]);
}
u32 u2 = (u[1] >> (32-n)) | (u[2] << n);
u32 u1 = (u[0] >> (32-n)) | (u[1] << n);
u32 u0 = u[0] << n;
return BB(u0, u1, u2);
}
The code works so far. However IMO it looks so slow since it has many ifs inside.
Can someone help me to improve it or show me some better sources / libraries?
I guess someone may face the same problems with other chess variants or working with compilers without int64 for chess.

