I'm writing a boardgame engine and I wrote a 10x10 bitboard class. The class holds an array of two uint64's and implements various bit operations. An important operation I didn't implement yet is lsb()
. I know that I can do lsb()
on the first integer and if it's 0 do it on the second. However, checking if it's 0 seems redundant. What would be the most efficient way to implement lsb()
?
EDIT: My current code is:
char s = lsb64(b_[0]);
if (s == 0 && b_[1] != 0) {
s = lsb64(b_[1]) + 64;
}
return s;
lsb64() here returns 1 + the index of the bit
Are there performance improvements I could make? Note the if condition will almost always be false.