Practical 8 Pipelined Memory, Branches, Jumps

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 practical.

Following completion of this practical you should be able to:

Guidelines

Your Tasks

Follow this sequence of instructions to complete the practical. This practical will all be done in your practical-pipe repository

1 Add lw and sw to your processor

  1. Trace both lw and sw on the datapath diagram on the worksheet. You should also indicate the relevant control signals being passed through the pipe, in addition to highlighting data wires.
  2. Add any new traced wires to verilog datapath. You should probably use the "B" ports on the memory module to implement the MEM stage, rather than adding a second memory module.
  3. Add the newly required control signals (or connect them). Don't forget the mux in the WB stage!
  4. Look over the provided tests in test_pipe_mem_nohaz.asm, use this file to generate a .txt file to input into memory using your assembler.
  5. Fill in the testing plan for one of the provided test instructions on the worksheet. Write a second entry in the testing plan for a test of your own devising. (You do not need to add this test to the actual test file, just add it to the worksheet.)
  6. Run the provided memory tests by uncommenting the call to test_mem_type_nohaz() in tests tb_Pipe.v.

2 Add lui to your datapath

The rest of these entries follows the same pattern as lw/sw above, see that entry for details.

  1. Trace on dp diagram (add any new wires)
  2. Add any new traced or drawn wires to verilog datapath
    • specifically watch out for what goes back into the register file
  3. Add control (or connect it)
  4. Write tests (uncomment the call to test_lui_nohaz() and read through its implementation in tb_Pipe.v, assemble the provided test_pipe_lui_nohaz.asm file with your assembler, and use it).
    • Write an additional test (which may require you to create another .asm file and assemble it).
    • Add test descriptions to the Testing Plan for one existing test, and a test of your own design.

3 Add Branches

  1. Trace beq on the datapath
    • NOTE: the diagram provided and the tests in your repo have the branch logic in Memory stage. In class we optimized performance by putting the branch logic in the Instruction Decode stage. You may implement it either way, but if you choose to optimize like we did in class modify the datapath drawing to show the modification.
    • NOTE for the future: If you leave the branch decision in the Memory stage, during the next practical you will need to flush three invalid instructions from the pipeline. This is acceptable, but will be more work in the future when you do hazard detection.
    • If you choose to implement branch detection in Decode, you will need to modify the tests for branches.
  2. Implement beq
    • hint: need a mux as input to the PC
  3. Add control
  4. Run beq test we gave you
  5. implement bne, blt, and bge (hint: similar modifications to single-cycle)
  6. Run other branch tests we gave you. Add tests to the branches testing plan as described on the worksheet.

4 Add jal

  1. Trace the jal instruction on the datapath (in the worksheet), adding any hardware needed to make jal work.
  2. Implement DP + control
    • hint: datapath is a little like lui
    • hint: input to PC is same as branch
    • hint: linking is a bit hard, you might need to keep newPC in your pipeline stage register until WB.
  3. Test (run tests we gave you). Add a test to the jal/jalr testing plan as described on the worksheet.

5 Add jalr

  1. Trace the jalr instruction on the datapath (in the worksheet), adding any hardware needed to make jalr work.
  2. Implement DP + control
    • hint: addr calculation is just like lw/sw
    • need to add to the PC input mux (new source)
  3. Test (run tests we gave you). Add a test to the jal/jalr testing plan as described on the worksheet. Add a description of a test of your own design.

6 Write and run a bigger test

  1. On the worksheet create a test plan entry that will test all the RISC-V instructions work in the same program, rather than one at a time.
  1. On the worksheet, answer the question to explain why the tests in this practical have no dependencies.

Turn It In

Grading Rubric

General Requirements for all Practicals:

  1. The solution fits the need
  2. Aspects of performance are discussed
  3. The solution is tested for correctness
  4. The submission shows iteration and documentation

Fill out the Practical Worksheet

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

Practical 8 Rubric items Possible Points
Practical Worksheet 45
Memory insts 15
LUI 5
SB-Types 15
JAL 10
JALR 10
Total out of 100
  1. Submit your completed Practical Worksheet to gradescope.

  2. Practical code will be submitted to your practical- pipe git repository as either new files or committed modifications to the repo. You must include your name and your teammates' names in a comment at the top of all files you submit.