From 6e3b3e91789c924a723133fcf73f1ed933aaf343 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Mon, 24 Mar 2025 22:46:42 -0400 Subject: [PATCH] Preliminary cleaning before repairing TagEngine * clean up state machine in Top * `requestTag` method now emits Maybe type * put more thought into comments around asynchronous bus --- bs/BusTypes.bs | 6 ++-- bs/TagEngine.bs | 30 ++++++++++++++++++-- bs/Top.bs | 74 ++++++++++++++++++++++++------------------------- 3 files changed, 67 insertions(+), 43 deletions(-) diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index d633ee6..99d0fb4 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -57,9 +57,9 @@ interface BusMaster = -- This has implications about for the implementor of BusMaster, namely, that it -- should hold its request until it's request method gets called. request :: BusRequest - -- From the masters's perspective, the response should not be called until - -- the client is ready to accept the response. In other words, response - -- should be guarded by the client. + -- From the masters's perspective, the response should not be called by the + -- arbiter until the master is ready to accept the response. In other words, + -- response should be guarded by the client. response :: BusResponse -> Action type Token = UInt 5 diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index df60839..4d67898 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -9,7 +9,7 @@ import Util #define UIntLog2N(n) (UInt (TLog n)) interface (TagEngine :: # -> *) numTags = - requestTag :: ActionValue UIntLog2N(numTags) + requestTag :: ActionValue (Maybe UIntLog2N(numTags)) retireTag :: UIntLog2N(numTags) -> ActionValue BasicResult -- The tag engine returns a tag that is unique for the duration of @@ -19,6 +19,7 @@ interface (TagEngine :: # -> *) numTags = mkTagEngine :: Module (TagEngine numTags) mkTagEngine = do + let reifiedNumTags = fromInteger |> valueOf numTags freeStackVec :: Vector numTags (Reg UIntLog2N(numTags)) @@ -30,8 +31,20 @@ mkTagEngine = stackPtr :: (Reg (Maybe(UIntLog2N(numTags)))) stackPtr <- mkReg |> Just |> reifiedNumTags - 1 + methodRequestTagCalled :: PulseWire + methodRequestTagCalled <- mkPulseWire + + + methodRetireTagCalled :: PulseWire + methodRetireTagCalled <- mkPulseWire + + tagResponse :: RWire UIntLog2N(numTags) + tagResponse <- mkRWireSBR + debugOnce <- mkReg True + tt :: Reg Bool <- mkReg False + addRules $ rules "display": when (debugOnce == True) ==> @@ -40,20 +53,30 @@ mkTagEngine = $display "inUseVec : " (fshow |> readVReg inUseVec) $display "stackPtr : " (fshow stackPtr) debugOnce := False + <+> + rules + when (methodRequestTagCalled && methodRetireTagCalled) ==> + do + $display "ho ho ho" + -- let + -- nextStackPtr = + -- case of (methodRequestTagCalled, methodRetireTagCalled) of + -- (True, True) -> counter <- mkReg(0 :: UIntLog2N(numTags)) return $ interface TagEngine - requestTag :: ActionValue UIntLog2N(numTags) + requestTag :: ActionValue (Maybe UIntLog2N(numTags)) requestTag = do + methodRequestTagCalled.send stackPtr := if sampledStackPtr == 0 then Nothing else Just |> sampledStackPtr - 1 (select inUseVec sampledStackPtr) := True - return |> readReg (select freeStackVec sampledStackPtr) + return |> Just |> readReg (select freeStackVec sampledStackPtr) when Just sampledStackPtr <- stackPtr @@ -64,6 +87,7 @@ mkTagEngine = retireTag :: UIntLog2N(numTags) -> ActionValue BasicResult retireTag tag = do + methodRetireTagCalled.send let tagValid = tag < reifiedNumTags tagInUse = readReg (select inUseVec tag) diff --git a/bs/Top.bs b/bs/Top.bs index 59344b2..023fce2 100644 --- a/bs/Top.bs +++ b/bs/Top.bs @@ -108,43 +108,43 @@ mkSim = do core :: Core FCLK <- mkCore; s :: ActionSeq - s <- actionSeq - $ do - $display "got tag : " tagEngine.requestTag - |> do - $display "got tag : " tagEngine.requestTag - |> do - $display "got tag : " tagEngine.requestTag - |> do - res <- tagEngine.retireTag 3 - $display "retiring tag : 3 " (fshow res) - action {} - |> do - $display "got tag : " tagEngine.requestTag - |> do - $display "got tag : " tagEngine.requestTag - |> do - res <- tagEngine.retireTag 4 - $display "retiring tag : 4 " (fshow res) - action {} - |> do - res <- tagEngine.retireTag 4 - $display "retiring tag : 4 " (fshow res) - action {} - |> do - res <- tagEngine.retireTag 0 - $display "retiring tag : 0 " (fshow res) - action {} - |> do - $display "got tag : " tagEngine.requestTag - |> do - $display "got tag : " tagEngine.requestTag - |> do - res <- tagEngine.retireTag 1 - $display "retiring tag : 1 " (fshow res) - action {} - |> do - $display "got tag : " tagEngine.requestTag + s <- + let + requestTagAction :: Action + requestTagAction = + do + tag <- tagEngine.requestTag + $display "got tag : " (fshow tag) + in + actionSeq $ + do requestTagAction + |> do requestTagAction + |> do requestTagAction + |> do + res <- tagEngine.retireTag 3 + $display "retiring tag : 3 " (fshow res) + action {} + |> do requestTagAction + |> do requestTagAction + |> do + res <- tagEngine.retireTag 4 + $display "retiring tag : 4 " (fshow res) + action {} + |> do + res <- tagEngine.retireTag 4 + $display "retiring tag : 4 " (fshow res) + action {} + |> do + res <- tagEngine.retireTag 0 + $display "retiring tag : 0 " (fshow res) + action {} + |> do requestTagAction + |> do requestTagAction + |> do + res <- tagEngine.retireTag 1 + $display "retiring tag : 1 " (fshow res) + action {} + |> do requestTagAction addRules $ rules