Skip to content

Commit

Permalink
Lava: Change Recipe to leverage the "do" syntax
Browse files Browse the repository at this point in the history
Fx, before:

shiftAndAdd s =
  While (s.b.val =/= 0) $
    Seq [ s.a <== low `vshr` (s.a.val)
        , s.b <== (s.b.val) `vshl` low
        , s.b.val.vhead |>
            s.result <== s.result.val + s.a.val
        , Tick
        ]

now

shiftAndAdd s = do
    while (s.b.val =/= 0) $do
       s.a <== low `vshr` (s.a.val)
       s.b <== (s.b.val) `vshl` low
       iff (s.b.val.vhead) $do
           s.result <== s.result.val + s.a.val
       tick

Note, this is a purely syntactic change, the effective code is exactly
the same as before.  This is but a step on the path to making
sequential logic more readable and mallable.
  • Loading branch information
tommythorn committed Sep 4, 2017
1 parent d807e0e commit 0b33651
Show file tree
Hide file tree
Showing 23 changed files with 480 additions and 484 deletions.
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,44 +86,43 @@ To build a hardware version of a given test
cd fpga; make && flite -r ../programs/$P | ./Red -v

where $P is one of the programs (.hs). Next, build a Reduceron system
for DE2-115:
for an FPGA board, fx the BeMicroCV A9:

make -C Reduceron/DE2-115
make -C Reduceron/BeMicroCV-A9

Unfortunately programs can't currently be loaded dynamically but are
baked into the FPGA image. It's a high priority goal to change that.

## WHERE IS THIS GOING?

Plan:
### Plan ###

1. Port to Verilog and Altera. DONE!
1. Port to Verilog and remove Xilinx-isms. DONE!

2. Shrink to fit mid-sized FPGA kits (eg. DE2-115). DONE!
2. Shrink to fit mid-sized FPGA kits (eg. DE2-115 and BeMicroCV-A9).
DONE!

3. Support load/store to an external bus (the key difficulty is stalling while waiting on the bus).
3. Rework Lava and the Reduceron implementation to be more
composable and elastic; this means fewer or no global assumptions
about timing. ONGOING!

4. Support load/store to an external bus (the key difficulty is
stalling while waiting on the bus).

4. Use the program memory as a cache, making programs dynamically loadable and dramatically raise the size limits.
5. Use the program memory as a cache, making programs dynamically
loadable and dramatically raise the size limits.

In some order:

- Add basic primitives (`(*)`, `(.&.)`, `(.|.)`, `(.^.)`, `(.<<.)`, `(.>>.)`, ...)
DONE: `(.&.)`

- Improve Lava simulation and RTL gen
- Add a C backend for much faster simulation
- Use names from the design
- generate busses where possible
- Make the design resettable
### Eventual Plan ###

- Move the heap [and tospace] to external memory
- Add a heap cache/newspace memory
- Implement the emu-32.c representation for the external heap

- Much richer primitives
- Haskell front-end

Finally: Performance improvements
### Long Term Plan ###

- Research the design space; explore parallelism

## OPEN QUESTIONS, with answers from Matthew:

Expand Down
49 changes: 25 additions & 24 deletions fpga/CachingOctostack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Lava
import Recipe
import Data.List
import Bytecode
import Control.Monad (zipWithM_)

-- Parameters

Expand Down Expand Up @@ -125,33 +126,33 @@ rotLeft :: [Bit] -> [Word n] -> [Word n]
rotLeft n xs = map Vec $ rotateLeft n $ map velems xs

update :: Word N4 -> Word N8 -> [Word n] -> Octostack n -> Recipe
update o en xs s = Seq ([s.offset <== o, s.writeEn <== en] ++ assigns)
where assigns = zipWith (<==) (s.dataIn.velems) xs
update o en xs s = do s.offset <== o
s.writeEn <== en
zipWithM_ (<==) (s.dataIn.velems) xs

-- Example usage

example :: Octostack N18 -> Recipe
example s =
Seq [ s.update 3 (high +> high +> high +> 0) [4, 5, 6]
, Tick -- PUSH [4, 5, 6]
, s.update 2 (high +> high +> 0) [8, 9]
, Tick -- PUSH [8, 9]
, s.update (-1) 0 []
, Tick -- POP 1
, s.update 4 (high +> high +> high +> high +> 0) [1, 2, 1, 2]
, Tick -- PUSH [1, 2, 1, 2]
, s.update 4 (high +> high +> high +> high +> 0) [6, 7, 6, 7]
, Tick -- PUSH [6, 7, 6, 7]
, s.update (-3) 0 []
, Tick -- POP 3
, s.update (-2) (high +> 0) [10]
, Tick -- POP 3, PUSH [10]
, s.update 2 (high +> high +> 0) [8, 9]
, Tick -- PUSH [8, 9]
, s.update 0 (high +> 0) [55]
, Tick -- PUSH [8, 9]
, Tick
, Tick
]
example s = do s.update 3 (high +> high +> high +> 0) [4, 5, 6]
tick -- PUSH [4, 5, 6]
s.update 2 (high +> high +> 0) [8, 9]
tick -- PUSH [8, 9]
s.update (-1) 0 []
tick -- POP 1
s.update 4 (high +> high +> high +> high +> 0) [1, 2, 1, 2]
tick -- PUSH [1, 2, 1, 2]
s.update 4 (high +> high +> high +> high +> 0) [6, 7, 6, 7]
tick -- PUSH [6, 7, 6, 7]
s.update (-3) 0 []
tick -- POP 3
s.update (-2) (high +> 0) [10]
tick -- POP 3, PUSH [10]
s.update 2 (high +> high +> 0) [8, 9]
tick -- PUSH [8, 9]
s.update 0 (high +> 0) [55]
tick -- PUSH [8, 9]
tick
tick


simExample = simRecipe (newOctostack "example_" id) example tops
Loading

0 comments on commit 0b33651

Please sign in to comment.