Skip to content

Commit 4b9c41e

Browse files
committed
Branch logic explained
1 parent 66eaa5f commit 4b9c41e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ The VIPS support a subset of the MIPS32 ISA. We can capture the control logic fo
153153

154154
## Simple Vips
155155

156-
Adding control logic for branches.
156+
Adding control logic for branches. The decoder/control unit implements the following logic.
157+
158+
Notice (*), for `beq` the `pc_sel` is `eq ? 10 : 00`, `bne` the `pc_sel` is `eq ? 00 : 10`, respectively.
159+
The *z* signal is not used.
157160

158161
| Operation | `rf_we` | `w_reg_sel` | `sub` | `op` | `alu_b_sel` | `sign_ext` | `pc_sel` |
159162
| --------- | :-----: | :---------: | :---: | :---: | :---------: | :--------: | :------: |
@@ -167,13 +170,14 @@ Adding control logic for branches.
167170
| addi | 1 | 0 | 0 | 10 | 1 | 1 | 00 |
168171
| slti | 1 | 0 | 1 | 11 | 1 | 1 | 00 |
169172
| jr | 0 | 0 | 0 | 10 | 0 | x | 01 |
170-
| beq | 0 | 0 | x | xx | x | 1 | 10 |
171-
| bne | 0 | 0 | x | xx | x | 1 | 10 |
173+
| beq | 0 | 0 | x | xx | x | 1 | (*) |
174+
| bne | 0 | 0 | x | xx | x | 1 | (*) |
172175
| j | 0 | 0 | x | xx | x | 1 | 11 |
173176

174177
The branch target for the relative branches (`beq` and `bne`) is computed by a seprate adder (not by the Alu). This decision allows the Alu to compute return address for function calls in the real MIPS.
175178

176-
Notice, for generating the `pc_sel` signal we need to take into accunt the `eq` input (`a_data` == `b_data`).
179+
Notice, for generating the `pc_sel` signal we need to take into accunt the *eq* input (`a_data` == `b_data`).
180+
177181
The `jr` instruction assumes the `rt` field to be `zero` and adds that (0) to the `rs` field. The real MIPS has a special ALU opcode for just passing the `rs` field, so here we break a bit with the MIPS specification.
178182

179183
The corresponding implementation is found in `src/decoder1.veryl`. A test program is found in `src/instr_mem1.veryl` allong with the top level `src/vips1.veryl`. See List of current tests, for running the model.
@@ -182,7 +186,10 @@ The corresponding implementation is found in `src/decoder1.veryl`. A test progra
182186

183187
## Full Vips
184188

185-
The Full Vips adds support for word sized access to data memory.
189+
The Full Vips adds support for word sized access to data memory. The decoder/control unit implements the following logic.
190+
191+
Notice (*), for `beq` the `pc_sel` is `eq ? 10 : 00`, `bne` the `pc_sel` is `eq ? 00 : 10`, respectively.
192+
The *z* signal is not used.
186193

187194
| Operation | `rf_we` | `w_reg_sel` | `sub` | `op` | `alu_b_sel` | `sign_ext` | `pc_sel` | `d_sel` |
188195
| --------- | :-----: | :---------: | :---: | :---: | :---------: | :--------: | :------: | :-----: |
@@ -196,12 +203,13 @@ The Full Vips adds support for word sized access to data memory.
196203
| addi | 1 | 0 | 0 | 10 | 1 | 1 | 00 | 0 |
197204
| slti | 1 | 0 | 1 | 11 | 1 | 1 | 00 | 0 |
198205
| jr | 0 | 0 | 0 | 10 | 0 | x | 01 | x |
199-
| beq | 0 | 0 | x | xx | x | 1 | 10 | x |
200-
| bne | 0 | 0 | x | xx | x | 1 | 10 | x |
206+
| beq | 0 | 0 | x | xx | x | 1 | (*) | x |
207+
| bne | 0 | 0 | x | xx | x | 1 | (*) | x |
201208
| j | 0 | 0 | x | xx | x | x | 11 | x |
202209
| lw | 1 | 0 | 0 | 10 | 1 | 1 | 00 | 1 |
203210
| sw | 0 | 0 | 0 | 10 | 1 | 1 | 00 | x |
204211

212+
205213
The load and store instructions computes the effective address using the Alu (`rs` + sig_ext(`imm`)). The data to store comes from the `rt` field (`b_data`).
206214

207215
The corresponding implementation is found in `src/decoder.veryl`. A test program is found in `src/instr_mem.veryl` allong with the top level `src/vips1.veryl`. See List of current tests, for running the model.

0 commit comments

Comments
 (0)