Skip to content

Commit

Permalink
perf improvement for Bitboard.Lsb
Browse files Browse the repository at this point in the history
  • Loading branch information
vinymeuh committed May 25, 2024
1 parent 39d1944 commit 132f216
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion engine/usiloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

const (
EngineVersion = "0.0"
EngineVersion = "0.1"
)

// ==================================== //
Expand Down
7 changes: 3 additions & 4 deletions shogi/bitboard/bitboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package bitboard

import (
"fmt"
"math"
"math/bits"
)

// A bitboard is a binary representation that encodes all the squares on the board.
Expand Down Expand Up @@ -84,7 +84,6 @@ func (b Bitboard) Or(other Bitboard) Bitboard {
low: b.low | other.low,
high: b.high | other.high,
}

}

// Not returns a new bitboard with the bitwise NOT operation applied.
Expand All @@ -98,10 +97,10 @@ func (b Bitboard) Not() Bitboard {
// Lsb returns the index of the first bit that is turned on from the LSB side.
func (b Bitboard) Lsb() int {
if b.low > 0 {
return int(math.Log2(float64(b.low & -b.low)))
return bits.TrailingZeros64(b.low)
}
if b.high > 0 {
return 64 + int(math.Log2(float64(b.high&-b.high)))
return 64 + bits.TrailingZeros64(b.high)
}
return -1
}
Expand Down

0 comments on commit 132f216

Please sign in to comment.