`[<<][rtl][>>][..]`
Sat Jul 21 08:53:49 EDT 2018

## The mapped if'

```I'm a little worried about that one.  How hard is it to bundle these
into imperative statements?

Recursively:
- find all if nodes that have the same condition
- group together the equations

What happens when there are ANF terms inbetween the conditionals?

It makes sense to write this as a test.

EDIT: Here's an example.

-- sequenced if' : does it need to be bundled?
x_ifs = do
putStrLn "--- x_ifs"
print_hdl \$ do
io@[c,i1,i2,o1,o2] <- SeqTerm.io \$ replicate 5 bit
os' <- ifs c [i1,i2] [0,0]
sequence \$ zipWith connect [o1,o2] os'
return io

--- x_ifs
-- ports:
[Node (SInt (Just 1) 0) 0,
Node (SInt (Just 1) 0) 1,
Node (SInt (Just 1) 0) 2,
Node (SInt (Just 1) 0) 3,
Node (SInt (Just 1) 0) 4]
-- bindings:
(0,Input (SInt (Just 1) 0))
(1,Input (SInt (Just 1) 0))
(2,Input (SInt (Just 1) 0))
(5,Comb3 (SInt (Just 1) 0) IF (Node (SInt (Just 1) 0) 0) (Node (SInt (Just 1) 0) 1) (Const (SInt Nothing 0)))
(6,Comb3 (SInt (Just 1) 0) IF (Node (SInt (Just 1) 0) 0) (Node (SInt (Just 1) 0) 2) (Const (SInt Nothing 0)))
(3,Connect (SInt (Just 1) 0) (Node (SInt (Just 1) 0) 5))
(4,Connect (SInt (Just 1) 0) (Node (SInt (Just 1) 0) 6))
0 <- (INPUT)
1 <- (INPUT)
2 <- (INPUT)
3 <- (CONNECT (IF (NODE 0) (NODE 1) (CONST SInt Nothing 0)))
4 <- (CONNECT (IF (NODE 0) (NODE 2) (CONST SInt Nothing 0)))
-- MyHDL:
from myhdl import *
def module(CLK, RST, s0, s1, s2, s3, s4):
# s0 is an input
# s1 is an input
# s2 is an input
@always_comb
def blk1():
s3.next = ((s1 if s0 else 0))
@always_comb
def blk2():
s4.next = ((s2 if s0 else 0))
return [blk1, blk2]

Looking at

cond ((mcond, whenTrue):clauses) dflt = do
c <- mcond
t <- whenTrue
f <- cond clauses dflt
ifs c t f

It appears that conditions will always be completely evaluated, so
they appear successive if nodes.

It doesn't seem too hard to make this work.

So this is an operation on bindings.

Maybe best to do it in a couple of steps
- translate current expression if to a statement if else
- chain else if to elif
- bundle

Note that seq can also be bundled.

What are the core operations?
- Conditionally bundle static assignments:
- Seq
- If (unless it is chained)

One thing that is implicit, is whether a set of equations is
independent.

When are equations independent?

- Sequential
- Combinatorial, but no (mutual) recursive references

Those can be bundled.

Before doing any of this, it is necessary to test if it is really
needed.  I'm assuming the synthesizer already does a lot of
rearranging.  Figure out how yosys works.

Another reason to do this is to make the output code more readable.

```
`[Reply][About]`
`[<<][rtl][>>][..]`