@@ -7,54 +7,53 @@ import treecorel2.common.InstConfig
77
88class LSU extends Module with InstConfig {
99 val io = IO (new Bundle {
10- val valid = Input (Bool ())
11- val isa = Input (UInt (InstValLen .W ))
12- val src1 = Input (UInt (XLen .W ))
13- val src2 = Input (UInt (XLen .W ))
14- val imm = Input (UInt (XLen .W ))
15- val ld = new LDIO
16- val sd = new SDIO
17- val loadData = Output (UInt (XLen .W ))
10+ val valid = Input (Bool ())
11+ val isa = Input (UInt (InstValLen .W ))
12+ val src1 = Input (UInt (XLen .W ))
13+ val src2 = Input (UInt (XLen .W ))
14+ val imm = Input (UInt (XLen .W ))
15+ val ld = new LDIO
16+ val sd = new SDIO
17+ val ldData = Output (UInt (XLen .W ))
1818 })
1919
2020 protected val ldInstVis = (io.isa === instLD) || (io.isa === instLW) || (io.isa === instLH) || (io.isa === instLB) || (io.isa === instLWU) || (io.isa === instLHU) || (io.isa === instLBU)
2121 protected val sdInstVis = (io.isa === instSD) || (io.isa === instSW) || (io.isa === instSH) || (io.isa === instSB)
2222
2323 io.ld.en := io.valid && ldInstVis
2424 io.ld.addr := io.src1 + io.imm
25- protected val bSize = 0 .U (3 .W )
26- protected val hSize = Mux ((io.isa === instLH) || (io.isa === instLHU), 1 .U , 0 .U )
27- protected val wSize = Mux ((io.isa === instLW) || (io.isa === instLWU), 2 .U , 0 .U )
28- protected val dSize = Mux ((io.isa === instLD), 3 .U , 0 .U )
29- protected val loadSize = bSize | hSize | wSize | dSize
30- io.ld.size := loadSize
25+
26+ protected val ldSize = MuxLookup (
27+ io.isa,
28+ 0 .U (3 .W ),
29+ Seq (
30+ instLH -> 1 .U (3 .W ),
31+ instLHU -> 1 .U (3 .W ),
32+ instLW -> 2 .U (3 .W ),
33+ instLWU -> 2 .U (3 .W ),
34+ instLD -> 3 .U (3 .W )
35+ )
36+ )
37+ io.ld.size := ldSize
3138
3239 protected val dInstData = io.ld.data
3340 protected val wInstData = Mux (io.ld.addr(2 ).asBool(), dInstData(63 , 32 ), dInstData(31 , 0 ))
3441 protected val hTypeData = Mux (io.ld.addr(1 ).asBool(), wInstData(31 , 16 ), wInstData(15 , 0 ))
3542 protected val bTypeData = Mux (io.ld.addr(0 ).asBool(), hTypeData(15 , 8 ), hTypeData(7 , 0 ))
3643
37- io.loadData := MuxLookup (
44+ io.ldData := MuxLookup (
3845 io.isa,
3946 0 .U (XLen .W ),
4047 Seq (
4148 instLD -> dInstData,
42- instLW -> (SignExt (wInstData, 64 )),
43- instLH -> (SignExt (hTypeData, 64 )),
44- instLB -> (SignExt (bTypeData, 64 )),
45- instLWU -> (ZeroExt (wInstData, 64 )),
46- instLHU -> (ZeroExt (hTypeData, 64 )),
47- instLBU -> (ZeroExt (bTypeData, 64 ))
49+ instLW -> (SignExt (wInstData, XLen )),
50+ instLH -> (SignExt (hTypeData, XLen )),
51+ instLB -> (SignExt (bTypeData, XLen )),
52+ instLWU -> (ZeroExt (wInstData, XLen )),
53+ instLHU -> (ZeroExt (hTypeData, XLen )),
54+ instLBU -> (ZeroExt (bTypeData, XLen ))
4855 )
4956 )
50- // protected val ldData = SignExt(io.isa.LD.asUInt, 64) & dInstData
51- // protected val lwData = SignExt(io.isa.LW.asUInt, 64) & (SignExt(wInstData, 64))
52- // protected val lhData = SignExt(io.isa.LH.asUInt, 64) & (SignExt(hTypeData, 64))
53- // protected val lbData = SignExt(io.isa.LB.asUInt, 64) & (SignExt(bTypeData, 64))
54- // protected val lwuData = SignExt(io.isa.LWU.asUInt, 64) & (ZeroExt(wInstData, 64))
55- // protected val lhuData = SignExt(io.isa.LHU.asUInt, 64) & (ZeroExt(hTypeData, 64))
56- // protected val lbuData = SignExt(io.isa.LBU.asUInt, 64) & (ZeroExt(bTypeData, 64))
57- // io.loadData := ldData | lwData | lhData | lbData | lwuData | lhuData | lbuData
5857
5958 // store signals
6059 io.sd.en := io.valid && sdInstVis
@@ -69,11 +68,6 @@ class LSU extends Module with InstConfig {
6968 instSB -> Cat (io.src2(7 , 0 ), io.src2(7 , 0 ), io.src2(7 , 0 ), io.src2(7 , 0 ), io.src2(7 , 0 ), io.src2(7 , 0 ), io.src2(7 , 0 ), io.src2(7 , 0 ))
7069 )
7170 )
72- // protected val sdData = SignExt(io.isa.SD.asUInt, 64) & io.src2
73- // protected val swData = SignExt(io.isa.SW.asUInt, 64) & Cat(io.src2(31, 0), io.src2(31, 0))
74- // protected val shData = SignExt(io.isa.SH.asUInt, 64) & Cat(io.src2(15, 0), io.src2(15, 0), io.src2(15, 0), io.src2(15, 0))
75- // protected val sbData = SignExt(io.isa.SB.asUInt, 64) & Cat(io.src2(7, 0), io.src2(7, 0), io.src2(7, 0), io.src2(7, 0), io.src2(7, 0), io.src2(7, 0), io.src2(7, 0), io.src2(7, 0))
76- // protected val storeData = sdData | swData | shData | sbData
7771
7872 protected val sdMask = MuxLookup (
7973 io.isa,
@@ -86,12 +80,6 @@ class LSU extends Module with InstConfig {
8680 )
8781 )
8882
89- // protected val dInstMask = SignExt(io.isa.SD.asUInt, 8) & "b1111_1111".U(8.W)
90- // protected val wInstMask = SignExt(io.isa.SW.asUInt, 8) & ("b0000_1111".U(8.W) << io.sd.addr(2, 0))
91- // protected val hInstMask = SignExt(io.isa.SH.asUInt, 8) & ("b0000_0011".U(8.W) << io.sd.addr(2, 0))
92- // protected val bInstMask = SignExt(io.isa.SB.asUInt, 8) & ("b0000_0001".U(8.W) << io.sd.addr(2, 0))
93- // protected val sdMask = dInstMask | wInstMask | hInstMask | bInstMask
94-
9583 protected val sdMask0 = Mux (sdMask(0 ).asBool(), " hff" .U (8 .W ), 0 .U (8 .W ))
9684 protected val sdMask1 = Mux (sdMask(1 ).asBool(), " hff" .U (8 .W ), 0 .U (8 .W ))
9785 protected val sdMask2 = Mux (sdMask(2 ).asBool(), " hff" .U (8 .W ), 0 .U (8 .W ))
0 commit comments