c++ - Efficient least significant set bit of "biginteger" class -
i'm writing boardgame engine , wrote 10x10 bitboard class. class holds array of 2 uint64's , implements various bit operations. important operation didn't implement yet lsb(). know can lsb() on first integer , if it's 0 on second. however, checking if it's 0 seems redundant. efficient way implement lsb()?
edit: 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 + index of bit
are there performance improvements make? note if condition false.
if expect inputs have bit set in lower 64 bits, have profile execution. following avoids 2 lsb64 calls.
return b_[0] ? lsb64(b_[0]) : (b_[1] ? 64 + lsb64(b_[1]) : 0); possible solutions lsb64 can found in related question.
Comments
Post a Comment