From d2561b10781f6fa30457ede74a6e623fce678947 Mon Sep 17 00:00:00 2001 From: Valentin Robert Date: Tue, 23 Jul 2024 16:15:24 -0700 Subject: [PATCH] add a `Bits` instance to `MemInt` This helps supporting bitwise operations over `MemInt`s without having to unwrap/rewrap them into `Int64`s. --- base/src/Data/Macaw/Memory.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/base/src/Data/Macaw/Memory.hs b/base/src/Data/Macaw/Memory.hs index 6973af9e..501d7795 100644 --- a/base/src/Data/Macaw/Memory.hs +++ b/base/src/Data/Macaw/Memory.hs @@ -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