xref: /XiangShan/src/main/scala/xiangshan/backend/decode/DecodeUnit.scala (revision f7063a43ab34da917ba6c670d21871314340c550)
1/***************************************************************************************
2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3* Copyright (c) 2020-2021 Peng Cheng Laboratory
4*
5* XiangShan is licensed under Mulan PSL v2.
6* You can use this software according to the terms and conditions of the Mulan PSL v2.
7* You may obtain a copy of Mulan PSL v2 at:
8*          http://license.coscl.org.cn/MulanPSL2
9*
10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13*
14* See the Mulan PSL v2 for more details.
15***************************************************************************************/
16
17package xiangshan.backend.decode
18
19import org.chipsalliance.cde.config.Parameters
20import chisel3._
21import chisel3.util._
22import freechips.rocketchip.rocket.Instructions._
23import freechips.rocketchip.util.uintToBitPat
24import utility._
25import utils._
26import xiangshan.ExceptionNO.{illegalInstr, virtualInstr}
27import xiangshan._
28import xiangshan.backend.fu.FuType
29import xiangshan.backend.Bundles.{DecodedInst, DynInst, StaticInst}
30import xiangshan.backend.decode.isa.bitfield.{InstVType, XSInstBitFields}
31import xiangshan.backend.fu.vector.Bundles.VType
32
33/**
34 * Abstract trait giving defaults and other relevant values to different Decode constants/
35 */
36abstract trait DecodeConstants {
37  // This X should be used only in 1-bit signal. Otherwise, use BitPat("b???") to align with the width of UInt.
38  def X = BitPat("b0")
39  def N = BitPat("b0")
40  def Y = BitPat("b1")
41  def T = true
42  def F = false
43
44  def decodeDefault: List[BitPat] = // illegal instruction
45    //   srcType(0) srcType(1) srcType(2) fuType    fuOpType    rfWen
46    //   |          |          |          |         |           |  fpWen
47    //   |          |          |          |         |           |  |  vecWen
48    //   |          |          |          |         |           |  |  |  isXSTrap
49    //   |          |          |          |         |           |  |  |  |  noSpecExec
50    //   |          |          |          |         |           |  |  |  |  |  blockBackward
51    //   |          |          |          |         |           |  |  |  |  |  |  flushPipe
52    //   |          |          |          |         |           |  |  |  |  |  |  |  canRobCompress
53    //   |          |          |          |         |           |  |  |  |  |  |  |  |  uopSplitType
54    //   |          |          |          |         |           |  |  |  |  |  |  |  |  |             selImm
55    List(SrcType.X, SrcType.X, SrcType.X, FuType.X, FuOpType.X, N, N, N, N, N, N, N, N, UopSplitType.X, SelImm.INVALID_INSTR) // Use SelImm to indicate invalid instr
56
57  val decodeArray: Array[(BitPat, XSDecodeBase)]
58  final def table: Array[(BitPat, List[BitPat])] = decodeArray.map(x => (x._1, x._2.generate()))
59}
60
61trait DecodeUnitConstants
62{
63  // abstract out instruction decode magic numbers
64  val RD_MSB  = 11
65  val RD_LSB  = 7
66  val RS1_MSB = 19
67  val RS1_LSB = 15
68  val RS2_MSB = 24
69  val RS2_LSB = 20
70  val RS3_MSB = 31
71  val RS3_LSB = 27
72}
73
74/**
75 * Decoded control signals
76 * See xiangshan/package.scala, xiangshan/backend/package.scala, Bundle.scala
77 */
78
79abstract class XSDecodeBase {
80  def X = BitPat("b?")
81  def N = BitPat("b0")
82  def Y = BitPat("b1")
83  def T = true
84  def F = false
85  def generate() : List[BitPat]
86}
87
88case class XSDecode(
89  src1: BitPat, src2: BitPat, src3: BitPat,
90  fu: FuType.OHType, fuOp: BitPat, selImm: BitPat,
91  uopSplitType: BitPat = UopSplitType.X,
92  xWen: Boolean = false,
93  fWen: Boolean = false,
94  vWen: Boolean = false,
95  mWen: Boolean = false,
96  xsTrap: Boolean = false,
97  noSpec: Boolean = false,
98  blockBack: Boolean = false,
99  flushPipe: Boolean = false,
100  canRobCompress: Boolean = false,
101) extends XSDecodeBase {
102  def generate() : List[BitPat] = {
103    List (src1, src2, src3, BitPat(fu.U(FuType.num.W)), fuOp, xWen.B, fWen.B, (vWen || mWen).B, xsTrap.B, noSpec.B, blockBack.B, flushPipe.B, canRobCompress.B, uopSplitType, selImm)
104  }
105}
106
107case class FDecode(
108  src1: BitPat, src2: BitPat, src3: BitPat,
109  fu: FuType.OHType, fuOp: BitPat, selImm: BitPat = SelImm.X,
110  uopSplitType: BitPat = UopSplitType.X,
111  xWen: Boolean = false,
112  fWen: Boolean = false,
113  vWen: Boolean = false,
114  mWen: Boolean = false,
115  xsTrap: Boolean = false,
116  noSpec: Boolean = false,
117  blockBack: Boolean = false,
118  flushPipe: Boolean = false,
119  canRobCompress: Boolean = false,
120) extends XSDecodeBase {
121  def generate() : List[BitPat] = {
122    XSDecode(src1, src2, src3, fu, fuOp, selImm, uopSplitType, xWen, fWen, vWen, mWen, xsTrap, noSpec, blockBack, flushPipe, canRobCompress).generate()
123  }
124}
125
126/**
127 * Decode constants for RV64
128 */
129object X64Decode extends DecodeConstants {
130  val decodeArray: Array[(BitPat, XSDecodeBase)] = Array(
131    LD      -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.ldu, LSUOpType.ld  , SelImm.IMM_I, xWen = T),
132    LWU     -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.ldu, LSUOpType.lwu , SelImm.IMM_I, xWen = T),
133    SD      -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.stu, LSUOpType.sd  , SelImm.IMM_S          ),
134
135    SLLI    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.sll , SelImm.IMM_I, xWen = T, canRobCompress = T),
136    SRLI    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.srl , SelImm.IMM_I, xWen = T, canRobCompress = T),
137    SRAI    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.sra , SelImm.IMM_I, xWen = T, canRobCompress = T),
138
139    ADDIW   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.addw, SelImm.IMM_I, xWen = T, canRobCompress = T),
140    SLLIW   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.sllw, SelImm.IMM_I, xWen = T, canRobCompress = T),
141    SRAIW   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.sraw, SelImm.IMM_I, xWen = T, canRobCompress = T),
142    SRLIW   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.srlw, SelImm.IMM_I, xWen = T, canRobCompress = T),
143
144    ADDW    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.addw, SelImm.X    , xWen = T, canRobCompress = T),
145    SUBW    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.subw, SelImm.X    , xWen = T, canRobCompress = T),
146    SLLW    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sllw, SelImm.X    , xWen = T, canRobCompress = T),
147    SRAW    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sraw, SelImm.X    , xWen = T, canRobCompress = T),
148    SRLW    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.srlw, SelImm.X    , xWen = T, canRobCompress = T),
149
150    RORW    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.rorw, SelImm.X    , xWen = T, canRobCompress = T),
151    RORIW   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.rorw, SelImm.IMM_I, xWen = T, canRobCompress = T),
152    ROLW    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.rolw, SelImm.X    , xWen = T, canRobCompress = T),
153  )
154}
155
156/**
157 * Overall Decode constants
158 */
159object XDecode extends DecodeConstants {
160  val decodeArray: Array[(BitPat, XSDecodeBase)] = Array(
161    LW      -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.ldu, LSUOpType.lw  , SelImm.IMM_I, xWen = T),
162    LH      -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.ldu, LSUOpType.lh  , SelImm.IMM_I, xWen = T),
163    LHU     -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.ldu, LSUOpType.lhu , SelImm.IMM_I, xWen = T),
164    LB      -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.ldu, LSUOpType.lb  , SelImm.IMM_I, xWen = T),
165    LBU     -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.ldu, LSUOpType.lbu , SelImm.IMM_I, xWen = T),
166    SW      -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.stu, LSUOpType.sw  , SelImm.IMM_S          ),
167    SH      -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.stu, LSUOpType.sh  , SelImm.IMM_S          ),
168    SB      -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.stu, LSUOpType.sb  , SelImm.IMM_S          ),
169    LUI     -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.add , SelImm.IMM_U, xWen = T, canRobCompress = T),
170    ADDI    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.add , SelImm.IMM_I, xWen = T, canRobCompress = T),
171    ANDI    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.and , SelImm.IMM_I, xWen = T, canRobCompress = T),
172    ORI     -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.or  , SelImm.IMM_I, xWen = T, canRobCompress = T),
173    XORI    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.xor , SelImm.IMM_I, xWen = T, canRobCompress = T),
174    SLTI    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.slt , SelImm.IMM_I, xWen = T, canRobCompress = T),
175    SLTIU   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.sltu, SelImm.IMM_I, xWen = T, canRobCompress = T),
176    SLL     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sll , SelImm.X    , xWen = T, canRobCompress = T),
177    ADD     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.add , SelImm.X    , xWen = T, canRobCompress = T),
178    SUB     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sub , SelImm.X    , xWen = T, canRobCompress = T),
179    SLT     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.slt , SelImm.X    , xWen = T, canRobCompress = T),
180    SLTU    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sltu, SelImm.X    , xWen = T, canRobCompress = T),
181    AND     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.and , SelImm.X    , xWen = T, canRobCompress = T),
182    OR      -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.or  , SelImm.X    , xWen = T, canRobCompress = T),
183    XOR     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.xor , SelImm.X    , xWen = T, canRobCompress = T),
184    SRA     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sra , SelImm.X    , xWen = T, canRobCompress = T),
185    SRL     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.srl , SelImm.X    , xWen = T, canRobCompress = T),
186
187    MUL     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mul, MDUOpType.mul   , SelImm.X, xWen = T, canRobCompress = T),
188    MULH    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mul, MDUOpType.mulh  , SelImm.X, xWen = T, canRobCompress = T),
189    MULHU   -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mul, MDUOpType.mulhu , SelImm.X, xWen = T, canRobCompress = T),
190    MULHSU  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mul, MDUOpType.mulhsu, SelImm.X, xWen = T, canRobCompress = T),
191    MULW    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mul, MDUOpType.mulw  , SelImm.X, xWen = T, canRobCompress = T),
192
193    DIV     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.div, MDUOpType.div   , SelImm.X, xWen = T, canRobCompress = T),
194    DIVU    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.div, MDUOpType.divu  , SelImm.X, xWen = T, canRobCompress = T),
195    REM     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.div, MDUOpType.rem   , SelImm.X, xWen = T, canRobCompress = T),
196    REMU    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.div, MDUOpType.remu  , SelImm.X, xWen = T, canRobCompress = T),
197    DIVW    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.div, MDUOpType.divw  , SelImm.X, xWen = T, canRobCompress = T),
198    DIVUW   -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.div, MDUOpType.divuw , SelImm.X, xWen = T, canRobCompress = T),
199    REMW    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.div, MDUOpType.remw  , SelImm.X, xWen = T, canRobCompress = T),
200    REMUW   -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.div, MDUOpType.remuw , SelImm.X, xWen = T, canRobCompress = T),
201
202    AUIPC   -> XSDecode(SrcType.pc , SrcType.imm, SrcType.X, FuType.jmp, JumpOpType.auipc, SelImm.IMM_U , xWen = T),
203    JAL     -> XSDecode(SrcType.pc , SrcType.imm, SrcType.X, FuType.jmp, JumpOpType.jal  , SelImm.IMM_UJ, xWen = T),
204    JALR    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.jmp, JumpOpType.jalr , SelImm.IMM_I , uopSplitType = UopSplitType.SCA_SIM, xWen = T),
205    BEQ     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.brh, BRUOpType.beq   , SelImm.IMM_SB          ),
206    BNE     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.brh, BRUOpType.bne   , SelImm.IMM_SB          ),
207    BGE     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.brh, BRUOpType.bge   , SelImm.IMM_SB          ),
208    BGEU    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.brh, BRUOpType.bgeu  , SelImm.IMM_SB          ),
209    BLT     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.brh, BRUOpType.blt   , SelImm.IMM_SB          ),
210    BLTU    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.brh, BRUOpType.bltu  , SelImm.IMM_SB          ),
211
212    // I-type, the immediate12 holds the CSR register.
213    CSRRW   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.csr, CSROpType.wrt , SelImm.IMM_I, xWen = T, noSpec = T, blockBack = T),
214    CSRRS   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.csr, CSROpType.set , SelImm.IMM_I, xWen = T, noSpec = T, blockBack = T),
215    CSRRC   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.csr, CSROpType.clr , SelImm.IMM_I, xWen = T, noSpec = T, blockBack = T),
216
217    CSRRWI  -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.csr, CSROpType.wrti, SelImm.IMM_Z, xWen = T, noSpec = T, blockBack = T),
218    CSRRSI  -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.csr, CSROpType.seti, SelImm.IMM_Z, xWen = T, noSpec = T, blockBack = T),
219    CSRRCI  -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.csr, CSROpType.clri, SelImm.IMM_Z, xWen = T, noSpec = T, blockBack = T),
220
221    EBREAK  -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.csr, CSROpType.jmp, SelImm.IMM_I, xWen = T, noSpec = T, blockBack = T),
222    ECALL   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.csr, CSROpType.jmp, SelImm.IMM_I, xWen = T, noSpec = T, blockBack = T),
223    SRET    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.csr, CSROpType.jmp, SelImm.IMM_I, xWen = T, noSpec = T, blockBack = T),
224    MRET    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.csr, CSROpType.jmp, SelImm.IMM_I, xWen = T, noSpec = T, blockBack = T),
225    DRET    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.csr, CSROpType.jmp, SelImm.IMM_I, xWen = T, noSpec = T, blockBack = T),
226    WFI     -> XSDecode(SrcType.pc , SrcType.imm, SrcType.X, FuType.csr, CSROpType.wfi, SelImm.X    , xWen = T, noSpec = T, blockBack = T),
227
228    SFENCE_VMA -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.fence, FenceOpType.sfence, SelImm.X, noSpec = T, blockBack = T, flushPipe = T),
229    FENCE_I    -> XSDecode(SrcType.pc , SrcType.imm, SrcType.X, FuType.fence, FenceOpType.fencei, SelImm.X, noSpec = T, blockBack = T, flushPipe = T),
230    FENCE      -> XSDecode(SrcType.pc , SrcType.imm, SrcType.X, FuType.fence, FenceOpType.fence , SelImm.X, noSpec = T, blockBack = T, flushPipe = T),
231
232    // A-type
233    AMOADD_W  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amoadd_w , SelImm.X, xWen = T, noSpec = T, blockBack = T),
234    AMOXOR_W  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amoxor_w , SelImm.X, xWen = T, noSpec = T, blockBack = T),
235    AMOSWAP_W -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amoswap_w, SelImm.X, xWen = T, noSpec = T, blockBack = T),
236    AMOAND_W  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amoand_w , SelImm.X, xWen = T, noSpec = T, blockBack = T),
237    AMOOR_W   -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amoor_w  , SelImm.X, xWen = T, noSpec = T, blockBack = T),
238    AMOMIN_W  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amomin_w , SelImm.X, xWen = T, noSpec = T, blockBack = T),
239    AMOMINU_W -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amominu_w, SelImm.X, xWen = T, noSpec = T, blockBack = T),
240    AMOMAX_W  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amomax_w , SelImm.X, xWen = T, noSpec = T, blockBack = T),
241    AMOMAXU_W -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amomaxu_w, SelImm.X, xWen = T, noSpec = T, blockBack = T),
242
243    AMOADD_D  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amoadd_d,  SelImm.X, xWen = T, noSpec = T, blockBack = T),
244    AMOXOR_D  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amoxor_d,  SelImm.X, xWen = T, noSpec = T, blockBack = T),
245    AMOSWAP_D -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amoswap_d, SelImm.X, xWen = T, noSpec = T, blockBack = T),
246    AMOAND_D  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amoand_d,  SelImm.X, xWen = T, noSpec = T, blockBack = T),
247    AMOOR_D   -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amoor_d,   SelImm.X, xWen = T, noSpec = T, blockBack = T),
248    AMOMIN_D  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amomin_d,  SelImm.X, xWen = T, noSpec = T, blockBack = T),
249    AMOMINU_D -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amominu_d, SelImm.X, xWen = T, noSpec = T, blockBack = T),
250    AMOMAX_D  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amomax_d,  SelImm.X, xWen = T, noSpec = T, blockBack = T),
251    AMOMAXU_D -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.amomaxu_d, SelImm.X, xWen = T, noSpec = T, blockBack = T),
252
253    LR_W    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.mou, LSUOpType.lr_w, SelImm.X, xWen = T, noSpec = T, blockBack = T),
254    LR_D    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.mou, LSUOpType.lr_d, SelImm.X, xWen = T, noSpec = T, blockBack = T),
255    SC_W    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.sc_w, SelImm.X, xWen = T, noSpec = T, blockBack = T),
256    SC_D    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.mou, LSUOpType.sc_d, SelImm.X, xWen = T, noSpec = T, blockBack = T),
257
258    ANDN    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.andn, SelImm.X, xWen = T, canRobCompress = T),
259    ORN     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.orn , SelImm.X, xWen = T, canRobCompress = T),
260    XNOR    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.xnor, SelImm.X, xWen = T, canRobCompress = T),
261    ORC_B   -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.alu, ALUOpType.orcb, SelImm.X, xWen = T, canRobCompress = T),
262
263    MIN     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.min , SelImm.X, xWen = T, canRobCompress = T),
264    MINU    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.minu, SelImm.X, xWen = T, canRobCompress = T),
265    MAX     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.max , SelImm.X, xWen = T, canRobCompress = T),
266    MAXU    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.maxu, SelImm.X, xWen = T, canRobCompress = T),
267
268    SEXT_B  -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.alu, ALUOpType.sextb, SelImm.X, xWen = T, canRobCompress = T),
269    PACKH   -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.packh, SelImm.X, xWen = T, canRobCompress = T),
270    SEXT_H  -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.alu, ALUOpType.sexth, SelImm.X, xWen = T, canRobCompress = T),
271    PACKW   -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.packw, SelImm.X, xWen = T, canRobCompress = T),
272    BREV8   -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.alu, ALUOpType.revb , SelImm.X, xWen = T, canRobCompress = T),
273    REV8    -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.alu, ALUOpType.rev8 , SelImm.X, xWen = T, canRobCompress = T),
274    PACK    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.pack , SelImm.X, xWen = T, canRobCompress = T),
275
276    BSET    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.bset, SelImm.X    , xWen = T, canRobCompress = T),
277    BSETI   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.bset, SelImm.IMM_I, xWen = T, canRobCompress = T),
278    BCLR    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.bclr, SelImm.X    , xWen = T, canRobCompress = T),
279    BCLRI   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.bclr, SelImm.IMM_I, xWen = T, canRobCompress = T),
280    BINV    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.binv, SelImm.X    , xWen = T, canRobCompress = T),
281    BINVI   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.binv, SelImm.IMM_I, xWen = T, canRobCompress = T),
282    BEXT    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.bext, SelImm.X    , xWen = T, canRobCompress = T),
283    BEXTI   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.bext, SelImm.IMM_I, xWen = T, canRobCompress = T),
284
285    ROR     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.ror, SelImm.X     , xWen = T, canRobCompress = T),
286    RORI    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.ror, SelImm.IMM_I , xWen = T, canRobCompress = T),
287    ROL     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.rol, SelImm.X     , xWen = T, canRobCompress = T),
288
289    SH1ADD    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sh1add  , SelImm.X    , xWen = T, canRobCompress = T),
290    SH2ADD    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sh2add  , SelImm.X    , xWen = T, canRobCompress = T),
291    SH3ADD    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sh3add  , SelImm.X    , xWen = T, canRobCompress = T),
292    SH1ADD_UW -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sh1adduw, SelImm.X    , xWen = T, canRobCompress = T),
293    SH2ADD_UW -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sh2adduw, SelImm.X    , xWen = T, canRobCompress = T),
294    SH3ADD_UW -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.sh3adduw, SelImm.X    , xWen = T, canRobCompress = T),
295    ADD_UW    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.alu, ALUOpType.adduw   , SelImm.X    , xWen = T, canRobCompress = T),
296    SLLI_UW   -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.slliuw  , SelImm.IMM_I, xWen = T, canRobCompress = T),
297  )
298}
299
300/**
301 * FP Decode constants
302 */
303object FpDecode extends DecodeConstants{
304  val decodeArray: Array[(BitPat, XSDecodeBase)] = Array(
305    FLW     -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.ldu, LSUOpType.lw, selImm = SelImm.IMM_I, fWen = T),
306    FLD     -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.ldu, LSUOpType.ld, selImm = SelImm.IMM_I, fWen = T),
307    FSW     -> FDecode(SrcType.reg, SrcType.fp,  SrcType.X, FuType.stu, LSUOpType.sw, selImm = SelImm.IMM_S          ),
308    FSD     -> FDecode(SrcType.reg, SrcType.fp,  SrcType.X, FuType.stu, LSUOpType.sd, selImm = SelImm.IMM_S          ),
309
310    FMV_D_X -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.i2v, IF2VectorType.FMX_D_X, fWen = T, canRobCompress = T),
311    FMV_W_X -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.i2v, IF2VectorType.FMX_W_X, fWen = T, canRobCompress = T),
312
313    // Int to FP
314    FCVT_S_W  -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.i2f, FuOpType.X, fWen = T, canRobCompress = T),
315    FCVT_S_WU -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.i2f, FuOpType.X, fWen = T, canRobCompress = T),
316    FCVT_S_L  -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.i2f, FuOpType.X, fWen = T, canRobCompress = T),
317    FCVT_S_LU -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.i2f, FuOpType.X, fWen = T, canRobCompress = T),
318
319    FCVT_D_W  -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.i2f, FuOpType.X, fWen = T, canRobCompress = T),
320    FCVT_D_WU -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.i2f, FuOpType.X, fWen = T, canRobCompress = T),
321    FCVT_D_L  -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.i2f, FuOpType.X, fWen = T, canRobCompress = T),
322    FCVT_D_LU -> FDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.i2f, FuOpType.X, fWen = T, canRobCompress = T),
323
324  )
325}
326
327/**
328  * Bit Manipulation Decode
329  */
330object BDecode extends DecodeConstants{
331  val decodeArray: Array[(BitPat, XSDecodeBase)] = Array(
332    // Basic bit manipulation
333    CLZ     -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.clz,    SelImm.X, xWen = T, canRobCompress = T),
334    CTZ     -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.ctz,    SelImm.X, xWen = T, canRobCompress = T),
335    CPOP    -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.cpop,   SelImm.X, xWen = T, canRobCompress = T),
336    XPERM8  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.xpermb, SelImm.X, xWen = T, canRobCompress = T),
337    XPERM4  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.xpermn, SelImm.X, xWen = T, canRobCompress = T),
338
339    CLZW    -> XSDecode(SrcType.reg, SrcType.DC, SrcType.X, FuType.bku, BKUOpType.clzw,    SelImm.X, xWen = T, canRobCompress = T),
340    CTZW    -> XSDecode(SrcType.reg, SrcType.DC, SrcType.X, FuType.bku, BKUOpType.ctzw,    SelImm.X, xWen = T, canRobCompress = T),
341    CPOPW   -> XSDecode(SrcType.reg, SrcType.DC, SrcType.X, FuType.bku, BKUOpType.cpopw,   SelImm.X, xWen = T, canRobCompress = T),
342
343    CLMUL   -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.clmul,  SelImm.X, xWen = T, canRobCompress = T),
344    CLMULH  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.clmulh, SelImm.X, xWen = T, canRobCompress = T),
345    CLMULR  -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.clmulr, SelImm.X, xWen = T, canRobCompress = T),
346
347    AES64ES    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.aes64es,    SelImm.X    , xWen = T, canRobCompress = T),
348    AES64ESM   -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.aes64esm,   SelImm.X    , xWen = T, canRobCompress = T),
349    AES64DS    -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.aes64ds,    SelImm.X    , xWen = T, canRobCompress = T),
350    AES64DSM   -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.aes64dsm,   SelImm.X    , xWen = T, canRobCompress = T),
351    AES64IM    -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.aes64im,    SelImm.X    , xWen = T, canRobCompress = T),
352    AES64KS1I  -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.bku, BKUOpType.aes64ks1i,  SelImm.IMM_I, xWen = T, canRobCompress = T),
353    AES64KS2   -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.aes64ks2,   SelImm.X    , xWen = T, canRobCompress = T),
354    SHA256SUM0 -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.sha256sum0, SelImm.X    , xWen = T, canRobCompress = T),
355    SHA256SUM1 -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.sha256sum1, SelImm.X    , xWen = T, canRobCompress = T),
356    SHA256SIG0 -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.sha256sig0, SelImm.X    , xWen = T, canRobCompress = T),
357    SHA256SIG1 -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.sha256sig1, SelImm.X    , xWen = T, canRobCompress = T),
358    SHA512SUM0 -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.sha512sum0, SelImm.X    , xWen = T, canRobCompress = T),
359    SHA512SUM1 -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.sha512sum1, SelImm.X    , xWen = T, canRobCompress = T),
360    SHA512SIG0 -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.sha512sig0, SelImm.X    , xWen = T, canRobCompress = T),
361    SHA512SIG1 -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.sha512sig1, SelImm.X    , xWen = T, canRobCompress = T),
362    SM3P0      -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.sm3p0,      SelImm.X    , xWen = T, canRobCompress = T),
363    SM3P1      -> XSDecode(SrcType.reg, SrcType.DC,  SrcType.X, FuType.bku, BKUOpType.sm3p1,      SelImm.X    , xWen = T, canRobCompress = T),
364    SM4KS0     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.sm4ks0,     SelImm.X    , xWen = T, canRobCompress = T),
365    SM4KS1     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.sm4ks1,     SelImm.X    , xWen = T, canRobCompress = T),
366    SM4KS2     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.sm4ks2,     SelImm.X    , xWen = T, canRobCompress = T),
367    SM4KS3     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.sm4ks3,     SelImm.X    , xWen = T, canRobCompress = T),
368    SM4ED0     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.sm4ed0,     SelImm.X    , xWen = T, canRobCompress = T),
369    SM4ED1     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.sm4ed1,     SelImm.X    , xWen = T, canRobCompress = T),
370    SM4ED2     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.sm4ed2,     SelImm.X    , xWen = T, canRobCompress = T),
371    SM4ED3     -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.bku, BKUOpType.sm4ed3,     SelImm.X    , xWen = T, canRobCompress = T),
372  )
373}
374
375/**
376 * FP Divide SquareRoot Constants
377 */
378object FDivSqrtDecode extends DecodeConstants {
379  val decodeArray: Array[(BitPat, XSDecodeBase)] = Array(
380    FDIV_S  -> FDecode(SrcType.fp,  SrcType.fp,  SrcType.X, FuType.fDivSqrt, FuOpType.X, fWen = T, canRobCompress = T),
381    FDIV_D  -> FDecode(SrcType.fp,  SrcType.fp,  SrcType.X, FuType.fDivSqrt, FuOpType.X, fWen = T, canRobCompress = T),
382    FSQRT_S -> FDecode(SrcType.fp,  SrcType.imm, SrcType.X, FuType.fDivSqrt, FuOpType.X, fWen = T, canRobCompress = T),
383    FSQRT_D -> FDecode(SrcType.fp,  SrcType.imm, SrcType.X, FuType.fDivSqrt, FuOpType.X, fWen = T, canRobCompress = T),
384  )
385}
386
387/**
388 * Svinval extension Constants
389 */
390object SvinvalDecode extends DecodeConstants {
391  val decodeArray: Array[(BitPat, XSDecodeBase)] = Array(
392    /* sinval_vma is like sfence.vma , but sinval_vma can be dispatched and issued like normal instructions while sfence.vma
393     * must assure it is the ONLY instrucion executing in backend.
394     */
395    SINVAL_VMA        -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.fence, FenceOpType.sfence, SelImm.X),
396    /* sfecne.w.inval is the begin instrucion of a TLB flush which set *noSpecExec* and *blockBackward* signals
397     * so when it comes to dispatch , it will block all instruction after itself until all instrucions ahead of it in rob commit
398     * then dispatch and issue this instrucion to flush sbuffer to dcache
399     * after this instrucion commits , issue following sinval_vma instructions (out of order) to flush TLB
400     */
401    SFENCE_W_INVAL    -> XSDecode(SrcType.DC, SrcType.DC, SrcType.X, FuType.fence, FenceOpType.nofence, SelImm.X, noSpec = T, blockBack = T),
402    /* sfecne.inval.ir is the end instrucion of a TLB flush which set *noSpecExec* *blockBackward* and *flushPipe* signals
403     * so when it comes to dispatch , it will wait until all sinval_vma ahead of it in rob commit
404     * then dispatch and issue this instrucion
405     * when it commit at the head of rob , flush the pipeline since some instrucions have been fetched to ibuffer using old TLB map
406     */
407    SFENCE_INVAL_IR   -> XSDecode(SrcType.DC, SrcType.DC, SrcType.X, FuType.fence, FenceOpType.nofence, SelImm.X, noSpec = T, blockBack = T, flushPipe = T)
408    /* what is Svinval extension ?
409     *                       ----->             sfecne.w.inval
410     * sfence.vma   vpn1     ----->             sinval_vma   vpn1
411     * sfence.vma   vpn2     ----->             sinval_vma   vpn2
412     *                       ----->             sfecne.inval.ir
413     *
414     * sfence.vma should be executed in-order and it flushes the pipeline after committing
415     * we can parallel sfence instrucions with this extension
416     */
417  )
418}
419
420/*
421 * CBO decode
422 */
423object CBODecode extends DecodeConstants {
424  val decodeArray: Array[(BitPat, XSDecodeBase)] = Array(
425    CBO_ZERO  -> XSDecode(SrcType.reg, SrcType.DC, SrcType.X, FuType.stu, LSUOpType.cbo_zero , SelImm.IMM_S),
426    CBO_CLEAN -> XSDecode(SrcType.reg, SrcType.DC, SrcType.X, FuType.stu, LSUOpType.cbo_clean, SelImm.IMM_S),
427    CBO_FLUSH -> XSDecode(SrcType.reg, SrcType.DC, SrcType.X, FuType.stu, LSUOpType.cbo_flush, SelImm.IMM_S),
428    CBO_INVAL -> XSDecode(SrcType.reg, SrcType.DC, SrcType.X, FuType.stu, LSUOpType.cbo_inval, SelImm.IMM_S)
429  )
430}
431
432/*
433 * Hypervisor decode
434 */
435object HypervisorDecode extends DecodeConstants {
436  override val decodeArray: Array[(BitPat, XSDecodeBase)] = Array(
437    HFENCE_GVMA -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.fence, FenceOpType.hfence_g, SelImm.X, noSpec = T, blockBack = T, flushPipe = T),
438    HFENCE_VVMA -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.fence, FenceOpType.hfence_v, SelImm.X, noSpec = T, blockBack = T, flushPipe = T),
439    HINVAL_GVMA -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.fence, FenceOpType.hfence_g, SelImm.X),
440    HINVAL_VVMA -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.fence, FenceOpType.hfence_v, SelImm.X),
441    HLV_B       -> XSDecode(SrcType.reg, SrcType.X,   SrcType.X, FuType.ldu,   LSUOpType.hlvb,       SelImm.X, xWen = T),
442    HLV_BU      -> XSDecode(SrcType.reg, SrcType.X,   SrcType.X, FuType.ldu,   LSUOpType.hlvbu,      SelImm.X, xWen = T),
443    HLV_D       -> XSDecode(SrcType.reg, SrcType.X,   SrcType.X, FuType.ldu,   LSUOpType.hlvd,       SelImm.X, xWen = T),
444    HLV_H       -> XSDecode(SrcType.reg, SrcType.X,   SrcType.X, FuType.ldu,   LSUOpType.hlvh,       SelImm.X, xWen = T),
445    HLV_HU      -> XSDecode(SrcType.reg, SrcType.X,   SrcType.X, FuType.ldu,   LSUOpType.hlvhu,      SelImm.X, xWen = T),
446    HLV_W       -> XSDecode(SrcType.reg, SrcType.X,   SrcType.X, FuType.ldu,   LSUOpType.hlvw,       SelImm.X, xWen = T),
447    HLV_WU      -> XSDecode(SrcType.reg, SrcType.X,   SrcType.X, FuType.ldu,   LSUOpType.hlvwu,      SelImm.X, xWen = T),
448    HLVX_HU     -> XSDecode(SrcType.reg, SrcType.X,   SrcType.X, FuType.ldu,   LSUOpType.hlvxhu,     SelImm.X, xWen = T),
449    HLVX_WU     -> XSDecode(SrcType.reg, SrcType.X,   SrcType.X, FuType.ldu,   LSUOpType.hlvxwu,     SelImm.X, xWen = T),
450    HSV_B       -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.stu,   LSUOpType.hsvb,       SelImm.X),
451    HSV_D       -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.stu,   LSUOpType.hsvd,       SelImm.X),
452    HSV_H       -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.stu,   LSUOpType.hsvh,       SelImm.X),
453    HSV_W       -> XSDecode(SrcType.reg, SrcType.reg, SrcType.X, FuType.stu,   LSUOpType.hsvw,       SelImm.X),
454  )
455}
456
457/**
458 * XiangShan Trap Decode constants
459 */
460object XSTrapDecode extends DecodeConstants {
461  def TRAP = BitPat("b000000000000?????000000001101011")
462  val decodeArray: Array[(BitPat, XSDecodeBase)] = Array(
463    TRAP    -> XSDecode(SrcType.reg, SrcType.imm, SrcType.X, FuType.alu, ALUOpType.add, SelImm.IMM_I, xWen = T, xsTrap = T, noSpec = T, blockBack = T)
464  )
465}
466
467abstract class Imm(val len: Int) {
468  def toImm32(minBits: UInt): UInt = do_toImm32(minBits(len - 1, 0))
469  def do_toImm32(minBits: UInt): UInt
470  def minBitsFromInstr(instr: UInt): UInt
471}
472
473case class Imm_I() extends Imm(12) {
474  override def do_toImm32(minBits: UInt): UInt = SignExt(minBits(len - 1, 0), 32)
475
476  override def minBitsFromInstr(instr: UInt): UInt =
477    Cat(instr(31, 20))
478}
479
480case class Imm_S() extends Imm(12) {
481  override def do_toImm32(minBits: UInt): UInt = SignExt(minBits, 32)
482
483  override def minBitsFromInstr(instr: UInt): UInt =
484    Cat(instr(31, 25), instr(11, 7))
485}
486
487case class Imm_B() extends Imm(12) {
488  override def do_toImm32(minBits: UInt): UInt = SignExt(Cat(minBits, 0.U(1.W)), 32)
489
490  override def minBitsFromInstr(instr: UInt): UInt =
491    Cat(instr(31), instr(7), instr(30, 25), instr(11, 8))
492}
493
494case class Imm_U() extends Imm(20){
495  override def do_toImm32(minBits: UInt): UInt = Cat(minBits(len - 1, 0), 0.U(12.W))
496
497  override def minBitsFromInstr(instr: UInt): UInt = {
498    instr(31, 12)
499  }
500}
501
502case class Imm_J() extends Imm(20){
503  override def do_toImm32(minBits: UInt): UInt = SignExt(Cat(minBits, 0.U(1.W)), 32)
504
505  override def minBitsFromInstr(instr: UInt): UInt = {
506    Cat(instr(31), instr(19, 12), instr(20), instr(30, 25), instr(24, 21))
507  }
508}
509
510case class Imm_Z() extends Imm(12 + 5){
511  override def do_toImm32(minBits: UInt): UInt = minBits
512
513  override def minBitsFromInstr(instr: UInt): UInt = {
514    Cat(instr(19, 15), instr(31, 20))
515  }
516}
517
518case class Imm_B6() extends Imm(6){
519  override def do_toImm32(minBits: UInt): UInt = ZeroExt(minBits, 32)
520
521  override def minBitsFromInstr(instr: UInt): UInt = {
522    instr(25, 20)
523  }
524}
525
526case class Imm_OPIVIS() extends Imm(5){
527  override def do_toImm32(minBits: UInt): UInt = SignExt(minBits, 32)
528
529  override def minBitsFromInstr(instr: UInt): UInt = {
530    instr(19, 15)
531  }
532}
533
534case class Imm_OPIVIU() extends Imm(5){
535  override def do_toImm32(minBits: UInt): UInt = ZeroExt(minBits, 32)
536
537  override def minBitsFromInstr(instr: UInt): UInt = {
538    instr(19, 15)
539  }
540}
541
542case class Imm_VSETVLI() extends Imm(11){
543  override def do_toImm32(minBits: UInt): UInt = SignExt(minBits, 32)
544
545  override def minBitsFromInstr(instr: UInt): UInt = {
546    instr(30, 20)
547  }
548}
549
550case class Imm_VSETIVLI() extends Imm(13){
551  override def do_toImm32(minBits: UInt): UInt = SignExt(minBits, 32)
552
553  override def minBitsFromInstr(instr: UInt): UInt = {
554    val rvInst: XSInstBitFields = instr.asTypeOf(new XSInstBitFields)
555    val uimm5 = rvInst.UIMM_VSETIVLI
556    val vtype8 = rvInst.ZIMM_VTYPE
557    Cat(uimm5, vtype8)
558  }
559  /**
560    * get VType from extended imm
561    * @param extedImm
562    * @return VType
563    */
564  def getVType(extedImm: UInt): InstVType = {
565    val vtype = Wire(new InstVType)
566    vtype := extedImm(7, 0).asTypeOf(new InstVType)
567    vtype
568  }
569
570  def getAvl(extedImm: UInt): UInt = {
571    extedImm(12, 8)
572  }
573}
574
575case class Imm_LUI32() extends Imm(32){
576  override def do_toImm32(minBits: UInt): UInt = minBits(31, 0)
577
578  override def minBitsFromInstr(instr: UInt): UInt = {
579    instr(31, 0)
580  }
581}
582
583case class Imm_VRORVI() extends Imm(6){
584  override def do_toImm32(minBits: UInt): UInt = ZeroExt(minBits, 32)
585
586  override def minBitsFromInstr(instr: UInt): UInt = {
587    Cat(instr(26), instr(19, 15))
588  }
589}
590
591object ImmUnion {
592  val I = Imm_I()
593  val S = Imm_S()
594  val B = Imm_B()
595  val U = Imm_U()
596  val J = Imm_J()
597  val Z = Imm_Z()
598  val B6 = Imm_B6()
599  val OPIVIS = Imm_OPIVIS()
600  val OPIVIU = Imm_OPIVIU()
601  val VSETVLI = Imm_VSETVLI()
602  val VSETIVLI = Imm_VSETIVLI()
603  val LUI32 = Imm_LUI32()
604  val VRORVI = Imm_VRORVI()
605
606  // do not add special type lui32 to this, keep ImmUnion max len being 20.
607  val imms = Seq(I, S, B, U, J, Z, B6, OPIVIS, OPIVIU, VSETVLI, VSETIVLI, VRORVI)
608  val maxLen = imms.maxBy(_.len).len
609  val immSelMap = Seq(
610    SelImm.IMM_I,
611    SelImm.IMM_S,
612    SelImm.IMM_SB,
613    SelImm.IMM_U,
614    SelImm.IMM_UJ,
615    SelImm.IMM_Z,
616    SelImm.IMM_B6,
617    SelImm.IMM_OPIVIS,
618    SelImm.IMM_OPIVIU,
619    SelImm.IMM_VSETVLI,
620    SelImm.IMM_VSETIVLI,
621    SelImm.IMM_VRORVI,
622  ).zip(imms)
623  println(s"ImmUnion max len: $maxLen")
624}
625
626case class Imm_LUI_LOAD() {
627  def immFromLuiLoad(lui_imm: UInt, load_imm: UInt): UInt = {
628    val loadImm = load_imm(Imm_I().len - 1, 0)
629    Cat(lui_imm(ImmUnion.maxLen - loadImm.getWidth - 1, 0), loadImm)
630  }
631  def getLuiImm(uop: DynInst): UInt = {
632    val loadImmLen = Imm_I().len
633    val imm_u = Cat(uop.psrc(1), uop.psrc(0), uop.imm(ImmUnion.maxLen - 1, loadImmLen))
634    Cat(Imm_U().toImm32(imm_u)(31, loadImmLen), uop.imm(loadImmLen - 1, 0))
635  }
636}
637
638/**
639 * IO bundle for the Decode unit
640 */
641class DecodeUnitDeqIO(implicit p: Parameters) extends XSBundle {
642  val decodedInst = Output(new DecodedInst)
643  val isComplex = Output(Bool())
644  val uopInfo = Output(new UopInfo)
645}
646class DecodeUnitIO(implicit p: Parameters) extends XSBundle {
647  val enq = new Bundle {
648    val ctrlFlow = Input(new StaticInst)
649    val vtype = Input(new VType)
650  }
651//  val vconfig = Input(UInt(XLEN.W))
652  val deq = new DecodeUnitDeqIO
653  val csrCtrl = Input(new CustomCSRCtrlIO)
654}
655
656/**
657 * Decode unit that takes in a single CtrlFlow and generates a CfCtrl.
658 */
659class DecodeUnit(implicit p: Parameters) extends XSModule with DecodeUnitConstants {
660  val io = IO(new DecodeUnitIO)
661
662  val ctrl_flow = io.enq.ctrlFlow // input with RVC Expanded
663
664  private val inst: XSInstBitFields = io.enq.ctrlFlow.instr.asTypeOf(new XSInstBitFields)
665
666  val decode_table: Array[(BitPat, List[BitPat])] = XDecode.table ++
667    FpDecode.table ++
668//    FDivSqrtDecode.table ++
669    X64Decode.table ++
670    XSTrapDecode.table ++
671    BDecode.table ++
672    CBODecode.table ++
673    SvinvalDecode.table ++
674    HypervisorDecode.table ++
675    VecDecoder.table
676
677  require(decode_table.map(_._2.length == 15).reduce(_ && _), "Decode tables have different column size")
678  // assertion for LUI: only LUI should be assigned `selImm === SelImm.IMM_U && fuType === FuType.alu`
679  val luiMatch = (t: Seq[BitPat]) => t(3).value == FuType.alu.ohid && t.reverse.head.value == SelImm.IMM_U.litValue
680  val luiTable = decode_table.filter(t => luiMatch(t._2)).map(_._1).distinct
681  assert(luiTable.length == 1 && luiTable.head == LUI, "Conflicts: LUI is determined by FuType and SelImm in Dispatch")
682
683  // output
684  val decodedInst: DecodedInst = Wire(new DecodedInst()).decode(ctrl_flow.instr, decode_table)
685
686  val fpDecoder = Module(new FPDecoder)
687  fpDecoder.io.instr := ctrl_flow.instr
688  decodedInst.fpu := fpDecoder.io.fpCtrl
689
690  decodedInst.connectStaticInst(io.enq.ctrlFlow)
691
692  decodedInst.uopIdx := 0.U
693  decodedInst.firstUop := true.B
694  decodedInst.lastUop := true.B
695  decodedInst.numUops := 1.U
696  decodedInst.numWB   := 1.U
697
698  val isMove = BitPat("b000000000000_?????_000_?????_0010011") === ctrl_flow.instr
699  decodedInst.isMove := isMove && ctrl_flow.instr(RD_MSB, RD_LSB) =/= 0.U && !io.csrCtrl.singlestep
700
701  // fmadd - b1000011
702  // fmsub - b1000111
703  // fnmsub- b1001011
704  // fnmadd- b1001111
705  private val isFMA = inst.OPCODE === BitPat("b100??11")
706
707  private val v0Idx = 0
708  private val vconfigIdx = VCONFIG_IDX
709
710  // read src1~3 location
711  decodedInst.lsrc(0) := inst.RS1
712  decodedInst.lsrc(1) := inst.RS2
713  // src(2) of fma is fs3, src(2) of vector inst is old vd
714  decodedInst.lsrc(2) := Mux(isFMA, inst.FS3, inst.VD)
715  decodedInst.lsrc(3) := v0Idx.U
716  decodedInst.lsrc(4) := vconfigIdx.U
717
718  // read dest location
719  decodedInst.ldest := inst.RD
720
721  // fill in exception vector
722  val vecException = Module(new VecExceptionGen)
723  vecException.io.inst := io.enq.ctrlFlow.instr
724  vecException.io.decodedInst := decodedInst
725  vecException.io.vtype := decodedInst.vpu.vtype
726  decodedInst.exceptionVec(illegalInstr) := decodedInst.selImm === SelImm.INVALID_INSTR || vecException.io.illegalInst
727
728  when (!io.csrCtrl.svinval_enable) {
729    val base_ii = decodedInst.selImm === SelImm.INVALID_INSTR || vecException.io.illegalInst
730    val sinval = BitPat("b0001011_?????_?????_000_00000_1110011") === ctrl_flow.instr
731    val w_inval = BitPat("b0001100_00000_00000_000_00000_1110011") === ctrl_flow.instr
732    val inval_ir = BitPat("b0001100_00001_00000_000_00000_1110011") === ctrl_flow.instr
733    val hinval_gvma = HINVAL_GVMA === ctrl_flow.instr
734    val hinval_vvma = HINVAL_VVMA === ctrl_flow.instr
735    val svinval_ii = sinval || w_inval || inval_ir || hinval_gvma || hinval_vvma
736    decodedInst.exceptionVec(illegalInstr) := base_ii || svinval_ii
737    decodedInst.flushPipe := false.B
738  }
739
740  when(io.csrCtrl.virtMode){
741    // Todo: optimize EX_VI decode
742    // vs/vu attempting to exec hyperinst will raise virtual instruction
743    decodedInst.exceptionVec(virtualInstr) := ctrl_flow.instr === HLV_B || ctrl_flow.instr === HLV_BU ||
744      ctrl_flow.instr === HLV_H   || ctrl_flow.instr === HLV_HU ||
745      ctrl_flow.instr === HLVX_HU || ctrl_flow.instr === HLV_W  ||
746      ctrl_flow.instr === HLVX_WU || ctrl_flow.instr === HLV_WU ||
747      ctrl_flow.instr === HLV_D   || ctrl_flow.instr === HSV_B  ||
748      ctrl_flow.instr === HSV_H   || ctrl_flow.instr === HSV_W  ||
749      ctrl_flow.instr === HSV_D   || ctrl_flow.instr === HFENCE_VVMA ||
750      ctrl_flow.instr === HFENCE_GVMA || ctrl_flow.instr === HINVAL_GVMA ||
751      ctrl_flow.instr === HINVAL_VVMA
752  }
753
754  // fix frflags
755  //                           fflags    zero csrrs rd    csr
756  val isFrflags = BitPat("b000000000001_00000_010_?????_1110011") === ctrl_flow.instr
757  when (decodedInst.fuType === FuType.csr.U && isFrflags) {
758    decodedInst.blockBackward := false.B
759  }
760
761  decodedInst.imm := LookupTree(decodedInst.selImm, ImmUnion.immSelMap.map(
762    x => {
763      val minBits = x._2.minBitsFromInstr(ctrl_flow.instr)
764      require(minBits.getWidth == x._2.len)
765      x._1 -> minBits
766    }
767  ))
768
769  private val isLs = FuType.isLoadStore(decodedInst.fuType)
770  private val isVls = FuType.isVls(decodedInst.fuType)
771  private val isStore = FuType.isStore(decodedInst.fuType)
772  private val isAMO = FuType.isAMO(decodedInst.fuType)
773  private val isVStore = FuType.isVStore(decodedInst.fuType)
774  private val isBranch = !decodedInst.preDecodeInfo.notCFI || FuType.isJump(decodedInst.fuType)
775
776  decodedInst.commitType := Cat(isLs | isVls, (isStore && !isAMO) | isVStore | isBranch)
777
778  decodedInst.isVset := FuType.isVset(decodedInst.fuType)
779
780  private val needReverseInsts = Seq(VRSUB_VI, VRSUB_VX, VFRDIV_VF, VFRSUB_VF, VFMV_F_S)
781  private val vextInsts = Seq(VZEXT_VF2, VZEXT_VF4, VZEXT_VF8, VSEXT_VF2, VSEXT_VF4, VSEXT_VF8)
782  private val narrowInsts = Seq(
783    VNSRA_WV, VNSRA_WX, VNSRA_WI, VNSRL_WV, VNSRL_WX, VNSRL_WI,
784    VNCLIP_WV, VNCLIP_WX, VNCLIP_WI, VNCLIPU_WV, VNCLIPU_WX, VNCLIPU_WI,
785  )
786  private val maskDstInsts = Seq(
787    VMADC_VV, VMADC_VX,  VMADC_VI,  VMADC_VVM, VMADC_VXM, VMADC_VIM,
788    VMSBC_VV, VMSBC_VX,  VMSBC_VVM, VMSBC_VXM,
789    VMAND_MM, VMNAND_MM, VMANDN_MM, VMXOR_MM, VMOR_MM, VMNOR_MM, VMORN_MM, VMXNOR_MM,
790    VMSEQ_VV, VMSEQ_VX, VMSEQ_VI, VMSNE_VV, VMSNE_VX, VMSNE_VI,
791    VMSLE_VV, VMSLE_VX, VMSLE_VI, VMSLEU_VV, VMSLEU_VX, VMSLEU_VI,
792    VMSLT_VV, VMSLT_VX, VMSLTU_VV, VMSLTU_VX,
793    VMSGT_VX, VMSGT_VI, VMSGTU_VX, VMSGTU_VI,
794    VMFEQ_VV, VMFEQ_VF, VMFNE_VV, VMFNE_VF, VMFLT_VV, VMFLT_VF, VMFLE_VV, VMFLE_VF, VMFGT_VF, VMFGE_VF,
795  )
796  private val maskOpInsts = Seq(
797    VMAND_MM, VMNAND_MM, VMANDN_MM, VMXOR_MM, VMOR_MM, VMNOR_MM, VMORN_MM, VMXNOR_MM,
798  )
799  private val wfflagsInsts = Seq(
800    // opfff
801    FADD_S, FSUB_S, FADD_D, FSUB_D,
802    FEQ_S, FLT_S, FLE_S, FEQ_D, FLT_D, FLE_D,
803    FMIN_S, FMAX_S, FMIN_D, FMAX_D,
804    FMUL_S, FMUL_D,
805    FDIV_S, FDIV_D, FSQRT_S, FSQRT_D,
806    FMADD_S, FMSUB_S, FNMADD_S, FNMSUB_S, FMADD_D, FMSUB_D, FNMADD_D, FNMSUB_D,
807    FSGNJ_S, FSGNJN_S, FSGNJX_S,
808    // opfvv
809    VFADD_VV, VFSUB_VV, VFWADD_VV, VFWSUB_VV, VFWADD_WV, VFWSUB_WV,
810    VFMUL_VV, VFDIV_VV, VFWMUL_VV,
811    VFMACC_VV, VFNMACC_VV, VFMSAC_VV, VFNMSAC_VV, VFMADD_VV, VFNMADD_VV, VFMSUB_VV, VFNMSUB_VV,
812    VFWMACC_VV, VFWNMACC_VV, VFWMSAC_VV, VFWNMSAC_VV,
813    VFSQRT_V,
814    VFMIN_VV, VFMAX_VV,
815    VMFEQ_VV, VMFNE_VV, VMFLT_VV, VMFLE_VV,
816    VFSGNJ_VV, VFSGNJN_VV, VFSGNJX_VV,
817    // opfvf
818    VFADD_VF, VFSUB_VF, VFRSUB_VF, VFWADD_VF, VFWSUB_VF, VFWADD_WF, VFWSUB_WF,
819    VFMUL_VF, VFDIV_VF, VFRDIV_VF, VFWMUL_VF,
820    VFMACC_VF, VFNMACC_VF, VFMSAC_VF, VFNMSAC_VF, VFMADD_VF, VFNMADD_VF, VFMSUB_VF, VFNMSUB_VF,
821    VFWMACC_VF, VFWNMACC_VF, VFWMSAC_VF, VFWNMSAC_VF,
822    VFMIN_VF, VFMAX_VF,
823    VMFEQ_VF, VMFNE_VF, VMFLT_VF, VMFLE_VF, VMFGT_VF, VMFGE_VF,
824    VFSGNJ_VF, VFSGNJN_VF, VFSGNJX_VF,
825    // fcvt & vfcvt
826    FCVT_S_W, FCVT_S_WU, FCVT_S_L, FCVT_S_LU,
827    FCVT_W_S, FCVT_WU_S, FCVT_L_S, FCVT_LU_S,
828    FCVT_D_W, FCVT_D_WU, FCVT_D_L, FCVT_D_LU,
829    FCVT_W_D, FCVT_WU_D, FCVT_L_D, FCVT_LU_D, FCVT_S_D, FCVT_D_S,
830    VFCVT_XU_F_V, VFCVT_X_F_V, VFCVT_RTZ_XU_F_V, VFCVT_RTZ_X_F_V, VFCVT_F_XU_V, VFCVT_F_X_V,
831    VFWCVT_XU_F_V, VFWCVT_X_F_V, VFWCVT_RTZ_XU_F_V, VFWCVT_RTZ_X_F_V, VFWCVT_F_XU_V, VFWCVT_F_X_V, VFWCVT_F_F_V,
832    VFNCVT_XU_F_W, VFNCVT_X_F_W, VFNCVT_RTZ_XU_F_W, VFNCVT_RTZ_X_F_W, VFNCVT_F_XU_W, VFNCVT_F_X_W, VFNCVT_F_F_W,
833    VFNCVT_ROD_F_F_W, VFRSQRT7_V, VFREC7_V,
834  )
835  decodedInst.wfflags := wfflagsInsts.map(_ === inst.ALL).reduce(_ || _)
836  val fpToVecDecoder = Module(new FPToVecDecoder())
837  fpToVecDecoder.io.instr := inst.asUInt
838  val isFpToVecInst = fpToVecDecoder.io.vpuCtrl.fpu.isFpToVecInst
839  decodedInst.vpu := 0.U.asTypeOf(decodedInst.vpu) // Todo: Connect vpu decoder
840  when(isFpToVecInst){
841    decodedInst.vpu := fpToVecDecoder.io.vpuCtrl
842  }.otherwise{
843    decodedInst.vpu.vill := io.enq.vtype.illegal
844    decodedInst.vpu.vma := io.enq.vtype.vma
845    decodedInst.vpu.vta := io.enq.vtype.vta
846    decodedInst.vpu.vsew := io.enq.vtype.vsew
847    decodedInst.vpu.vlmul := io.enq.vtype.vlmul
848    decodedInst.vpu.vm := inst.VM
849    decodedInst.vpu.nf := inst.NF
850    decodedInst.vpu.veew := inst.WIDTH
851    decodedInst.vpu.isReverse := needReverseInsts.map(_ === inst.ALL).reduce(_ || _)
852    decodedInst.vpu.isExt := vextInsts.map(_ === inst.ALL).reduce(_ || _)
853    decodedInst.vpu.isNarrow := narrowInsts.map(_ === inst.ALL).reduce(_ || _)
854    decodedInst.vpu.isDstMask := maskDstInsts.map(_ === inst.ALL).reduce(_ || _)
855    decodedInst.vpu.isOpMask := maskOpInsts.map(_ === inst.ALL).reduce(_ || _)
856  }
857
858  decodedInst.vlsInstr := isVls
859
860  decodedInst.srcType(3) := Mux(inst.VM === 0.U && !isFpToVecInst, SrcType.vp, SrcType.DC) // mask src
861  decodedInst.srcType(4) := Mux(!isFpToVecInst, SrcType.vp, SrcType.DC) // vconfig
862
863  val uopInfoGen = Module(new UopInfoGen)
864  uopInfoGen.io.in.preInfo.typeOfSplit := decodedInst.uopSplitType
865  uopInfoGen.io.in.preInfo.vsew := decodedInst.vpu.vsew
866  uopInfoGen.io.in.preInfo.vlmul := decodedInst.vpu.vlmul
867  uopInfoGen.io.in.preInfo.vwidth := inst.RM
868  uopInfoGen.io.in.preInfo.vmvn := inst.IMM5_OPIVI(2, 0)
869  uopInfoGen.io.in.preInfo.nf := inst.NF
870  uopInfoGen.io.in.preInfo.isVlsr := decodedInst.fuOpType === VlduType.vlr || decodedInst.fuOpType === VstuType.vsr
871  uopInfoGen.io.in.preInfo.isVlsm := decodedInst.fuOpType === VlduType.vlm || decodedInst.fuOpType === VstuType.vsm
872  io.deq.isComplex := uopInfoGen.io.out.isComplex
873  io.deq.uopInfo.numOfUop := uopInfoGen.io.out.uopInfo.numOfUop
874  io.deq.uopInfo.numOfWB := uopInfoGen.io.out.uopInfo.numOfWB
875  io.deq.uopInfo.lmul := uopInfoGen.io.out.uopInfo.lmul
876
877  io.deq.decodedInst := decodedInst
878  io.deq.decodedInst.rfWen := (decodedInst.ldest =/= 0.U) && decodedInst.rfWen
879  //-------------------------------------------------------------
880  // Debug Info
881//  XSDebug("in:  instr=%x pc=%x excepVec=%b crossPageIPFFix=%d\n",
882//    io.enq.ctrl_flow.instr, io.enq.ctrl_flow.pc, io.enq.ctrl_flow.exceptionVec.asUInt,
883//    io.enq.ctrl_flow.crossPageIPFFix)
884//  XSDebug("out: srcType(0)=%b srcType(1)=%b srcType(2)=%b lsrc(0)=%d lsrc(1)=%d lsrc(2)=%d ldest=%d fuType=%b fuOpType=%b\n",
885//    io.deq.cf_ctrl.ctrl.srcType(0), io.deq.cf_ctrl.ctrl.srcType(1), io.deq.cf_ctrl.ctrl.srcType(2),
886//    io.deq.cf_ctrl.ctrl.lsrc(0), io.deq.cf_ctrl.ctrl.lsrc(1), io.deq.cf_ctrl.ctrl.lsrc(2),
887//    io.deq.cf_ctrl.ctrl.ldest, io.deq.cf_ctrl.ctrl.fuType, io.deq.cf_ctrl.ctrl.fuOpType)
888//  XSDebug("out: rfWen=%d fpWen=%d isXSTrap=%d noSpecExec=%d isBlocked=%d flushPipe=%d imm=%x\n",
889//    io.deq.cf_ctrl.ctrl.rfWen, io.deq.cf_ctrl.ctrl.fpWen, io.deq.cf_ctrl.ctrl.isXSTrap,
890//    io.deq.cf_ctrl.ctrl.noSpecExec, io.deq.cf_ctrl.ctrl.blockBackward, io.deq.cf_ctrl.ctrl.flushPipe,
891//    io.deq.cf_ctrl.ctrl.imm)
892//  XSDebug("out: excepVec=%b\n", io.deq.cf_ctrl.cf.exceptionVec.asUInt)
893}
894