|
| 1 | +package ATFCacheHit where |
| 2 | + |
| 3 | +-- Test that a ground ATF resolution recorded by ctxreduce during |
| 4 | +-- typecheck is delivered to iExpand and HITS in the ATF cache. |
| 5 | +-- forceGround solves Encode ((UInt 5, UInt 5)) monomorphically at |
| 6 | +-- typecheck time, so EncSize ((UInt 5, UInt 5)) is recorded ground; |
| 7 | +-- elaborating checkPair's polymorphic body at (UInt 5, UInt 5) then |
| 8 | +-- finds it in the cache instead of falling back to normTFun. |
| 9 | +-- (Cache-hit twin of ATFPolyCacheMiss.bs.) |
| 10 | + |
| 11 | +class Encode a n | a -> n where |
| 12 | + type EncSize a = n |
| 13 | + encode :: a -> Bit n |
| 14 | + |
| 15 | +instance Encode (UInt k) k where |
| 16 | + encode x = pack x |
| 17 | + |
| 18 | +instance Encode Bool 1 where |
| 19 | + encode True = 1 |
| 20 | + encode False = 0 |
| 21 | + |
| 22 | +instance (Encode a sa, Encode b sb) => Encode (a, b) (TAdd sa sb) where |
| 23 | + encode (x, y) = encode x ++ encode y |
| 24 | + |
| 25 | +data Encoded a = Encoded (Bit (EncSize a)) |
| 26 | + |
| 27 | +wrap :: (Encode a sa) => a -> Encoded a |
| 28 | +wrap x = Encoded (encode x) |
| 29 | + |
| 30 | +checkPair :: (Encode a sa) => a -> Bool |
| 31 | +checkPair x = case wrap (x, x) of |
| 32 | + Encoded b -> msb b == 1 |
| 33 | + |
| 34 | +-- The monomorphic forcing definition: typechecking this solves |
| 35 | +-- Encode ((UInt 5, UInt 5)) ground and records its EncSize result. |
| 36 | +forceGround :: (UInt 5, UInt 5) -> Encoded (UInt 5, UInt 5) |
| 37 | +forceGround p = wrap p |
| 38 | + |
| 39 | +{-# verilog sysATFCacheHit #-} |
| 40 | +sysATFCacheHit :: Module Empty |
| 41 | +sysATFCacheHit = module |
| 42 | + r :: Reg (UInt 5) <- mkReg 7 |
| 43 | + rules |
| 44 | + "test": when True ==> |
| 45 | + action |
| 46 | + let result = checkPair r |
| 47 | + $display "result: %b" (pack result) |
| 48 | + $finish 0 |
0 commit comments