Skip to content

Commit a83cfd4

Browse files
committed
feat: add imm gen module impl
1 parent dbfbff1 commit a83cfd4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package treecorel3
2+
3+
import chisel._
4+
import chiesl.uitl._
5+
6+
class ImmGenIO(implicit p: Parameters) extends Bundle {
7+
val inst = Input(UInt(xlen.W))
8+
val sel = Input(UInt(3.W))
9+
val out = Output(UInt(xlen.W))
10+
}
11+
12+
class ImmGen(implicit p: Parameters) extends Module {
13+
val io = IO(new ImmGenIO)
14+
val Iimm = io.inst(31, 20).asSInt
15+
val Simm = Cat(io.inst(31, 25), io.inst(11, 7)).asSInt
16+
val Bimm = Cat(io.inst(31), io.inst(7), io.inst(30, 25), io.inst(11, 8), 0.U(1.W)).asSInt
17+
val Uimm = Cat(io.inst(31, 12), 0.U(12.W)).asSInt
18+
val Jimm = Cat(io.inst(31), io.inst(19, 12), io.inst(20), io.inst(30, 25), io.inst(24, 21), 0.U(1.W)).asSInt
19+
val Zimm = io.inst(19, 15).zext
20+
21+
io.out := MuxLookup(
22+
io.sel,
23+
Iimm & -2.S,
24+
Seq(
25+
IMM_I -> Iimm,
26+
IMM_S -> Simm,
27+
IMM_B -> Bimm,
28+
IMM_U -> Uimm,
29+
IMM_J -> Jimm,
30+
IMM_Z -> Zimm
31+
)
32+
).asUInt
33+
}

0 commit comments

Comments
 (0)