From 35fc49382d605252b3c3aeccfefbf9ba36fd297c Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Sun, 23 Mar 2025 18:30:56 -0400 Subject: [PATCH] reverting as it seems we really cant condition rules on arguments safely --- bs/TagEngine.bs | 38 +++++++++++++------------------------- bs/Top.bs | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index 5b0e5a6..e43f468 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -9,8 +9,7 @@ import Util interface (TagEngine :: # -> *) numTags = requestTag :: ActionValue UIntLog2N(numTags) - setTagToRetire :: UIntLog2N(numTags) -> Action - retireTag :: Action + retireTag :: UIntLog2N(numTags) -> Action -- The tag engine returns a tag that is unique for the duration of -- the lifetime of the tag. Useful when you need to tag transactions @@ -30,9 +29,6 @@ mkTagEngine = stackPtr :: (Reg (Maybe(UIntLog2N(numTags)))) stackPtr <- mkReg |> Just |> reifiedNumTags - 1 - tagToRetire :: RWire (UIntLog2N(numTags)) - tagToRetire <- mkRWireSBR - debugOnce <- mkReg True addRules $ @@ -60,27 +56,19 @@ mkTagEngine = when Just sampledStackPtr <- stackPtr - setTagToRetire :: UIntLog2N(numTags) -> Action - setTagToRetire tag = - let - tagValid = tag < (reifiedNumTags - 1) - tagInUse = readReg (select inUseVec tag) - in - do - if (tagValid && tagInUse) - then do tagToRetire.wset tag - else do action {} - - retireTag :: Action - retireTag = + retireTag :: UIntLog2N(numTags) -> Action + retireTag tag = do - let nextStackPtrUint = + let + tagValid = tag < reifiedNumTags + tagInUse = readReg (select inUseVec tag) + nextStackPtrUint = case stackPtr of Nothing -> 0 Just n -> n + 1 - - (select freeStackVec nextStackPtrUint) := tag - stackPtr := Just nextStackPtrUint - (select inUseVec tag) := False - when - Valid tag <- tagToRetire.wget + if (tagValid && tagInUse) + then do + (select inUseVec tag) := False + (select freeStackVec nextStackPtrUint) := tag + stackPtr := Just nextStackPtrUint + else action {} diff --git a/bs/Top.bs b/bs/Top.bs index e361286..ef23502 100644 --- a/bs/Top.bs +++ b/bs/Top.bs @@ -8,6 +8,7 @@ import CBindings import Bus import TagEngine import List +import ActionSeq type FCLK = 25000000 type BAUD = 9600 @@ -102,12 +103,44 @@ mkSim = do let cfg :: BRAM_Configure = defaultValue tagEngine :: TagEngine 5 <- mkTagEngine - count :: Reg (UInt 3) <- mkReg 0; + count :: Reg (UInt 4) <- mkReg 0; initCFunctions :: Reg Bool <- mkReg False; 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 + $display "retiring tag : 3" + tagEngine.retireTag 3 + |> do + $display "got tag : " tagEngine.requestTag + |> do + $display "got tag : " tagEngine.requestTag + |> do + $display "retiring tag : 4" + tagEngine.retireTag 4 + |> do + $display "got tag : " tagEngine.requestTag + |> do + $display "got tag : " tagEngine.requestTag + |> do + $display "retiring tag : 1" + tagEngine.retireTag 1 + |> do + $display "got tag : " tagEngine.requestTag + addRules $ rules + "testIncrement": when (count < 10) ==> + do + count := count + 1 + s.start "initCFunctionsOnce": when not initCFunctions ==> do initTerminal