branchless bitboard set
This commit is contained in:
parent
fef4f64ecd
commit
b2b5fb9e2c
@ -51,23 +51,9 @@ impl BitBoard {
|
||||
#[cfg(not(feature = "bitvec"))]
|
||||
pub const fn set(&mut self, row: usize, col: usize, value: bool) {
|
||||
let index = Self::get_index(row, col);
|
||||
if value {
|
||||
self.set_bit(index); // Set the bit at (row, col) to 1
|
||||
} else {
|
||||
self.clear_bit(index); // Clear the bit at (row, col)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "bitvec"))]
|
||||
const fn clear_bit(&mut self, index: usize) {
|
||||
self.0 &= !(1 << index)
|
||||
}
|
||||
|
||||
// PERF! was going to optimize setting multiple indexes,
|
||||
// seems rust does this for us: https://godbolt.org/z/ddj3dMxsP
|
||||
#[cfg(not(feature = "bitvec"))]
|
||||
const fn set_bit(&mut self, index: usize) {
|
||||
self.0 |= 1 << index
|
||||
// PERF! branchless setting of bit (~+3% perf bump)
|
||||
self.0 &= !(1 << index); // clear bit
|
||||
self.0 |= (value as BitBoardInner) << index; // set bit (if needed)
|
||||
}
|
||||
|
||||
const fn get_index(row: usize, col: usize) -> usize {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user