Skip to content

Commit

Permalink
add a Bits instance to MemInt
Browse files Browse the repository at this point in the history
This helps supporting bitwise operations over `MemInt`s without having
to unwrap/rewrap them into `Int64`s.
  • Loading branch information
Ptival committed Jul 23, 2024
1 parent 83d3907 commit d2561b1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions base/src/Data/Macaw/Memory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,20 @@ instance MemWidth w => Integral (MemInt w) where
where (q,r) = memIntValue x `quotRem` memIntValue y
toInteger = toInteger . memIntValue

instance MemWidth w => Bits (MemInt w) where
MemInt x .&. MemInt y = memInt (x .&. y)
MemInt x .|. MemInt y = memInt (x .|. y)
MemInt x `xor` MemInt y = memInt (x `xor` y)
complement (MemInt x) = memInt (complement x)
MemInt x `shift` i = memInt (x `shift` i)
MemInt x `rotate` i = memInt (x `rotate` i)
bitSize = addrBitSize
bitSizeMaybe x = Just (addrBitSize x)
isSigned _ = True
MemInt x `testBit` i = x `testBit` i
bit i = memInt (bit i)
popCount (MemInt x) = popCount x

------------------------------------------------------------------------
-- Relocation

Expand Down

0 comments on commit d2561b1

Please sign in to comment.