From ed8e0b8337539e4de4fab80883c381bf18da2a1d Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Tue, 25 Mar 2025 01:15:49 -0400 Subject: [PATCH] tag engine now allows from simultaneous retire and request - but had to use unsafe --- bs/TagEngine.bs | 83 +++++++++++++++++++++++-------------- bs/Tests/TagEngineTester.bs | 13 ++++-- 2 files changed, 62 insertions(+), 34 deletions(-) diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index 4d67898..134e2c8 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -34,12 +34,8 @@ mkTagEngine = methodRequestTagCalled :: PulseWire methodRequestTagCalled <- mkPulseWire - - methodRetireTagCalled :: PulseWire - methodRetireTagCalled <- mkPulseWire - - tagResponse :: RWire UIntLog2N(numTags) - tagResponse <- mkRWireSBR + methodRetireTagCalledValid :: RWire UIntLog2N(numTags) + methodRetireTagCalledValid <- mkUnsafeRWire debugOnce <- mkReg True @@ -53,15 +49,48 @@ mkTagEngine = $display "inUseVec : " (fshow |> readVReg inUseVec) $display "stackPtr : " (fshow stackPtr) debugOnce := False - <+> - rules - when (methodRequestTagCalled && methodRetireTagCalled) ==> + + "update stack pointer": when True ==> do - $display "ho ho ho" - -- let - -- nextStackPtr = - -- case of (methodRequestTagCalled, methodRetireTagCalled) of - -- (True, True) -> + stackPtr := + case (methodRequestTagCalled, methodRetireTagCalledValid.wget) of + (True, Just tag) -> stackPtr + (True, Nothing) -> + case stackPtr of + Just 0 -> Nothing + Just sampledStackPtr -> Just |> sampledStackPtr - 1 + Nothing -> Nothing + (False, Just tag) -> + case stackPtr of + Just sampledStackPtr -> Just |> sampledStackPtr + 1 + Nothing -> Nothing + (False, Nothing) -> stackPtr + + "update free stack": when True ==> + do + case (methodRequestTagCalled, methodRetireTagCalledValid.wget) of + (True, Just tag) -> do action {} + (True, Nothing) -> do action {} + (False, Just tag) -> do + case stackPtr of + Just sampledStackPtr -> do + (select freeStackVec (sampledStackPtr + 1)) := tag + Nothing -> do + (select freeStackVec 0) := tag + (False, Nothing) -> do action {} + + "update in use": when True ==> + do + case (methodRequestTagCalled, methodRetireTagCalledValid.wget) of + (True, Just tag) -> do action {} + (True, Nothing) -> + case stackPtr of + Just sampledStackPtr -> do + (select inUseVec sampledStackPtr) := True + Nothing -> do action {} + (False, Just tag) -> do + (select inUseVec tag) := False + (False, Nothing) -> do action {} counter <- mkReg(0 :: UIntLog2N(numTags)) return $ @@ -71,23 +100,19 @@ mkTagEngine = requestTag = do methodRequestTagCalled.send - stackPtr := - if sampledStackPtr == 0 - then Nothing - else Just |> sampledStackPtr - 1 - (select inUseVec sampledStackPtr) := True - return |> Just |> readReg (select freeStackVec sampledStackPtr) - when - Just sampledStackPtr <- stackPtr + case methodRetireTagCalledValid.wget of + Just tag -> do + return |> Just tag + Nothing -> do + return |> + case stackPtr of + Just sampledStackPtr -> + Just |> readReg (select freeStackVec sampledStackPtr) + Nothing -> Nothing - -- retireTag isn't guarded so its up to external module to only attempt to - -- retire valid tags... At any rate, we can notify the requestor of failures - -- to retire tags - although the requestor can merely ignore this - -- notification. retireTag :: UIntLog2N(numTags) -> ActionValue BasicResult retireTag tag = do - methodRetireTagCalled.send let tagValid = tag < reifiedNumTags tagInUse = readReg (select inUseVec tag) @@ -97,9 +122,7 @@ mkTagEngine = Just n -> n + 1 if (tagValid && tagInUse) then do - (select inUseVec tag) := False - (select freeStackVec nextStackPtrUint) := tag - stackPtr := Just nextStackPtrUint + methodRetireTagCalledValid.wset tag return Success else do return Failure diff --git a/bs/Tests/TagEngineTester.bs b/bs/Tests/TagEngineTester.bs index 9cbab60..334b8d2 100644 --- a/bs/Tests/TagEngineTester.bs +++ b/bs/Tests/TagEngineTester.bs @@ -7,6 +7,7 @@ mkTagEngineTester :: Module Empty mkTagEngineTester = do tagEngine :: TagEngine 5 <- mkTagEngine count :: Reg (UInt 4) <- mkReg 0; + runOnce :: Reg Bool <- mkReg False s :: ActionSeq s <- @@ -30,7 +31,11 @@ mkTagEngineTester = do |> do requestTagAction |> do requestTagAction |> do retireTagAction 3 - |> do requestTagAction + |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" + |> do + retireTagAction 4 + requestTagAction + |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" |> do requestTagAction |> do retireTagAction 4 |> do retireTagAction 4 @@ -42,7 +47,7 @@ mkTagEngineTester = do addRules $ rules - "testIncrement": when (count < 10) ==> + "testIncrement": when (runOnce == False) ==> do - count := count + 1 - s.start \ No newline at end of file + s.start + runOnce := True \ No newline at end of file