add a Bits instance to MemInt

This helps supporting bitwise operations over `MemInt`s without having
to unwrap/rewrap them into `Int64`s.
This commit is contained in:
Valentin Robert 2024-07-23 16:15:24 -07:00
parent 83d3907054
commit d2561b1078

View File

@ -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