S2.4.1 Add the Store Path

MediumImplement35 minIcarus Verilog · serverReview the topic

The datapath of the lab stores whole words only. Write the store path of a real core: bytes and halves on their byte lanes, and a check of the address.

Hardware context: The datapath of ap_rv32_sc for an arithmetic instruction: a PC, the real register file and the real ALU of ap_rv32, an operand select and a write back, with given control signals. Reading the datapath of any processor core

The lab of the lesson sends rs2_data straight to the data memory. That is right for sw and for nothing else. An sb must change one byte of a word, and an sh two.

Write the block between the ALU and the data memory that does this. It has no clock. The decoder gives it mem_write and mem_size.

Signals in the Timeline

SignalWidthRole
trial10input of each check
Full specification
Where the bytes go
Every lane that the store does not write carries 0. The value 3 of mem_size never occurs.
mem_sizeInstructionBytes taken from rs2_dataTheir place on dmem_wdata
0sbthe low byte, bits 7 to 0the lane that address bits 1 and 0 name. Lane 0 is bits 7 to 0, lane 3 is bits 31 to 24
1shthe low half, bits 15 to 0bits 15 to 0 when address bit 1 is 0, bits 31 to 16 when it is 1
2swall four bytesall four lanes
When a store is misaligned
A misaligned store must not reach the memory. The core takes a trap for it: S2.13.
StoreMisaligned when
sbnever
shthe address is odd
swthe address is not a multiple of 4

How to read a result: a public case shows the two flags, and the data when the store happens. A private case tries many inputs of one kind, and all_match is 1 when every output was right.

Examples

Example 1

A Word
Input
sw of 1234_5678 to address 8000_0008
Output
dmem_req = 1, misaligned = 0, dmem_wdata = 0x12345678

A word fills all four lanes. The address is a multiple of 4, so the store happens.

Example 2

A Byte on Lane 2
Input
sb of 1234_5678 to address 8000_0006
Output
dmem_req = 1, misaligned = 0, dmem_wdata = 0x780000

A byte store takes the low byte, 78. The two low address bits are 10 in binary: lane 2, bits 23 to 16.

Example 3

A Half at an Odd Address
Input
sh of 1234_5678 to address 8000_0005
Output
dmem_req = 0, misaligned = 1, dmem_wdata = 0x0

A half needs an even address. This one is odd: misaligned is 1 and no store happens.

Constraints and Contract

  • The outputs depend only on the inputs of the same moment. The bench waits 1 ns after it sets them.
  • dmem_req is 1 exactly when mem_write is 1 and the store is not misaligned. misaligned is 0 when mem_write is 0.
  • dmem_addr is the address as the ALU gives it, with all 32 bits. The memory finds the word by itself.
  • dmem_wdata is checked only when dmem_req is 1.

Hints

Hint 1

Give each of the three sizes one branch of a case statement.

Hint 2

For a byte, first make a word that holds only that byte. Then move it by 8 bits for each lane.

Hint 3

Write the two flags last. One of them needs the other.

What the grader checks: Bytes on all four lanes at five base addresses, among them the last word of the address space. Halves at even and at odd addresses, words at every low address. Ten data patterns that tell lanes apart. Instructions that are not stores, and 80 random cases.

11 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 3 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 Word

Input
sw of 1234_5678 to address 8000_0008
Expected output
dmem_req = 1, misaligned = 0, dmem_wdata = 0x12345678

A word fills all four lanes. The address is a multiple of 4, so the store happens.

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

Icarus Verilog · server