{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_HADDOCK show-extensions #-}
module Clash.Sized.BitVector
(
Bit
, high
, low
, BitVector
, size#
, maxIndex#
, bLit
, hLit
, oLit
, (++#)
, (+>>.)
, (.<<+)
, bitPattern
)
where
import Clash.Sized.Internal.BitVector
import Clash.Promoted.Nat (SNat(..), SNatLE(..), compareSNat, natToNum)
import Data.Bits (shiftL, shiftR)
import GHC.TypeNats (KnownNat)
infixr 4 +>>.
(+>>.) :: forall n. KnownNat n => Bit -> BitVector n -> BitVector n
Bit
b +>>. :: Bit -> BitVector n -> BitVector n
+>>. BitVector n
bv = case SNat n -> SNat 0 -> SNatLE n 0
forall (a :: Nat) (b :: Nat). SNat a -> SNat b -> SNatLE a b
compareSNat (KnownNat n => SNat n
forall (n :: Nat). KnownNat n => SNat n
SNat @n) (KnownNat 0 => SNat 0
forall (n :: Nat). KnownNat n => SNat n
SNat @0) of
SNatLE n 0
SNatGT -> BitVector n -> Int -> Bit -> BitVector n
forall (n :: Nat).
KnownNat n =>
BitVector n -> Int -> Bit -> BitVector n
replaceBit# (BitVector n -> Int -> BitVector n
forall a. Bits a => a -> Int -> a
shiftR BitVector n
bv Int
1) (forall a. (Num a, KnownNat n) => a
forall (n :: Nat) a. (Num a, KnownNat n) => a
natToNum @n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Bit
b
SNatLE n 0
SNatLE -> BitVector n
bv
infixr 4 .<<+
(.<<+) :: forall n. KnownNat n => BitVector n -> Bit -> BitVector n
BitVector n
bv .<<+ :: BitVector n -> Bit -> BitVector n
.<<+ Bit
b = case SNat n -> SNat 0 -> SNatLE n 0
forall (a :: Nat) (b :: Nat). SNat a -> SNat b -> SNatLE a b
compareSNat (KnownNat n => SNat n
forall (n :: Nat). KnownNat n => SNat n
SNat @n) (KnownNat 0 => SNat 0
forall (n :: Nat). KnownNat n => SNat n
SNat @0) of
SNatLE n 0
SNatGT -> BitVector n -> Int -> Bit -> BitVector n
forall (n :: Nat).
KnownNat n =>
BitVector n -> Int -> Bit -> BitVector n
replaceBit# (BitVector n -> Int -> BitVector n
forall a. Bits a => a -> Int -> a
shiftL BitVector n
bv Int
1) Int
0 Bit
b
SNatLE n 0
SNatLE -> BitVector n
bv