Skip to content

Commit b097d7d

Browse files
committed
sys:risc-v added mia with mul stage with latency 3
1 parent 6e7de6b commit b097d7d

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

sys/risc-v/rv64imFive.vadl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import rv64im::{RV64IM}
77

8-
micro architecture FiveStage implements RV32IM = {
8+
micro architecture FiveStage implements RV64IM = {
99

1010
stage FETCH -> ( fr : FetchResult ) = {
1111
fr := fetchNext // fetch next packet from memory (or cache)
1212
}
1313

1414
stage DECODE -> ( ir : Instruction ) = {
1515
let instr = decode( FETCH. fr ) in { // decode the fetch packet, gives an Instruction
16-
if ( instr .unknown ) then
16+
if ( instr.unknown ) then
1717
raise invalidInstruction // raise an invalid instruction exception
1818
instr.address( @X ) // output computed address (X + offset ) to memory
1919
instr.read( @X ) // read from the X register file
@@ -23,7 +23,7 @@ micro architecture FiveStage implements RV32IM = {
2323
}
2424

2525
stage EXECUTE -> ( ir : Instruction ) = {
26-
let instr =DECODE.ir in {
26+
let instr = DECODE.ir in {
2727
instr.compute // evaluate all expressions
2828
instr.verify // check and flush pipeline if branch misprediction
2929
instr.write( @PC ) // write PC
@@ -32,15 +32,15 @@ micro architecture FiveStage implements RV32IM = {
3232
}
3333

3434
stage MEMORY -> ( ir : Instruction ) = {
35-
let instr = EXECUTE. ir in {
35+
let instr = EXECUTE.ir in {
3636
instr.write( @MEM ) // write to memory
37-
instr .read( @MEM ) // receive data from memory read
37+
instr.read( @MEM ) // receive data from memory read
3838
ir := instr
3939
}
4040
}
4141

4242
stage WRITE_BACK = {
4343
let instr = MEMORY.ir in
44-
instr.write( @X ) // write back to register file X
44+
instr.write( @X ) // write back to register file X
4545
}
4646
}

sys/risc-v/rv64imFiveMul.vadl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)