{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wall -Werror #-}
module Data.SBV.Core.Sized (
SWord, WordN, sWord, sWord_, sWords
, SInt, IntN, sInt, sInt_, sInts
, bvExtract, (#), zeroExtend, signExtend, bvDrop, bvTake
, ByteConverter(..)
, IsNonZero
) where
import Data.Bits
import Data.Maybe (fromJust)
import Data.Proxy (Proxy(..))
import GHC.TypeLits
import Data.Kind
import Data.SBV.Core.Data
import Data.SBV.Core.Model
import Data.SBV.Core.Operations
import Data.SBV.Core.Symbolic
import Data.SBV.Control.Utils
import Data.SBV.SMT.SMT
newtype WordN (n :: Nat) = WordN Integer deriving (Eq, Ord)
type SWord (n :: Nat) = SBV (WordN n)
instance Show (WordN n) where
show (WordN v) = show v
intOfProxy :: KnownNat n => Proxy n -> Int
intOfProxy = fromEnum . natVal
type ZeroWidth = 'Text "Zero-width BV's are not allowed."
type family IsNonZero (arg :: Nat) :: Constraint where
IsNonZero 0 = TypeError ZeroWidth
IsNonZero n = ()
instance (KnownNat n, IsNonZero n) => HasKind (WordN n) where
kindOf _ = KBounded False (intOfProxy (Proxy @n))
instance (KnownNat n, IsNonZero n) => SymVal (WordN n) where
literal x = genLiteral (kindOf x) x
mkSymVal = genMkSymVar (kindOf (undefined :: WordN n))
fromCV = genFromCV
newtype IntN (n :: Nat) = IntN Integer deriving (Eq, Ord)
type SInt (n :: Nat) = SBV (IntN n)
instance Show (IntN n) where
show (IntN v) = show v
instance (KnownNat n, IsNonZero n) => HasKind (IntN n) where
kindOf _ = KBounded True (intOfProxy (Proxy @n))
instance (KnownNat n, IsNonZero n) => SymVal (IntN n) where
literal x = genLiteral (kindOf x) x
mkSymVal = genMkSymVar (kindOf (undefined :: IntN n))
fromCV = genFromCV
lift1 :: (KnownNat n, IsNonZero n, HasKind (bv n), Integral (bv n), Show (bv n)) => String -> (SVal -> SVal) -> bv n -> bv n
lift1 nm op x = uc $ op (c x)
where k = kindOf x
c = SVal k . Left . CV k . CInteger . toInteger
uc (SVal _ (Left (CV _ (CInteger v)))) = fromInteger v
uc r = error $ "Impossible happened while lifting " ++ show nm ++ " over " ++ show (k, x, r)
lift2 :: (KnownNat n, IsNonZero n, HasKind (bv n), Integral (bv n), Show (bv n)) => String -> (SVal -> SVal -> SVal) -> bv n -> bv n -> bv n
lift2 nm op x y = uc $ c x `op` c y
where k = kindOf x
c = SVal k . Left . CV k . CInteger . toInteger
uc (SVal _ (Left (CV _ (CInteger v)))) = fromInteger v
uc r = error $ "Impossible happened while lifting " ++ show nm ++ " over " ++ show (k, x, y, r)
lift2I :: (KnownNat n, IsNonZero n, HasKind (bv n), Integral (bv n), Show (bv n)) => String -> (SVal -> Int -> SVal) -> bv n -> Int -> bv n
lift2I nm op x i = uc $ c x `op` i
where k = kindOf x
c = SVal k . Left . CV k . CInteger . toInteger
uc (SVal _ (Left (CV _ (CInteger v)))) = fromInteger v
uc r = error $ "Impossible happened while lifting " ++ show nm ++ " over " ++ show (k, x, i, r)
lift2IB :: (KnownNat n, IsNonZero n, HasKind (bv n), Integral (bv n), Show (bv n)) => String -> (SVal -> Int -> SVal) -> bv n -> Int -> Bool
lift2IB nm op x i = uc $ c x `op` i
where k = kindOf x
c = SVal k . Left . CV k . CInteger . toInteger
uc (SVal _ (Left v)) = cvToBool v
uc r = error $ "Impossible happened while lifting " ++ show nm ++ " over " ++ show (k, x, i, r)
instance (KnownNat n, IsNonZero n) => Bounded (WordN n) where
minBound = WordN 0
maxBound = let sz = intOfProxy (Proxy @n) in WordN $ 2 ^ sz - 1
instance (KnownNat n, IsNonZero n) => Bounded (IntN n) where
minBound = let sz1 = intOfProxy (Proxy @n) - 1 in IntN $ - (2 ^ sz1)
maxBound = let sz1 = intOfProxy (Proxy @n) - 1 in IntN $ 2 ^ sz1 - 1
instance (KnownNat n, IsNonZero n) => Num (WordN n) where
(+) = lift2 "(+)" svPlus
(-) = lift2 "(*)" svMinus
(*) = lift2 "(*)" svTimes
negate = lift1 "signum" svUNeg
abs = lift1 "abs" svAbs
signum = WordN . signum . toInteger
fromInteger = WordN . fromJust . svAsInteger . svInteger (kindOf (undefined :: WordN n))
instance (KnownNat n, IsNonZero n) => Num (IntN n) where
(+) = lift2 "(+)" svPlus
(-) = lift2 "(*)" svMinus
(*) = lift2 "(*)" svTimes
negate = lift1 "signum" svUNeg
abs = lift1 "abs" svAbs
signum = IntN . signum . toInteger
fromInteger = IntN . fromJust . svAsInteger . svInteger (kindOf (undefined :: IntN n))
instance (KnownNat n, IsNonZero n) => Enum (WordN n) where
toEnum = fromInteger . toInteger
fromEnum = fromIntegral . toInteger
instance (KnownNat n, IsNonZero n) => Enum (IntN n) where
toEnum = fromInteger . toInteger
fromEnum = fromIntegral . toInteger
instance (KnownNat n, IsNonZero n) => Real (WordN n) where
toRational (WordN x) = toRational x
instance (KnownNat n, IsNonZero n) => Real (IntN n) where
toRational (IntN x) = toRational x
instance (KnownNat n, IsNonZero n) => Integral (WordN n) where
toInteger (WordN x) = x
quotRem (WordN x) (WordN y) = let (q, r) = quotRem x y in (WordN q, WordN r)
instance (KnownNat n, IsNonZero n) => Integral (IntN n) where
toInteger (IntN x) = x
quotRem (IntN x) (IntN y) = let (q, r) = quotRem x y in (IntN q, IntN r)
instance (KnownNat n, IsNonZero n) => Bits (WordN n) where
(.&.) = lift2 "(.&.)" svAnd
(.|.) = lift2 "(.|.)" svOr
xor = lift2 "xor" svXOr
complement = lift1 "complement" svNot
shiftL = lift2I "shiftL" svShl
shiftR = lift2I "shiftR" svShr
rotateL = lift2I "rotateL" svRol
rotateR = lift2I "rotateR" svRor
testBit = lift2IB "svTestBit" svTestBit
bitSizeMaybe = Just . const (intOfProxy (Proxy @n))
bitSize _ = intOfProxy (Proxy @n)
isSigned = hasSign . kindOf
bit i = 1 `shiftL` i
popCount = fromIntegral . popCount . toInteger
instance (KnownNat n, IsNonZero n) => Bits (IntN n) where
(.&.) = lift2 "(.&.)" svAnd
(.|.) = lift2 "(.|.)" svOr
xor = lift2 "xor" svXOr
complement = lift1 "complement" svNot
shiftL = lift2I "shiftL" svShl
shiftR = lift2I "shiftR" svShr
rotateL = lift2I "rotateL" svRol
rotateR = lift2I "rotateR" svRor
testBit = lift2IB "svTestBit" svTestBit
bitSizeMaybe = Just . const (intOfProxy (Proxy @n))
bitSize _ = intOfProxy (Proxy @n)
isSigned = hasSign . kindOf
bit i = 1 `shiftL` i
popCount = fromIntegral . popCount . toInteger
instance (KnownNat n, IsNonZero n) => SIntegral (WordN n)
instance (KnownNat n, IsNonZero n) => SIntegral (IntN n)
instance (KnownNat n, IsNonZero n) => SDivisible (WordN n) where
sQuotRem x 0 = (0, x)
sQuotRem x y = x `quotRem` y
sDivMod x 0 = (0, x)
sDivMod x y = x `divMod` y
instance (KnownNat n, IsNonZero n) => SDivisible (IntN n) where
sQuotRem x 0 = (0, x)
sQuotRem x y = x `quotRem` y
sDivMod x 0 = (0, x)
sDivMod x y = x `divMod` y
instance (KnownNat n, IsNonZero n) => SDivisible (SWord n) where
sQuotRem = liftQRem
sDivMod = liftDMod
instance (KnownNat n, IsNonZero n) => SDivisible (SInt n) where
sQuotRem = liftQRem
sDivMod = liftDMod
instance (KnownNat n, IsNonZero n) => SFiniteBits (WordN n) where
sFiniteBitSize _ = intOfProxy (Proxy @n)
instance (KnownNat n, IsNonZero n) => SFiniteBits (IntN n) where
sFiniteBitSize _ = intOfProxy (Proxy @n)
instance (KnownNat n, IsNonZero n) => SMTValue (WordN n) where
sexprToVal e = WordN <$> sexprToVal e
instance (KnownNat n, IsNonZero n) => SMTValue (IntN n) where
sexprToVal e = IntN <$> sexprToVal e
instance (KnownNat n, IsNonZero n) => SatModel (WordN n) where
parseCVs = genParse (kindOf (undefined :: WordN n))
instance (KnownNat n, IsNonZero n) => SatModel (IntN n) where
parseCVs = genParse (kindOf (undefined :: IntN n))
instance (KnownNat n, IsNonZero n) => Metric (WordN n)
instance (KnownNat n, IsNonZero n) => Metric (IntN n) where
type MetricSpace (IntN n) = WordN n
toMetricSpace x = sFromIntegral x + 2 ^ (intOfProxy (Proxy @n) - 1)
fromMetricSpace x = sFromIntegral x - 2 ^ (intOfProxy (Proxy @n) - 1)
sWord :: (KnownNat n, IsNonZero n) => MonadSymbolic m => String -> m (SWord n)
sWord = symbolic
sWord_ :: (KnownNat n, IsNonZero n) => MonadSymbolic m => m (SWord n)
sWord_ = free_
sWords :: (KnownNat n, IsNonZero n) => MonadSymbolic m => [String] -> m [SWord n]
sWords = symbolics
sInt :: (KnownNat n, IsNonZero n) => MonadSymbolic m => String -> m (SInt n)
sInt = symbolic
sInt_ :: (KnownNat n, IsNonZero n) => MonadSymbolic m => m (SInt n)
sInt_ = free_
sInts :: (KnownNat n, IsNonZero n) => MonadSymbolic m => [String] -> m [SInt n]
sInts = symbolics
bvExtract :: forall i j n bv proxy. ( KnownNat n, IsNonZero n, SymVal (bv n)
, KnownNat i
, KnownNat j
, i + 1 <= n
, j <= i
, IsNonZero (i - j + 1)
) => proxy i
-> proxy j
-> SBV (bv n)
-> SBV (bv (i - j + 1))
bvExtract start end = SBV . svExtract i j . unSBV
where i = fromIntegral (natVal start)
j = fromIntegral (natVal end)
(#) :: ( KnownNat n, IsNonZero n, SymVal (bv n)
, KnownNat m, IsNonZero m, SymVal (bv m)
) => SBV (bv n)
-> SBV (bv m)
-> SBV (bv (n + m))
n # m = SBV $ svJoin (unSBV n) (unSBV m)
infixr 5 #
zeroExtend :: forall n m bv. ( KnownNat n, IsNonZero n, SymVal (bv n)
, KnownNat m, IsNonZero m, SymVal (bv m)
, n + 1 <= m
, SIntegral (bv (m - n))
, IsNonZero (m - n)
) => SBV (bv n)
-> SBV (bv m)
zeroExtend n = SBV $ svJoin (unSBV zero) (unSBV n)
where zero :: SBV (bv (m - n))
zero = literal 0
signExtend :: forall n m bv. ( KnownNat n, IsNonZero n, SymVal (bv n)
, KnownNat m, IsNonZero m, SymVal (bv m)
, n + 1 <= m
, SFiniteBits (bv n)
, SIntegral (bv (m - n))
, IsNonZero (m - n)
) => SBV (bv n)
-> SBV (bv m)
signExtend n = SBV $ svJoin (unSBV ext) (unSBV n)
where zero, ones, ext :: SBV (bv (m - n))
zero = literal 0
ones = complement zero
ext = ite (msb n) ones zero
bvDrop :: forall i n m bv proxy. ( KnownNat n, IsNonZero n
, KnownNat i
, i + 1 <= n
, i + m - n <= 0
, IsNonZero (n - i)
) => proxy i
-> SBV (bv n)
-> SBV (bv m)
bvDrop i = SBV . svExtract start 0 . unSBV
where nv = intOfProxy (Proxy @n)
start = nv - fromIntegral (natVal i) - 1
bvTake :: forall i n bv proxy. ( KnownNat n, IsNonZero n
, KnownNat i, IsNonZero i
, i <= n
) => proxy i
-> SBV (bv n)
-> SBV (bv i)
bvTake i = SBV . svExtract start end . unSBV
where nv = intOfProxy (Proxy @n)
start = nv - 1
end = start - fromIntegral (natVal i) + 1
class ByteConverter a where
toBytes :: a -> [SWord 8]
fromBytes :: [SWord 8] -> a
instance ByteConverter (SWord 8) where
toBytes a = [a]
fromBytes [x] = x
fromBytes as = error $ "fromBytes:SWord 8: Incorrect number of bytes: " ++ show (length as)
instance ByteConverter (SWord 16) where
toBytes a = [ bvExtract (Proxy @15) (Proxy @8) a
, bvExtract (Proxy @7) (Proxy @0) a
]
fromBytes as
| l == 2
= (fromBytes :: [SWord 8] -> SWord 8) (take 1 as) # fromBytes (drop 1 as)
| True
= error $ "fromBytes:SWord 16: Incorrect number of bytes: " ++ show l
where l = length as
instance ByteConverter (SWord 32) where
toBytes a = [ bvExtract (Proxy @31) (Proxy @24) a, bvExtract (Proxy @23) (Proxy @16) a, bvExtract (Proxy @15) (Proxy @8) a, bvExtract (Proxy @7) (Proxy @0) a
]
fromBytes as
| l == 4
= (fromBytes :: [SWord 8] -> SWord 16) (take 2 as) # fromBytes (drop 2 as)
| True
= error $ "fromBytes:SWord 32: Incorrect number of bytes: " ++ show l
where l = length as
instance ByteConverter (SWord 64) where
toBytes a = [ bvExtract (Proxy @63) (Proxy @56) a, bvExtract (Proxy @55) (Proxy @48) a, bvExtract (Proxy @47) (Proxy @40) a, bvExtract (Proxy @39) (Proxy @32) a
, bvExtract (Proxy @31) (Proxy @24) a, bvExtract (Proxy @23) (Proxy @16) a, bvExtract (Proxy @15) (Proxy @8) a, bvExtract (Proxy @7) (Proxy @0) a
]
fromBytes as
| l == 8
= (fromBytes :: [SWord 8] -> SWord 32) (take 4 as) # fromBytes (drop 4 as)
| True
= error $ "fromBytes:SWord 64: Incorrect number of bytes: " ++ show l
where l = length as
instance ByteConverter (SWord 128) where
toBytes a = [ bvExtract (Proxy @127) (Proxy @120) a, bvExtract (Proxy @119) (Proxy @112) a, bvExtract (Proxy @111) (Proxy @104) a, bvExtract (Proxy @103) (Proxy @96) a
, bvExtract (Proxy @95) (Proxy @88) a, bvExtract (Proxy @87) (Proxy @80) a, bvExtract (Proxy @79) (Proxy @72) a, bvExtract (Proxy @71) (Proxy @64) a
, bvExtract (Proxy @63) (Proxy @56) a, bvExtract (Proxy @55) (Proxy @48) a, bvExtract (Proxy @47) (Proxy @40) a, bvExtract (Proxy @39) (Proxy @32) a
, bvExtract (Proxy @31) (Proxy @24) a, bvExtract (Proxy @23) (Proxy @16) a, bvExtract (Proxy @15) (Proxy @8) a, bvExtract (Proxy @7) (Proxy @0) a
]
fromBytes as
| l == 16
= (fromBytes :: [SWord 8] -> SWord 64) (take 8 as) # fromBytes (drop 8 as)
| True
= error $ "fromBytes:SWord 128: Incorrect number of bytes: " ++ show l
where l = length as
instance ByteConverter (SWord 256) where
toBytes a = [ bvExtract (Proxy @255) (Proxy @248) a, bvExtract (Proxy @247) (Proxy @240) a, bvExtract (Proxy @239) (Proxy @232) a, bvExtract (Proxy @231) (Proxy @224) a
, bvExtract (Proxy @223) (Proxy @216) a, bvExtract (Proxy @215) (Proxy @208) a, bvExtract (Proxy @207) (Proxy @200) a, bvExtract (Proxy @199) (Proxy @192) a
, bvExtract (Proxy @191) (Proxy @184) a, bvExtract (Proxy @183) (Proxy @176) a, bvExtract (Proxy @175) (Proxy @168) a, bvExtract (Proxy @167) (Proxy @160) a
, bvExtract (Proxy @159) (Proxy @152) a, bvExtract (Proxy @151) (Proxy @144) a, bvExtract (Proxy @143) (Proxy @136) a, bvExtract (Proxy @135) (Proxy @128) a
, bvExtract (Proxy @127) (Proxy @120) a, bvExtract (Proxy @119) (Proxy @112) a, bvExtract (Proxy @111) (Proxy @104) a, bvExtract (Proxy @103) (Proxy @96) a
, bvExtract (Proxy @95) (Proxy @88) a, bvExtract (Proxy @87) (Proxy @80) a, bvExtract (Proxy @79) (Proxy @72) a, bvExtract (Proxy @71) (Proxy @64) a
, bvExtract (Proxy @63) (Proxy @56) a, bvExtract (Proxy @55) (Proxy @48) a, bvExtract (Proxy @47) (Proxy @40) a, bvExtract (Proxy @39) (Proxy @32) a
, bvExtract (Proxy @31) (Proxy @24) a, bvExtract (Proxy @23) (Proxy @16) a, bvExtract (Proxy @15) (Proxy @8) a, bvExtract (Proxy @7) (Proxy @0) a
]
fromBytes as
| l == 32
= (fromBytes :: [SWord 8] -> SWord 128) (take 16 as) # fromBytes (drop 16 as)
| True
= error $ "fromBytes:SWord 256: Incorrect number of bytes: " ++ show l
where l = length as
instance ByteConverter (SWord 512) where
toBytes a = [ bvExtract (Proxy @511) (Proxy @504) a, bvExtract (Proxy @503) (Proxy @496) a, bvExtract (Proxy @495) (Proxy @488) a, bvExtract (Proxy @487) (Proxy @480) a
, bvExtract (Proxy @479) (Proxy @472) a, bvExtract (Proxy @471) (Proxy @464) a, bvExtract (Proxy @463) (Proxy @456) a, bvExtract (Proxy @455) (Proxy @448) a
, bvExtract (Proxy @447) (Proxy @440) a, bvExtract (Proxy @439) (Proxy @432) a, bvExtract (Proxy @431) (Proxy @424) a, bvExtract (Proxy @423) (Proxy @416) a
, bvExtract (Proxy @415) (Proxy @408) a, bvExtract (Proxy @407) (Proxy @400) a, bvExtract (Proxy @399) (Proxy @392) a, bvExtract (Proxy @391) (Proxy @384) a
, bvExtract (Proxy @383) (Proxy @376) a, bvExtract (Proxy @375) (Proxy @368) a, bvExtract (Proxy @367) (Proxy @360) a, bvExtract (Proxy @359) (Proxy @352) a
, bvExtract (Proxy @351) (Proxy @344) a, bvExtract (Proxy @343) (Proxy @336) a, bvExtract (Proxy @335) (Proxy @328) a, bvExtract (Proxy @327) (Proxy @320) a
, bvExtract (Proxy @319) (Proxy @312) a, bvExtract (Proxy @311) (Proxy @304) a, bvExtract (Proxy @303) (Proxy @296) a, bvExtract (Proxy @295) (Proxy @288) a
, bvExtract (Proxy @287) (Proxy @280) a, bvExtract (Proxy @279) (Proxy @272) a, bvExtract (Proxy @271) (Proxy @264) a, bvExtract (Proxy @263) (Proxy @256) a
, bvExtract (Proxy @255) (Proxy @248) a, bvExtract (Proxy @247) (Proxy @240) a, bvExtract (Proxy @239) (Proxy @232) a, bvExtract (Proxy @231) (Proxy @224) a
, bvExtract (Proxy @223) (Proxy @216) a, bvExtract (Proxy @215) (Proxy @208) a, bvExtract (Proxy @207) (Proxy @200) a, bvExtract (Proxy @199) (Proxy @192) a
, bvExtract (Proxy @191) (Proxy @184) a, bvExtract (Proxy @183) (Proxy @176) a, bvExtract (Proxy @175) (Proxy @168) a, bvExtract (Proxy @167) (Proxy @160) a
, bvExtract (Proxy @159) (Proxy @152) a, bvExtract (Proxy @151) (Proxy @144) a, bvExtract (Proxy @143) (Proxy @136) a, bvExtract (Proxy @135) (Proxy @128) a
, bvExtract (Proxy @127) (Proxy @120) a, bvExtract (Proxy @119) (Proxy @112) a, bvExtract (Proxy @111) (Proxy @104) a, bvExtract (Proxy @103) (Proxy @96) a
, bvExtract (Proxy @95) (Proxy @88) a, bvExtract (Proxy @87) (Proxy @80) a, bvExtract (Proxy @79) (Proxy @72) a, bvExtract (Proxy @71) (Proxy @64) a
, bvExtract (Proxy @63) (Proxy @56) a, bvExtract (Proxy @55) (Proxy @48) a, bvExtract (Proxy @47) (Proxy @40) a, bvExtract (Proxy @39) (Proxy @32) a
, bvExtract (Proxy @31) (Proxy @24) a, bvExtract (Proxy @23) (Proxy @16) a, bvExtract (Proxy @15) (Proxy @8) a, bvExtract (Proxy @7) (Proxy @0) a
]
fromBytes as
| l == 64
= (fromBytes :: [SWord 8] -> SWord 256) (take 32 as) # fromBytes (drop 32 as)
| True
= error $ "fromBytes:SWord 512: Incorrect number of bytes: " ++ show l
where l = length as
instance ByteConverter (SWord 1024) where
toBytes a = [ bvExtract (Proxy @1023) (Proxy @1016) a, bvExtract (Proxy @1015) (Proxy @1008) a, bvExtract (Proxy @1007) (Proxy @1000) a, bvExtract (Proxy @999) (Proxy @992) a
, bvExtract (Proxy @991) (Proxy @984) a, bvExtract (Proxy @983) (Proxy @976) a, bvExtract (Proxy @975) (Proxy @968) a, bvExtract (Proxy @967) (Proxy @960) a
, bvExtract (Proxy @959) (Proxy @952) a, bvExtract (Proxy @951) (Proxy @944) a, bvExtract (Proxy @943) (Proxy @936) a, bvExtract (Proxy @935) (Proxy @928) a
, bvExtract (Proxy @927) (Proxy @920) a, bvExtract (Proxy @919) (Proxy @912) a, bvExtract (Proxy @911) (Proxy @904) a, bvExtract (Proxy @903) (Proxy @896) a
, bvExtract (Proxy @895) (Proxy @888) a, bvExtract (Proxy @887) (Proxy @880) a, bvExtract (Proxy @879) (Proxy @872) a, bvExtract (Proxy @871) (Proxy @864) a
, bvExtract (Proxy @863) (Proxy @856) a, bvExtract (Proxy @855) (Proxy @848) a, bvExtract (Proxy @847) (Proxy @840) a, bvExtract (Proxy @839) (Proxy @832) a
, bvExtract (Proxy @831) (Proxy @824) a, bvExtract (Proxy @823) (Proxy @816) a, bvExtract (Proxy @815) (Proxy @808) a, bvExtract (Proxy @807) (Proxy @800) a
, bvExtract (Proxy @799) (Proxy @792) a, bvExtract (Proxy @791) (Proxy @784) a, bvExtract (Proxy @783) (Proxy @776) a, bvExtract (Proxy @775) (Proxy @768) a
, bvExtract (Proxy @767) (Proxy @760) a, bvExtract (Proxy @759) (Proxy @752) a, bvExtract (Proxy @751) (Proxy @744) a, bvExtract (Proxy @743) (Proxy @736) a
, bvExtract (Proxy @735) (Proxy @728) a, bvExtract (Proxy @727) (Proxy @720) a, bvExtract (Proxy @719) (Proxy @712) a, bvExtract (Proxy @711) (Proxy @704) a
, bvExtract (Proxy @703) (Proxy @696) a, bvExtract (Proxy @695) (Proxy @688) a, bvExtract (Proxy @687) (Proxy @680) a, bvExtract (Proxy @679) (Proxy @672) a
, bvExtract (Proxy @671) (Proxy @664) a, bvExtract (Proxy @663) (Proxy @656) a, bvExtract (Proxy @655) (Proxy @648) a, bvExtract (Proxy @647) (Proxy @640) a
, bvExtract (Proxy @639) (Proxy @632) a, bvExtract (Proxy @631) (Proxy @624) a, bvExtract (Proxy @623) (Proxy @616) a, bvExtract (Proxy @615) (Proxy @608) a
, bvExtract (Proxy @607) (Proxy @600) a, bvExtract (Proxy @599) (Proxy @592) a, bvExtract (Proxy @591) (Proxy @584) a, bvExtract (Proxy @583) (Proxy @576) a
, bvExtract (Proxy @575) (Proxy @568) a, bvExtract (Proxy @567) (Proxy @560) a, bvExtract (Proxy @559) (Proxy @552) a, bvExtract (Proxy @551) (Proxy @544) a
, bvExtract (Proxy @543) (Proxy @536) a, bvExtract (Proxy @535) (Proxy @528) a, bvExtract (Proxy @527) (Proxy @520) a, bvExtract (Proxy @519) (Proxy @512) a
, bvExtract (Proxy @511) (Proxy @504) a, bvExtract (Proxy @503) (Proxy @496) a, bvExtract (Proxy @495) (Proxy @488) a, bvExtract (Proxy @487) (Proxy @480) a
, bvExtract (Proxy @479) (Proxy @472) a, bvExtract (Proxy @471) (Proxy @464) a, bvExtract (Proxy @463) (Proxy @456) a, bvExtract (Proxy @455) (Proxy @448) a
, bvExtract (Proxy @447) (Proxy @440) a, bvExtract (Proxy @439) (Proxy @432) a, bvExtract (Proxy @431) (Proxy @424) a, bvExtract (Proxy @423) (Proxy @416) a
, bvExtract (Proxy @415) (Proxy @408) a, bvExtract (Proxy @407) (Proxy @400) a, bvExtract (Proxy @399) (Proxy @392) a, bvExtract (Proxy @391) (Proxy @384) a
, bvExtract (Proxy @383) (Proxy @376) a, bvExtract (Proxy @375) (Proxy @368) a, bvExtract (Proxy @367) (Proxy @360) a, bvExtract (Proxy @359) (Proxy @352) a
, bvExtract (Proxy @351) (Proxy @344) a, bvExtract (Proxy @343) (Proxy @336) a, bvExtract (Proxy @335) (Proxy @328) a, bvExtract (Proxy @327) (Proxy @320) a
, bvExtract (Proxy @319) (Proxy @312) a, bvExtract (Proxy @311) (Proxy @304) a, bvExtract (Proxy @303) (Proxy @296) a, bvExtract (Proxy @295) (Proxy @288) a
, bvExtract (Proxy @287) (Proxy @280) a, bvExtract (Proxy @279) (Proxy @272) a, bvExtract (Proxy @271) (Proxy @264) a, bvExtract (Proxy @263) (Proxy @256) a
, bvExtract (Proxy @255) (Proxy @248) a, bvExtract (Proxy @247) (Proxy @240) a, bvExtract (Proxy @239) (Proxy @232) a, bvExtract (Proxy @231) (Proxy @224) a
, bvExtract (Proxy @223) (Proxy @216) a, bvExtract (Proxy @215) (Proxy @208) a, bvExtract (Proxy @207) (Proxy @200) a, bvExtract (Proxy @199) (Proxy @192) a
, bvExtract (Proxy @191) (Proxy @184) a, bvExtract (Proxy @183) (Proxy @176) a, bvExtract (Proxy @175) (Proxy @168) a, bvExtract (Proxy @167) (Proxy @160) a
, bvExtract (Proxy @159) (Proxy @152) a, bvExtract (Proxy @151) (Proxy @144) a, bvExtract (Proxy @143) (Proxy @136) a, bvExtract (Proxy @135) (Proxy @128) a
, bvExtract (Proxy @127) (Proxy @120) a, bvExtract (Proxy @119) (Proxy @112) a, bvExtract (Proxy @111) (Proxy @104) a, bvExtract (Proxy @103) (Proxy @96) a
, bvExtract (Proxy @95) (Proxy @88) a, bvExtract (Proxy @87) (Proxy @80) a, bvExtract (Proxy @79) (Proxy @72) a, bvExtract (Proxy @71) (Proxy @64) a
, bvExtract (Proxy @63) (Proxy @56) a, bvExtract (Proxy @55) (Proxy @48) a, bvExtract (Proxy @47) (Proxy @40) a, bvExtract (Proxy @39) (Proxy @32) a
, bvExtract (Proxy @31) (Proxy @24) a, bvExtract (Proxy @23) (Proxy @16) a, bvExtract (Proxy @15) (Proxy @8) a, bvExtract (Proxy @7) (Proxy @0) a
]
fromBytes as
| l == 128
= (fromBytes :: [SWord 8] -> SWord 512) (take 64 as) # fromBytes (drop 64 as)
| True
= error $ "fromBytes:SWord 1024: Incorrect number of bytes: " ++ show l
where l = length as