|
| 1 | +// SPDX-FileCopyrightText : © 2024 TU Wien <vadl@tuwien.ac.at> |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +// RISC-V 64 five stage pipeline with longer mul/div pipeline |
| 5 | + |
| 6 | +import rv64im::{RV64IM} |
| 7 | + |
| 8 | +micro architecture FiveStage implements RV64IM = { |
| 9 | + |
| 10 | + operation AddOps = {ADD, SUB, AND, OR, XOR, SLT, SLTU, SLL, SRL, SRA} |
| 11 | + operation ImmOps = {ADDI, ANDI, ORI, XORI, SLTI, SLTIU, AUIPC, LUI} |
| 12 | + operation MemOps = {LB, LBU, LH, LHU, LW, SB, SH, SW} |
| 13 | + operation BraOps = {BEQ, BNE, BGE, BGEU, BLT, BLTZ, JAL, JALR} |
| 14 | + operation MulOps = {MUL, MULH, MULHSU, MULHU, MULW} |
| 15 | + operation DivOps = {DIV, DIVU, REM, REMU, DIVW, DIVUW, REMW, REMUW} |
| 16 | + operation AluOps = {AddOps, ImmOps, MemOps, BraOps} |
| 17 | + operation MulDivOps = {MulOps, DivOps} |
| 18 | + |
| 19 | + stage FETCH -> ( fr : FetchResult ) = { |
| 20 | + fr := fetchNext // fetch next packet from memory (or cache) |
| 21 | + } |
| 22 | + |
| 23 | + stage DECODE -> ( ir : Instruction, mulir : Instruction ) = { |
| 24 | + let instr = decode( FETCH. fr ) in { // decode the fetch packet, gives an Instruction |
| 25 | + if ( instr.unknown ) then |
| 26 | + raise invalidInstruction // raise an invalid instruction exception |
| 27 | + instr.address( @X ) // output computed address (X + offset ) to memory |
| 28 | + instr.read( @X ) // read from the X register file |
| 29 | + instr.read( @PC ) // read from the PC |
| 30 | + ir := filter(instr, @AluOps) // ir are common instructions |
| 31 | + mulir := filter(instr, @MulDivOps) // mulir are multiplication / division instructions |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + stage EXECUTE -> ( ir : Instruction ) = { |
| 36 | + let instr = DECODE.ir in { |
| 37 | + instr.compute // evaluate all expressions |
| 38 | + instr.verify // check and flush pipeline if branch misprediction |
| 39 | + instr.write( @PC ) // write PC |
| 40 | + ir := instr |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + [restart : 1] |
| 45 | + [latency : 3] |
| 46 | + stage MUL -> ( ir : Instruction ) = { |
| 47 | + let instr = DECODE.mulir in { |
| 48 | + instr.compute // evaluate mul expressions |
| 49 | + ir := instr |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + stage MEMORY -> ( ir : Instruction ) = { |
| 54 | + let instr = EXECUTE.ir in { |
| 55 | + instr.write( @MEM ) // write to memory |
| 56 | + instr.read( @MEM ) // receive data from memory read |
| 57 | + ir := instr |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + stage WRITE_BACK = { |
| 62 | + let instr = MEMORY.ir | MUL.ir in // combine memory and mul pipeline |
| 63 | + instr.write( @X ) // write back to register file X |
| 64 | + } |
| 65 | +} |
0 commit comments