A register file hands a value that is being written straight to a read of the same cycle. One program gets a wrong value from it. Find the case and repair it.
Hardware context: The lab pipeline with forwarding multiplexers in front of the ALU and on the store data, and a bench that plays the forwarding unit; the forwarding can be switched off. Reading forwarding in a pipeline trace and reviewing the forwarding paths of a core
This register file is made for a pipeline. When a register is read in the cycle in which it is written, the read gets the new value. The lesson calls that the bypass of the register file.
The team ran many programs on it and all were right. Then one program, which uses x0 as the place to throw a result away, read a wrong value. Repair the register file. Change as little as you can.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
trial | 10 | input of each check |
Full specification
| Case | Value |
|---|---|
| The register is x0 | 0, always |
| The register is being written in this cycle | the value on rd_data |
| Any other case | the stored value. After a reset, every register holds 0 |
| Case | Effect at the clock edge |
|---|---|
| write_enable is 1 and rd_addr is not 0 | the register takes rd_data |
| write_enable is 1 and rd_addr is 0 | nothing: x0 has no storage |
| write_enable is 0 | nothing, whatever rd_addr and rd_data are |
How to read a result: a public case shows the two values read in its last cycle. A private case runs many cycles and checks both reads in every one, and all_match is 1 when all were right.
Examples
Example 1
A Read Meets a Write- Input
x5 is written with 7. In the same cycle, x5 and x6 are read
- Output
rs1_data = 0x7, rs2_data = 0x0
The first read meets the write: it gets the 7 that is on its way into x5. x6 was never written and reads 0.
Example 2
A Write to x0- Input
x5 is written with 7. Then x0 is written with 14, and x0 and x5 are read in that cycle
- Output
rs1_data = 0x0, rs2_data = 0x7
The write to x0 is thrown away, and x0 reads 0 whatever is on the write port. x5 holds its 7.
Example 3
A Write Port That Is Off- Input
x9 is written with 1234. In the next cycle write_enable is 0, rd_addr is 9, and x9 is read twice
- Output
rs1_data = 0x1234, rs2_data = 0x1234
Nothing is written in the second cycle. Both reads give the stored value. The value on the write port means nothing while write_enable is 0.
Constraints and Contract
- The reset is asynchronous and active low. A read has no clock: it follows its address, and the write port, at once.
- A read that meets a write must still get the new value in that same cycle. Removing that path is not a repair.
- The bench reads both ports before each clock edge, 1 ns after it has set the inputs.
Hints
Hint 1
Run the starter and look at the three public cases. One of them fails, and it tells you which register is involved.
Hint 2
Follow that case through the last four assign lines by hand. Which line gives the wrong value?
Hint 3
Compare that line with the line that stores a value. One of the two knows something that the other does not.
What the grader checks: Every register read while it is written and after it was written, on both ports. Writes to x0, read at once and later. Reads of x0 while another register is written. Equal numbers with write_enable at 0. A value of 0 written over another value. The register numbers 15, 16, 17 and 31. Two mixed runs.
12 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path