handled tag engine edge case

This commit is contained in:
Yehowshua Immanuel 2025-04-04 15:09:56 -04:00
parent 271148e538
commit ca59e6eaec
2 changed files with 57 additions and 23 deletions

View file

@ -7,6 +7,7 @@ import Vector
import Util
import FIFO
import FIFOF
import SpecialFIFOs
#define UIntLog2N(n) (UInt (TLog n))
@ -37,8 +38,14 @@ mkTagEngine =
initialTagDistributor :: (Reg (Maybe UIntLog2N(numTags)))
initialTagDistributor <- mkReg |> Just |> reifiedNumTags - 1
retireTag :: Wire UIntLog2N(numTags)
retireTag <- mkWire
validatedTagToRetire :: FIFO UIntLog2N(numTags)
validatedTagToRetire <- mkBypassFIFO
updateUsageRetireTag :: RWire UIntLog2N(numTags)
updateUsageRetireTag <- mkRWire
updateUsageRequestTag :: RWire UIntLog2N(numTags)
updateUsageRequestTag <- mkRWire
tagFIFO :: FIFOF UIntLog2N(numTags)
tagFIFO <- mkSizedFIFOF reifiedNumTags
@ -52,11 +59,38 @@ mkTagEngine =
$display "tagUsageTracker : " (fshow |> readVReg tagUsageTracker)
debugOnce := False
"update_usage_just_retire": when
Just tag <- updateUsageRetireTag.wget,
Nothing <- updateUsageRequestTag.wget ==>
do
$display $time " tagUsageTracker after update retire: " (fshow |> readVReg tagUsageTracker)
(select tagUsageTracker tag) := False
"update_usage_just_request": when
Nothing <- updateUsageRetireTag.wget,
Just tag <- updateUsageRequestTag.wget ==>
do
$display $time " tagUsageTracker after update request: " (fshow |> readVReg tagUsageTracker)
(select tagUsageTracker tag) := True
"update_usage_request_and_retire": when
Just retireTag <- updateUsageRetireTag.wget,
Just requestTag <- updateUsageRequestTag.wget ==>
do
$display $time " tagUsageTracker after update request and retire: " (fshow |> readVReg tagUsageTracker)
let
tagUsageTrackerInner = readVReg tagUsageTracker
tagUsageTracker' = update tagUsageTrackerInner requestTag True
tagUsageTracker'' = update tagUsageTracker' retireTag False
writeVReg tagUsageTracker tagUsageTracker''
"retire_tags": when True ==>
do
$display "firing retire_tags" (fshow retireTag)
tagFIFO.enq retireTag
(select tagUsageTracker retireTag) := False
let tagToRetire = validatedTagToRetire.first
$display "firing retire_tags" (fshow tagToRetire)
validatedTagToRetire.deq
tagFIFO.enq tagToRetire
updateUsageRetireTag.wset tagToRetire
return $
interface TagEngine
@ -67,15 +101,16 @@ mkTagEngine =
case initialTagDistributor of
Just 0 -> do
initialTagDistributor := Nothing
(select tagUsageTracker 0) := True
updateUsageRequestTag.wset 0
return 0
Just tag -> do
initialTagDistributor := Just |> tag - 1
(select tagUsageTracker tag) := True
updateUsageRequestTag.wset tag
return tag
Nothing -> do
let tag = tagFIFO.first
tagFIFO.deq
updateUsageRequestTag.wset tag
return tag
-- `retireTag` isn't guarded on tag validity(this would break Bluespec's safety model)
@ -90,6 +125,6 @@ mkTagEngine =
tagInUse = readReg (select tagUsageTracker tag)
if (tagValid && tagInUse)
then do
retireTag := tag
validatedTagToRetire.enq tag
else do
action {}

View file

@ -6,7 +6,6 @@ import ActionSeq
mkTagEngineTester :: Module Empty
mkTagEngineTester = do
tagEngine :: TagEngine 5 <- mkTagEngine
count :: Reg (UInt 32) <- mkReg 0;
runOnce :: Reg Bool <- mkReg False
s :: ActionSeq
@ -16,13 +15,13 @@ mkTagEngineTester = do
requestTagAction =
do
tag <- tagEngine.requestTag
$display "got tag : " (fshow tag)
$display $time " got tag : " (fshow tag)
retireTagAction :: UInt 3 -> Action
retireTagAction tag =
do
res <- tagEngine.retireTag tag
$display "retiring tag : " (fshow tag) " " (fshow res)
$display $time " retiring tag : " (fshow tag) " " (fshow res)
action {}
in
@ -55,10 +54,10 @@ mkTagEngineTester = do
addRules $
rules
"counter": when True ==>
do
count := count + 1
$display "count : " (fshow count)
-- "counter": when True ==>
-- do
-- count := count + 1
-- $display "count : " (fshow count)
"testIncrement": when (runOnce == False) ==>
do
s.start