Greatly simpliflied tag engine to use stack implementation. Having trouble guarding on interface argument...

This commit is contained in:
Yehowshua Immanuel 2025-03-23 08:12:24 -04:00
parent 8e27ca877f
commit c5ad62aaed
2 changed files with 35 additions and 63 deletions

View file

@ -7,55 +7,23 @@ import Util
#define UIntLog2N(n) (UInt (TLog n)) #define UIntLog2N(n) (UInt (TLog n))
data Tag numTags
= Next UIntLog2N(numTags)
| Freed
| Tail
deriving (Bits, Eq, FShow)
data TagPtr numTags
= SomeTagPtr UIntLog2N(numTags)
| None
deriving (Bits, Eq, FShow)
interface (TagEngine :: # -> *) numTags = interface (TagEngine :: # -> *) numTags =
requestTag :: ActionValue UIntLog2N(numTags) requestTag :: ActionValue UIntLog2N(numTags)
retireTag :: UIntLog2N(numTags) -> Action retireTag :: UIntLog2N(numTags) -> Action
instance FShow (Reg (Tag numTags)) where
fshow value = fshow (readReg value)
initTagNext :: Integer -> Module(Reg (Tag numTags))
initTagNext i = do
t :: Reg (Tag numTags)
t <- mkReg (Next (fromInteger i))
return t
initTagTail :: Module(Reg (Tag numTags))
initTagTail = do
t :: Reg (Tag numTags)
t <- mkReg Tail
return t
initTagVec :: Module(Vector numTags (Reg (Tag numTags)))
initTagVec =
let
lastIdx :: Integer = (fromInteger |> valueOf numTags) - 1
initByIdx currIdx =
if (currIdx < lastIdx)
then initTagNext (currIdx + 1)
else initTagTail
in
mapM initByIdx genVector
mkTagEngine :: Module (TagEngine numTags) mkTagEngine :: Module (TagEngine numTags)
mkTagEngine = mkTagEngine =
do do
tagVec :: Vector numTags (Reg (Tag numTags)) let reifiedNumTags = fromInteger |> valueOf numTags
tagVec <- initTagVec
head :: Reg(TagPtr(numTags)) <- mkReg(SomeTagPtr(0)) freeStackVec :: Vector numTags (Reg UIntLog2N(numTags))
tail :: Reg(TagPtr(numTags)) <- mkReg(SomeTagPtr(lastIdx)) freeStackVec <- mapM (\i -> mkReg |> fromInteger i) genVector
inUseVec :: Vector numTags (Reg Bool)
inUseVec <- replicateM |> mkReg False
stackPtr :: (Reg (Maybe(UIntLog2N(numTags))))
stackPtr <- mkReg |> Just |> reifiedNumTags - 1
debugOnce <- mkReg True debugOnce <- mkReg True
@ -63,35 +31,37 @@ mkTagEngine =
rules rules
"display": when (debugOnce == True) ==> "display": when (debugOnce == True) ==>
do do
$display (fshow tagVec) $display "freeStackVec : " (fshow |> readVReg freeStackVec)
$display "inUseVec : " (fshow |> readVReg inUseVec)
$display "stackPtr : " (fshow stackPtr)
debugOnce := False debugOnce := False
counter <- mkReg(0 :: UIntLog2N(numTags)) counter <- mkReg(0 :: UIntLog2N(numTags))
return $ return $
interface TagEngine interface TagEngine
requestTag :: ActionValue UIntLog2N(numTags) requestTag :: ActionValue UIntLog2N(numTags)
requestTag = requestTag =
do do
let currHeadPtr :: UIntLog2N(numTags) = stackPtr :=
case head of if sampledStackPtr == 0
SomeTagPtr ptr -> ptr then Nothing
-- we technically will never hit this arm else Just |> sampledStackPtr - 1
-- due to when guard `SomeTagPtr ptr <- head` (select inUseVec sampledStackPtr) := True
None -> 0 return |> readReg (select freeStackVec sampledStackPtr)
let currHead :: (Reg (Tag numTags)) = (select tagVec currHeadPtr)
let nextHeadPtr :: UIntLog2N(numTags) =
case currHead of
Next ptr -> ptr
-- TODO : handle tail correctly
Tail -> 0
currHead := Freed
head := SomeTagPtr(nextHeadPtr)
return nextHeadPtr
when when
SomeTagPtr ptr <- head Just sampledStackPtr <- stackPtr
retireTag :: UIntLog2N(numTags) -> Action retireTag :: UIntLog2N(numTags) -> Action
retireTag tag = do retireTag tag =
-- placeholder do
counter := 0 let nextStackPtrUint =
where case stackPtr of
lastIdx :: UIntLog2N(numTags) = (fromInteger |> valueOf numTags) - 1 Nothing -> 0
Just n -> n + 1
(select inUseVec tag) := False
(select freeStackVec nextStackPtrUint) := tag
stackPtr := Just nextStackPtrUint
-- when
-- tag < (reifiedNumTags - 1),
-- readReg (select inUseVec tag)

View file

@ -1,5 +1,7 @@
package Util((|>), simulate_for) where package Util((|>), simulate_for) where
infixr 0 |>
(|>) :: (a -> b) -> a -> b (|>) :: (a -> b) -> a -> b
f |> x = f x; f |> x = f x;