Adds extension M instructions: not tested
This commit is contained in:
@@ -3,11 +3,15 @@ package projet
|
||||
import chisel3._
|
||||
import chisel3.util.switch
|
||||
import chisel3.util.is
|
||||
import chisel3.util.Cat
|
||||
import chisel3.util.Fill
|
||||
|
||||
object AluOpCode extends ChiselEnum {
|
||||
val Add, AddW, Sub, And, Or, Xor, ShiftLeft, ShiftRight,
|
||||
val Add, AddW, Sub, Mul, Mulh, Mulhsu, Mulhu, Div, Divu, Rem, Remu, Mulw,
|
||||
Divw, Divuw, Remw, Remuw, And, Or, Xor, ShiftLeft, ShiftRight,
|
||||
ShiftArithmeticRight, LessThanSigned, LessThanUnsigned,
|
||||
GreaterEqualSigned, GreaterEqualUnsigned, Equal = Value
|
||||
GreaterEqualSigned, GreaterEqualUnsigned, Equal =
|
||||
Value
|
||||
}
|
||||
|
||||
class Alu extends Module {
|
||||
@@ -32,6 +36,63 @@ class Alu extends Module {
|
||||
io.out := io.a - io.b;
|
||||
}
|
||||
|
||||
is(Mul) {
|
||||
io.out := (io.a.asSInt * io.b.asSInt).asUInt;
|
||||
}
|
||||
|
||||
is(Mulh) {
|
||||
io.out := ((io.a.asSInt * io.b.asSInt) >> 64.U).asUInt;
|
||||
}
|
||||
|
||||
is(Mulhsu) {
|
||||
io.out := ((io.a.asSInt * io.b).asSInt >> 64.U).asUInt;
|
||||
}
|
||||
|
||||
is(Mulhu) {
|
||||
io.out := (io.a * io.b) >> 64.U;
|
||||
}
|
||||
|
||||
is(Div) {
|
||||
io.out := (io.a.asSInt / io.b.asSInt).asUInt;
|
||||
}
|
||||
|
||||
is(Divu) {
|
||||
io.out := io.a / io.b;
|
||||
}
|
||||
|
||||
is(Rem) {
|
||||
io.out := (io.a.asSInt % io.b.asSInt).asUInt;
|
||||
}
|
||||
|
||||
is(Remu) {
|
||||
io.out := io.a % io.b;
|
||||
}
|
||||
|
||||
is(Mulw) {
|
||||
val res = (io.a.asSInt * io.b.asSInt).asUInt
|
||||
io.out := Cat(Fill(32, res(31)), res(31, 0))
|
||||
}
|
||||
|
||||
is(Divw) {
|
||||
val res = (io.a(31, 0).asSInt / io.b(31, 0).asSInt).asUInt;
|
||||
io.out := Cat(Fill(32, res(31)), res(31, 0));
|
||||
}
|
||||
|
||||
is(Divuw) {
|
||||
val res = io.a(31, 0) / io.b(31, 0);
|
||||
io.out := Cat(Fill(32, res(31)), res(31, 0));
|
||||
}
|
||||
|
||||
is(Remw) {
|
||||
val res = (io.a(31, 0).asSInt % io.b(31, 0).asSInt).asUInt;
|
||||
io.out := Cat(Fill(32, res(31)), res(31, 0));
|
||||
}
|
||||
|
||||
is(Remuw) {
|
||||
val res = io.a(31, 0) % io.b(31, 0);
|
||||
io.out := Cat(Fill(32, res(31)), res(31, 0));
|
||||
}
|
||||
|
||||
is(And) {
|
||||
io.out := io.a & io.b;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user