S2.8.2 The Forward to x0

MediumDebug25 minIcarus Verilog · serverReview the topic

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

SignalWidthRole
trial10input of each check
Full specification
What a read must give
The first row comes first. The two read ports behave alike.
CaseValue
The register is x00, always
The register is being written in this cyclethe value on rd_data
Any other casethe stored value. After a reset, every register holds 0
What a write does
CaseEffect at the clock edge
write_enable is 1 and rd_addr is not 0the register takes rd_data
write_enable is 1 and rd_addr is 0nothing: x0 has no storage
write_enable is 0nothing, 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

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

A Read Meets a Write

Input
x5 is written with 7. In the same cycle, x5 and x6 are read
Expected 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.

Run samples executes all 3 public checks. Check all tests runs 12 checks on the server.

Icarus Verilog · server