Tag Engine Now Finished it seems #10

Merged
Yehowshua merged 12 commits from tag_engine_version_3 into main 2025-04-08 01:32:40 +00:00
2 changed files with 57 additions and 23 deletions
Showing only changes of commit ca59e6eaec - Show all commits

View file

@ -7,6 +7,7 @@ import Vector
import Util import Util
import FIFO import FIFO
import FIFOF import FIFOF
import SpecialFIFOs
#define UIntLog2N(n) (UInt (TLog n)) #define UIntLog2N(n) (UInt (TLog n))
@ -23,7 +24,7 @@ mkTagEngine =
do do
let reifiedNumTags = fromInteger |> valueOf numTags let reifiedNumTags = fromInteger |> valueOf numTags
-- we really only use tagUsageTracker after emptying out our -- we really only use tagUsageTracker after emptying out our
-- `initialTagDistributor` buffer -- `initialTagDistributor` buffer
tagUsageTracker :: Vector numTags (Reg Bool) tagUsageTracker :: Vector numTags (Reg Bool)
tagUsageTracker <- replicateM |> mkReg False tagUsageTracker <- replicateM |> mkReg False
@ -32,13 +33,19 @@ mkTagEngine =
-- reset, we can pretend as if the buffer within our tagFIFO is populated -- reset, we can pretend as if the buffer within our tagFIFO is populated
-- with sequentially incrementing values(starting from 0) on reset -- with sequentially incrementing values(starting from 0) on reset
-- by having our tag engine effectively return the value of a decrementing -- by having our tag engine effectively return the value of a decrementing
-- counter initialized to (numTags - 1) for the first n tag requests made -- counter initialized to (numTags - 1) for the first n tag requests made
-- to TagEngine where `n := numTags`. -- to TagEngine where `n := numTags`.
initialTagDistributor :: (Reg (Maybe UIntLog2N(numTags))) initialTagDistributor :: (Reg (Maybe UIntLog2N(numTags)))
initialTagDistributor <- mkReg |> Just |> reifiedNumTags - 1 initialTagDistributor <- mkReg |> Just |> reifiedNumTags - 1
retireTag :: Wire UIntLog2N(numTags) validatedTagToRetire :: FIFO UIntLog2N(numTags)
retireTag <- mkWire validatedTagToRetire <- mkBypassFIFO
updateUsageRetireTag :: RWire UIntLog2N(numTags)
updateUsageRetireTag <- mkRWire
updateUsageRequestTag :: RWire UIntLog2N(numTags)
updateUsageRequestTag <- mkRWire
tagFIFO :: FIFOF UIntLog2N(numTags) tagFIFO :: FIFOF UIntLog2N(numTags)
tagFIFO <- mkSizedFIFOF reifiedNumTags tagFIFO <- mkSizedFIFOF reifiedNumTags
@ -51,12 +58,39 @@ mkTagEngine =
do do
$display "tagUsageTracker : " (fshow |> readVReg tagUsageTracker) $display "tagUsageTracker : " (fshow |> readVReg tagUsageTracker)
debugOnce := False 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 ==> "retire_tags": when True ==>
do do
$display "firing retire_tags" (fshow retireTag) let tagToRetire = validatedTagToRetire.first
tagFIFO.enq retireTag $display "firing retire_tags" (fshow tagToRetire)
(select tagUsageTracker retireTag) := False validatedTagToRetire.deq
tagFIFO.enq tagToRetire
updateUsageRetireTag.wset tagToRetire
return $ return $
interface TagEngine interface TagEngine
@ -67,18 +101,19 @@ mkTagEngine =
case initialTagDistributor of case initialTagDistributor of
Just 0 -> do Just 0 -> do
initialTagDistributor := Nothing initialTagDistributor := Nothing
(select tagUsageTracker 0) := True updateUsageRequestTag.wset 0
return 0 return 0
Just tag -> do Just tag -> do
initialTagDistributor := Just |> tag - 1 initialTagDistributor := Just |> tag - 1
(select tagUsageTracker tag) := True updateUsageRequestTag.wset tag
return tag return tag
Nothing -> do Nothing -> do
let tag = tagFIFO.first let tag = tagFIFO.first
tagFIFO.deq tagFIFO.deq
updateUsageRequestTag.wset tag
return tag return tag
-- `retireTag` isn't guarded on tag validity(this would break Bluespec's safety model) -- `retireTag` isn't guarded on tag validity(this would break Bluespec's safety model)
-- so it is advisable that the caller of `retireTag` only attempt to retire valid tags. -- so it is advisable that the caller of `retireTag` only attempt to retire valid tags.
-- Internally, the tagEngine will keep a correct and consistent state since TagEngine -- Internally, the tagEngine will keep a correct and consistent state since TagEngine
-- validates tags before attempting to retire them. -- validates tags before attempting to retire them.
@ -90,6 +125,6 @@ mkTagEngine =
tagInUse = readReg (select tagUsageTracker tag) tagInUse = readReg (select tagUsageTracker tag)
if (tagValid && tagInUse) if (tagValid && tagInUse)
then do then do
retireTag := tag validatedTagToRetire.enq tag
else do else do
action {} action {}

View file

@ -6,23 +6,22 @@ import ActionSeq
mkTagEngineTester :: Module Empty mkTagEngineTester :: Module Empty
mkTagEngineTester = do mkTagEngineTester = do
tagEngine :: TagEngine 5 <- mkTagEngine tagEngine :: TagEngine 5 <- mkTagEngine
count :: Reg (UInt 32) <- mkReg 0;
runOnce :: Reg Bool <- mkReg False runOnce :: Reg Bool <- mkReg False
s :: ActionSeq s :: ActionSeq
s <- s <-
let let
requestTagAction :: Action requestTagAction :: Action
requestTagAction = requestTagAction =
do do
tag <- tagEngine.requestTag tag <- tagEngine.requestTag
$display "got tag : " (fshow tag) $display $time " got tag : " (fshow tag)
retireTagAction :: UInt 3 -> Action retireTagAction :: UInt 3 -> Action
retireTagAction tag = retireTagAction tag =
do do
res <- tagEngine.retireTag tag res <- tagEngine.retireTag tag
$display "retiring tag : " (fshow tag) " " (fshow res) $display $time " retiring tag : " (fshow tag) " " (fshow res)
action {} action {}
in in
@ -34,12 +33,12 @@ mkTagEngineTester = do
|> do requestTagAction |> do requestTagAction
|> do retireTagAction 2 |> do retireTagAction 2
-- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST"
|> do |> do
retireTagAction 4 retireTagAction 4
requestTagAction requestTagAction
-- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST"
-- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST"
|> do |> do
retireTagAction 4 retireTagAction 4
requestTagAction requestTagAction
-- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST"
@ -55,11 +54,11 @@ mkTagEngineTester = do
addRules $ addRules $
rules rules
"counter": when True ==> -- "counter": when True ==>
do -- do
count := count + 1 -- count := count + 1
$display "count : " (fshow count) -- $display "count : " (fshow count)
"testIncrement": when (runOnce == False) ==> "testIncrement": when (runOnce == False) ==>
do do
s.start s.start
runOnce := True runOnce := True