diff options
| author | azidar | 2015-02-20 16:56:25 -0800 |
|---|---|---|
| committer | azidar | 2015-02-20 16:56:25 -0800 |
| commit | 95dd261b4e65840ade351dcb00e4164a99daf654 (patch) | |
| tree | 73f5fa894f5ebb3a61581dd2f29ae96e46d476e4 /notes/initialize-register-explanation.txt | |
| parent | 8299c2ecae1701fa6060185a8aed25543e201eba (diff) | |
Rewrote the initialize-register pass, now correctly implemented
with a new IR construct - Null. LetRec is not implemented, but is
marked with a TODO.
Test cases for this pass are now located in
test/passes/initialize-register
Diffstat (limited to 'notes/initialize-register-explanation.txt')
| -rw-r--r-- | notes/initialize-register-explanation.txt | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/notes/initialize-register-explanation.txt b/notes/initialize-register-explanation.txt new file mode 100644 index 00000000..27bbde52 --- /dev/null +++ b/notes/initialize-register-explanation.txt @@ -0,0 +1,81 @@ +reg r: UInt(16) + +=> + +reg r: UInt(16) +wire r_init : UInt(16) +r_init := NULL + +when reset : + r := r_init + +=============== + +reg r: UInt(16) +r.init := UInt(0) + +=> + +reg r: UInt(16) +wire r_init : UInt(16) +r_init := NULL +r_init := UInt(0) +when reset : + r := r_init + +=> + +reg r: UInt(16) +wire r_init2 : UInt(16) +r_init2 := NULL +wire r_init : UInt(16) +r_init := NULL +r_init := UInt(0) +when reset : + r := r_init +when reset : + r := r_init2 + + +====== + +We continue to simplify from the previous example. Here's the input we had (but with the incorrect lines removed). + +reg r: UInt(16) +wire r_init2 : UInt(16) +r_init2 := NULL +wire r_init : UInt(16) +r_init := NULL +r_init := UInt(0) +when reset : + r := r_init +when reset : + r := r_init2 + +One of the following passes will turn wires into nodes, by scanning to see what they are connected to. + +reg r: UInt(16) +node r_init2 = NULL +node r_init = UInt(0) +when reset : + r := r_init +when reset : + r := r_init2 + +Another pass will compute the final value connected to the register, expressed as a bunch of muxes. The default value for a register is set to itself. + +node r_init2 = NULL +node r_init = UInt(0) +reg r:UInt(16) = Mux(reset, r_init2, Mux(reset, r_init, r)) + +Next we inline all the nodes with NULL in them, to arrive at the final expression for the register. + +reg r:UInt(16) = Mux(reset, NULL, Mux(reset, r_init, r)) + +NULL's do nothing, so any expression of the form Mux(a, NULL, b) can be simplified to b. Arriving finally at: + +reg r:UInt(16) = Mux(reset, r_init, r) + +which is what we wanted. + + |
