Skip to content

Commit

Permalink
Add unary cells
Browse files Browse the repository at this point in the history
  • Loading branch information
dopamane committed Jun 8, 2024
1 parent 5888f9f commit a3fc44d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
58 changes: 54 additions & 4 deletions lib/Bayeux/Rtlil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ module Bayeux.Rtlil
, CellType(..)
, CellBodyStmt(..)
, CellEndStmt(..)
, -- *** Unary cells
unaryCell
, notC
, posC
, negC
, reduceAndC
, reduceOrC
, reduceXorC
, reduceXnorC
, reduceBoolC
, logicNotC
, -- *** Binary cells
binaryCell
, shiftCell
Expand Down Expand Up @@ -405,6 +416,45 @@ data CellEndStmt = CellEndStmt
instance Pretty CellEndStmt where
pretty _ = "end" <> hardline

unaryCell
:: CellStmt
-> Bool -- ^ \\A_SIGNED
-> Integer -- ^ \\A_WIDTH
-> Integer -- ^ \\Y_WIDTH
-> SigSpec -- ^ A
-> WireId -- ^ Y
-> Cell
unaryCell cellStmt aSigned aWidth yWidth a y = Cell
[]
cellStmt
[ CellParameter Nothing "\\A_SIGNED" $ ConstantInteger $ fromBool aSigned
, CellParameter Nothing "\\A_WIDTH" $ ConstantInteger aWidth
, CellParameter Nothing "\\Y_WIDTH" $ ConstantInteger yWidth
, CellConnect "\\A" a
, CellConnect "\\Y" $ SigSpecWireId y
]
CellEndStmt

-- unary cells
notC, posC, negC, reduceAndC, reduceOrC, reduceXorC, reduceXnorC, reduceBoolC, logicNotC
:: CellId
-> Bool
-> Integer
-> Integer
-> SigSpec
-> WireId
-> Cell

notC = unaryCell . CellStmt "$not"
posC = unaryCell . CellStmt "$pos"
negC = unaryCell . CellStmt "$neg"
reduceAndC = unaryCell . CellStmt "$reduce_and"
reduceOrC = unaryCell . CellStmt "$reduce_or"
reduceXorC = unaryCell . CellStmt "$reduce_xor"
reduceXnorC = unaryCell . CellStmt "$reduce_xnor"
reduceBoolC = unaryCell . CellStmt "$reduce_bool"
logicNotC = unaryCell . CellStmt "$logic_not"

binaryCell
:: CellStmt
-> Bool -- ^ \\A_SIGNED
Expand All @@ -429,10 +479,10 @@ binaryCell cellStmt aSigned aWidth bSigned bWidth yWidth a b y = Cell
, CellConnect "\\Y" $ SigSpecWireId y
]
CellEndStmt
where
fromBool :: Bool -> Integer
fromBool True = 1
fromBool False = 0

fromBool :: Bool -> Integer
fromBool True = 1
fromBool False = 0

shiftCell
:: CellStmt
Expand Down
1 change: 0 additions & 1 deletion test/Test/Bayeux/RgbCounter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module Test.Bayeux.RgbCounter
( tests
) where

import Test.Tasty
import Bayeux.RgbCounter
import Bayeux.Rtlil
import Data.String
Expand Down

0 comments on commit a3fc44d

Please sign in to comment.