Skip to content

Commit

Permalink
Improve performance by 1% by eliminating pnr
Browse files Browse the repository at this point in the history
  • Loading branch information
mlang committed Oct 21, 2024
1 parent d75ab53 commit a89572f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Game/Chess/Internal/QuadBitboard.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ data QuadBitboard = QBB { black, pbq, nbk, rqk :: {-# UNPACK #-} !Word64 }

instance NFData QuadBitboard

occupied, pnr, white, pawns, knights, bishops, rooks, queens, kings :: QuadBitboard -> Word64
occupied, white, pawns, knights, bishops, rooks, queens, kings :: QuadBitboard -> Word64
occupied = liftA2 (.|.) pbq $ liftA2 (.|.) nbk rqk
pnr = liftA2 xor pbq $ liftA2 xor nbk rqk
white = liftA2 xor occupied black
pawns = liftA2 (.&.) pnr pbq
knights = liftA2 (.&.) pnr nbk
pawns = liftA2 (.&.) pbq $ liftA2 (.&.) (complement . nbk) (complement . rqk)
knights = liftA2 (.&.) (complement . pbq) $ liftA2 (.&.) nbk (complement . rqk)
bishops = liftA2 (.&.) pbq nbk
rooks = liftA2 (.&.) pnr rqk
rooks = liftA2 (.&.) (complement . pbq) $ liftA2 (.&.) (complement . nbk) rqk
queens = liftA2 (.&.) pbq rqk
kings = liftA2 (.&.) nbk rqk

Expand All @@ -99,7 +98,6 @@ bRooks = liftA2 (.&.) rooks black
bQueens = liftA2 (.&.) queens black
bKings = liftA2 (.&.) kings black

{-# INLINE pnr #-}
{-# INLINE occupied #-}
{-# INLINE white #-}
{-# INLINE pawns #-}
Expand Down

0 comments on commit a89572f

Please sign in to comment.