58 lines
1.3 KiB
Scala
58 lines
1.3 KiB
Scala
package projet
|
|
|
|
import chisel3._
|
|
import chisel3.util.switch
|
|
import chisel3.util.is
|
|
import chisel3.util.Cat
|
|
import chisel3.util.Fill
|
|
|
|
class ImmediateDecoder extends Module {
|
|
import projet.OpType
|
|
|
|
val io = IO(new Bundle {
|
|
val op_type = Input(OpType())
|
|
val instruction = Input(UInt(32.W))
|
|
val immediate = Output(UInt(32.W))
|
|
})
|
|
io.immediate := 0.U
|
|
|
|
// Decode and construct immediates
|
|
val imm_u = Cat(io.instruction(31, 12), 0.U(12.W));
|
|
val imm_i = Cat(Fill(20, io.instruction(31)), io.instruction(31, 20));
|
|
val imm_ir = io.instruction(24, 20);
|
|
val imm_j = Cat(
|
|
Fill(11, io.instruction(31)),
|
|
io.instruction(31),
|
|
io.instruction(19, 12),
|
|
io.instruction(20),
|
|
io.instruction(30, 21),
|
|
0.U
|
|
);
|
|
val imm_b = Cat(
|
|
Fill(19, io.instruction(31)),
|
|
io.instruction(31),
|
|
io.instruction(7),
|
|
io.instruction(30, 25),
|
|
io.instruction(11, 8),
|
|
0.U
|
|
)
|
|
|
|
switch(io.op_type) {
|
|
is(OpType.U) {
|
|
io.immediate := imm_u
|
|
}
|
|
is(OpType.I) {
|
|
io.immediate := imm_i
|
|
}
|
|
is(OpType.IR) {
|
|
io.immediate := imm_ir
|
|
}
|
|
is(OpType.J) {
|
|
io.immediate := imm_j
|
|
}
|
|
is(OpType.B) {
|
|
io.immediate := imm_b
|
|
}
|
|
}
|
|
}
|