Lab 9 Pipelined hazard resolution

Objectives

This section is not a list of tasks for you to do. It is a list of skills you will have or things you will know after you complete the lab.

Following completion of this lab you should be able to:

Guidelines

Your Tasks

Follow this sequence of instructions to complete the lab. This lab will all be done in your D-group repository

1 Run the hazards tests

TODO: some lab worksheet stuff exploring the hazard test bench.

2 Write then read

  1. Examine the x2 hazards .asm file
  2. Examine the tb_Processor_hazards.v test bench
  3. Run it, and make a waveform
  4. Uncomment the write-then-read test in the
  5. Figure out how to make your reg file write before it reads
    • hint: two clocks? Kind of.

3 Data forwarding

  1. Create forwarding unit
    • specs?
  2. Handle WB -> EX forwarding
    • uncomment our test for this
  3. Handle MEM -> EX forwarding
    • uncomment our test for this

4 lw stall

  1. Examine test asm file test_datahaz_lw.asm

  2. Construct a hazard unit module

  3. Handle stall when lw is in EX and the next instruction will use its rd value (see page 322 in the textbook)

    • hint: disable writing to the IF_ID register and PC when stalling.
    • hint: need to insert bubble in ID_EX (hint: add a flush capability to the stage register that puts all zeroes into its control bits and any instruction data you're carrying)
    • hint: special case for UJ and U types that follow a lw: they don't use register sources!
  4. Run our tests (test_lw_stall())

  5. Something about SW tests too

  6. TODO: On the worksheet, answer the question about forwarding from lw to sw

5 Flushing the pipe

  1. TODO: On the worksheet, draw a pipeline diagram for the instructions given.
  2. Examine test asm file test_ctlhaz_beq.asm
    • NOTE: branch writes the PC in the memory cycle (see textbook)
    • this means everything following it must be erased.
  3. Figure out how to insert bubbles as instructions leave the EX, ID, and IF cycles
    • hint: use the same trick used to insert a stall to flush EX_MEM, ID_EX, and IF_ID stage registers while the PC is being written to the branch target by the instruction in MEM.
  4. Run our tests (test_beq_flush())
  5. Write new tests for jal and jalr and run them.

6 Write and run a bigger test

TODO: tell them to write a test with jumps, returns, arguments. Give them C code or something.

// m and n are variables in memory.  Be sure to update them when they change.
// Array A is at x5
int[] A = {1, 2, 3, 4, 5};
int idx = 0;
while(idx < 5) {
    A[idx] = A[idx] + 1;
    idx = idx + 1;
}

Then, have them run their relprime from previous homework or something.

TODO: Give them an empty tb_Processor_Program.v file to run an arbitrary program.

7 Design a new instruction

TODO: tell them to design an instruction that will be hard to add to the pipeline

  1. Document the design (in the lab worksheet +10 pts) and explain how you plan to add it to the pipeline
    • maybe add a stage to support extra work
    • or stall the pipeline
    • or add more hardware to existing stages
  2. implement the design
  3. Run relprime with your new instruction (you'll have to rewrite relprime)
  4. Compare the two runtimes (number of cycles for each run)
  5. Optional: implement it another way too (git branch?)

8 Bonus - add MMIO

TODO: Give them a diagram for MMIO, have them add to pipeline

Turn It In

Grading Rubric

General Requirements for all Labs:

  1. fits the need
  2. discuss performance
  3. tests for correctness
  4. iteration and documentation

Fill out the Lab Worksheet

In the worksheet, explain how you satisfy each of these items. Some guidelines:

Lab 9 Rubric items Possible Points
Lab Worksheet 30
Write-Then-Read RegFile 5
Forwarding unit 15
lw stall (Hazard Unit) 15
branch/jump flushing 15
New tests 10
New Instruction (impl) 5
Extra points 5
Total out of 100

For extra points, you could:

  1. Submit your completed Lab Worksheet to gradescope.

  2. Lab code will be submitted to your D git repository as new files and committed modifications to the repo we provided you. You must include your name and your teammates' names in a comment at the top of all files you submit.