riscv-bluespec-classic/bs/TagEngine.bs
2025-03-20 00:10:00 -04:00

72 lines
2 KiB
Haskell

package TagEngine(TagEngine(..), mkTagEngine) where
import Vector
import Util
#define UIntLog2N(n) (UInt (TLog n))
data Tag numTags
= Next UIntLog2N(numTags)
| Tail
deriving (Bits, Eq, FShow)
interface (TagEngine :: # -> *) numTags =
requestTag :: ActionValue UIntLog2N(numTags)
retireTag :: UIntLog2N(numTags) -> Action
initTagNext :: Integer -> Module(Reg (Tag numTags))
initTagNext i = do
t :: Reg (Tag numTags)
t <- mkReg (Next (fromInteger i))
return t
initTagTail :: Module(Reg (Tag numTags))
initTagTail = do
t :: Reg (Tag numTags)
t <- mkReg Tail
return t
initTagVec :: Module(Vector numTags (Reg (Tag numTags)))
initTagVec =
do
tagVecSequential :: Vector numTags (Reg (Tag numTags))
tagVecSequential <- mapM (\idx -> initTagNext (idx+1)) genVector
let idxLast :: Integer = (fromInteger |> valueOf numTags) - 1
tailTag <- initTagTail
-- the tail of our TagVec should be `Tail` not `Next`
let finalTagVec = update tagVecSequential idxLast tailTag
return finalTagVec
mkTagEngine :: Module (TagEngine numTags)
mkTagEngine =
do
tagVec :: Vector numTags (Reg (Tag numTags))
tagVec <- initTagVec
fileHandle :: Handle <- openFile "compile.log" WriteMode
cycle <- mkReg 0
end_cycle <- mkReg 4
addRules (simulate_for cycle end_cycle)
addRules $
rules
"display": when True ==>
do
$display (fshow (tagVec !! 0))
$finish
counter <- mkReg(0 :: UIntLog2N(numTags))
return $
interface TagEngine
requestTag :: ActionValue UIntLog2N(numTags)
requestTag = do
-- placeholder
counter := counter + 1
return counter
retireTag :: UIntLog2N(numTags) -> Action
retireTag tag = do
-- placeholder
counter := 0