Idris2/tests/refc/integers/IntBits.idr
madman-bob 98d67499db
RefC Integer Support (#1480)
* Add utility functions to treat All as a heterogeneous container
* Distinguish RefC Int and Bits types
* Change RefC Integers to be arbitrary precision
* Add RefC Bits maths operations
* Make RefC div and mod Euclidean
* Add RefC bit-ops tests
* Add RefC integer comparison tests
* Add RefC IntN support
2021-06-03 10:44:42 +01:00

95 lines
2.5 KiB
Idris

module IntBits
import IntCasts
import IntEqOrd
import IntNum
import Data.Bits
import Data.DPair
-- This file to be deleted once these interfaces are added to base
public export %inline
Bits Int8 where
Index = Subset Nat (`LT` 8)
(.&.) = prim__and_Int8
(.|.) = prim__or_Int8
xor = prim__xor_Int8
bit = (1 `shiftL`)
zeroBits = 0
testBit x i = (x .&. bit i) /= 0
shiftR x = prim__shr_Int8 x . cast . fst
shiftL x = prim__shl_Int8 x . cast . fst
complement = xor (-1)
oneBits = -1
public export %inline
Bits Int16 where
Index = Subset Nat (`LT` 16)
(.&.) = prim__and_Int16
(.|.) = prim__or_Int16
xor = prim__xor_Int16
bit = (1 `shiftL`)
zeroBits = 0
testBit x i = (x .&. bit i) /= 0
shiftR x = prim__shr_Int16 x . cast . fst
shiftL x = prim__shl_Int16 x . cast . fst
complement = xor (-1)
oneBits = -1
public export %inline
Bits Int32 where
Index = Subset Nat (`LT` 32)
(.&.) = prim__and_Int32
(.|.) = prim__or_Int32
xor = prim__xor_Int32
bit = (1 `shiftL`)
zeroBits = 0
testBit x i = (x .&. bit i) /= 0
shiftR x = prim__shr_Int32 x . cast . fst
shiftL x = prim__shl_Int32 x . cast . fst
complement = xor (-1)
oneBits = -1
public export %inline
Bits Int64 where
Index = Subset Nat (`LT` 64)
(.&.) = prim__and_Int64
(.|.) = prim__or_Int64
xor = prim__xor_Int64
bit = (1 `shiftL`)
zeroBits = 0
testBit x i = (x .&. bit i) /= 0
shiftR x = prim__shr_Int64 x . cast . fst
shiftL x = prim__shl_Int64 x . cast . fst
complement = xor (-1)
oneBits = -1
public export %inline
Bits Bits64 where
Index = Subset Nat (`LT` 64)
(.&.) = prim__and_Bits64
(.|.) = prim__or_Bits64
xor = prim__xor_Bits64
bit = (1 `shiftL`)
zeroBits = 0
testBit x i = (x .&. bit i) /= 0
shiftR x = prim__shr_Bits64 x . fromInteger . cast . fst
shiftL x = prim__shl_Bits64 x . fromInteger . cast . fst
complement = xor 0xffffffffffffffff
oneBits = 0xffffffffffffffff
public export %inline
Bits Integer where
Index = Nat
(.&.) = prim__and_Integer
(.|.) = prim__or_Integer
xor = prim__xor_Integer
bit = (1 `shiftL`)
zeroBits = 0
testBit x i = (x .&. bit i) /= 0
shiftR x = prim__shr_Integer x . cast
shiftL x = prim__shl_Integer x . cast
complement = xor (-1)
oneBits = (-1)