Merge branch 'main' of gitlab.ensimag.fr:thillarj/FMN_2526S1_thillarj_chaboisa

This commit is contained in:
2025-11-09 19:47:51 +01:00
3 changed files with 42 additions and 4 deletions

22
bench/tests/op/sub.s Normal file
View File

@@ -0,0 +1,22 @@
# expected: 00000000, 00000001, FFFFFFFF, 00000008
.text
_start:
# Sub equal numbers
addi x1, x0, (-1)
addi x2, x0, (-1)
sub x31, x1, x2
# Positive result sub
addi x1, x0, 13
addi x2, x0, 12
sub x31, x1, x2
# Negative result sub
addi x1, x0, 12
addi x2, x0, 13
sub x31, x1, x2
# Negative result sub
addi x1, x0, 4
addi x2, x0, (-4)
sub x31, x1, x2

View File

@@ -5,7 +5,7 @@ import chisel3.util.switch
import chisel3.util.is import chisel3.util.is
object AluOpCode extends ChiselEnum { object AluOpCode extends ChiselEnum {
val Add, And, Or, Xor, ShiftLeft, ShiftRight, ShiftArithmeticRight, val Add, Sub, And, Or, Xor, ShiftLeft, ShiftRight, ShiftArithmeticRight,
LessThanSigned, LessThanUnsigned, GreaterEqualSigned, LessThanSigned, LessThanUnsigned, GreaterEqualSigned,
GreaterEqualUnsigned, Equal = Value GreaterEqualUnsigned, Equal = Value
} }
@@ -28,6 +28,10 @@ class Alu extends Module {
io.out := io.a + io.b; io.out := io.a + io.b;
} }
is(Sub) {
io.out := io.a - io.b;
}
is(And) { is(And) {
io.out := io.a & io.b; io.out := io.a & io.b;
} }

View File

@@ -282,7 +282,7 @@ class ControlUnit() extends Module {
// Meaning of Funct3 in the context of an OpR instruction // Meaning of Funct3 in the context of an OpR instruction
object Funct3 extends ChiselEnum { object Funct3 extends ChiselEnum {
// Type I // Type I
val ADD = "b000".U val ADD_SUB = "b000".U
val AND = "b111".U val AND = "b111".U
val OR = "b110".U val OR = "b110".U
val XOR = "b100".U val XOR = "b100".U
@@ -300,13 +300,25 @@ class ControlUnit() extends Module {
val SRA = "b0100000".U val SRA = "b0100000".U
} }
object ADDFunct7 extends ChiselEnum {
val ADD = "b0000000".U
val SUB = "b0100000".U
}
io.mux_regb_imm := true.B; // OpImm are operations with imm, so send imm to ALU io.mux_regb_imm := true.B; // OpImm are operations with imm, so send imm to ALU
io.mux_rega_pc := true.B; io.mux_rega_pc := true.B;
io.mux_alu_imm := true.B; io.mux_alu_imm := true.B;
switch(funct3) { switch(funct3) {
// Type I // Type I
is(Funct3.ADD) { is(Funct3.ADD_SUB) {
io.alu_opcode := AluOpCode.Add switch(funct7) {
is(ADDFunct7.ADD) {
io.alu_opcode := AluOpCode.Add
}
is(ADDFunct7.SUB) {
io.alu_opcode := AluOpCode.Sub
}
}
} }
is(Funct3.AND) { is(Funct3.AND) {