1package xiangshan.backend 2 3import chipsalliance.rocketchip.config.Parameters 4import chisel3._ 5import chisel3.util.BitPat.bitPatToUInt 6import chisel3.util._ 7import utils.OptionWrapper 8import xiangshan._ 9import xiangshan.backend.datapath.DataConfig._ 10import xiangshan.backend.datapath.DataSource 11import xiangshan.backend.datapath.WbConfig.WbConfig 12import xiangshan.backend.decode.{ImmUnion, XDecode} 13import xiangshan.backend.exu.ExeUnitParams 14import xiangshan.backend.fu.FuType 15import xiangshan.backend.fu.fpu.Bundles.Frm 16import xiangshan.backend.fu.vector.Bundles.{Category, Nf, VConfig, VLmul, VSew, VType, Vl, Vxrm} 17import xiangshan.backend.issue.{IssueBlockParams, IssueQueueDeqRespBundle, IssueQueueJumpBundle, SchedulerType, StatusArrayDeqRespBundle} 18import xiangshan.backend.regfile.{RfReadPortWithConfig, RfWritePortWithConfig} 19import xiangshan.backend.rob.RobPtr 20import xiangshan.frontend._ 21import xiangshan.mem.{LqPtr, SqPtr} 22 23object Bundles { 24 25 // frontend -> backend 26 class StaticInst(implicit p: Parameters) extends XSBundle { 27 val instr = UInt(32.W) 28 val pc = UInt(VAddrBits.W) 29 val foldpc = UInt(MemPredPCWidth.W) 30 val exceptionVec = ExceptionVec() 31 val trigger = new TriggerCf 32 val preDecodeInfo = new PreDecodeInfo 33 val pred_taken = Bool() 34 val crossPageIPFFix = Bool() 35 val ftqPtr = new FtqPtr 36 val ftqOffset = UInt(log2Up(PredictWidth).W) 37 38 def connectCtrlFlow(source: CtrlFlow): Unit = { 39 this.instr := source.instr 40 this.pc := source.pc 41 this.foldpc := source.foldpc 42 this.exceptionVec := source.exceptionVec 43 this.trigger := source.trigger 44 this.preDecodeInfo := source.pd 45 this.pred_taken := source.pred_taken 46 this.crossPageIPFFix := source.crossPageIPFFix 47 this.ftqPtr := source.ftqPtr 48 this.ftqOffset := source.ftqOffset 49 } 50 } 51 52 // StaticInst --[Decode]--> DecodedInst 53 class DecodedInst(implicit p: Parameters) extends XSBundle { 54 def numSrc = backendParams.numSrc 55 // passed from StaticInst 56 val instr = UInt(32.W) 57 val pc = UInt(VAddrBits.W) 58 val foldpc = UInt(MemPredPCWidth.W) 59 val exceptionVec = ExceptionVec() 60 val trigger = new TriggerCf 61 val preDecodeInfo = new PreDecodeInfo 62 val pred_taken = Bool() 63 val crossPageIPFFix = Bool() 64 val ftqPtr = new FtqPtr 65 val ftqOffset = UInt(log2Up(PredictWidth).W) 66 // decoded 67 val srcType = Vec(numSrc, SrcType()) 68 val lsrc = Vec(numSrc, UInt(6.W)) 69 val ldest = UInt(6.W) 70 val fuType = FuType() 71 val fuOpType = FuOpType() 72 val rfWen = Bool() 73 val fpWen = Bool() 74 val vecWen = Bool() 75 val isXSTrap = Bool() 76 val waitForward = Bool() // no speculate execution 77 val blockBackward = Bool() 78 val flushPipe = Bool() // This inst will flush all the pipe when commit, like exception but can commit 79 val selImm = SelImm() 80 val imm = UInt(ImmUnion.maxLen.W) 81 val fpu = new FPUCtrlSignals 82 val vpu = new VPUCtrlSignals 83 val isMove = Bool() 84 val uopIdx = UInt(5.W) 85 val uopSplitType = UopSplitType() 86 val isVset = Bool() 87 val firstUop = Bool() 88 val lastUop = Bool() 89 val numUops = UInt(log2Up(MaxUopSize).W) // rob need this 90 val commitType = CommitType() // Todo: remove it 91 92 private def allSignals = srcType.take(3) ++ Seq(fuType, fuOpType, rfWen, fpWen, vecWen, 93 isXSTrap, waitForward, blockBackward, flushPipe, uopSplitType, selImm) 94 95 def decode(inst: UInt, table: Iterable[(BitPat, List[BitPat])]): DecodedInst = { 96 val decoder: Seq[UInt] = ListLookup( 97 inst, XDecode.decodeDefault.map(bitPatToUInt), 98 table.map{ case (pat, pats) => (pat, pats.map(bitPatToUInt)) }.toArray 99 ) 100 allSignals zip decoder foreach { case (s, d) => s := d } 101 this 102 } 103 104 def isSoftPrefetch: Bool = { 105 fuType === FuType.alu.U && fuOpType === ALUOpType.or && selImm === SelImm.IMM_I && ldest === 0.U 106 } 107 108 def connectStaticInst(source: StaticInst): Unit = { 109 for ((name, data) <- this.elements) { 110 if (source.elements.contains(name)) { 111 data := source.elements(name) 112 } 113 } 114 } 115 } 116 117 // DecodedInst --[Rename]--> DynInst 118 class DynInst(implicit p: Parameters) extends XSBundle { 119 def numSrc = backendParams.numSrc 120 // passed from StaticInst 121 val instr = UInt(32.W) 122 val pc = UInt(VAddrBits.W) 123 val foldpc = UInt(MemPredPCWidth.W) 124 val exceptionVec = ExceptionVec() 125 val trigger = new TriggerCf 126 val preDecodeInfo = new PreDecodeInfo 127 val pred_taken = Bool() 128 val crossPageIPFFix = Bool() 129 val ftqPtr = new FtqPtr 130 val ftqOffset = UInt(log2Up(PredictWidth).W) 131 // passed from DecodedInst 132 val srcType = Vec(numSrc, SrcType()) 133 val lsrc = Vec(numSrc, UInt(6.W)) 134 val ldest = UInt(6.W) 135 val fuType = FuType() 136 val fuOpType = FuOpType() 137 val rfWen = Bool() 138 val fpWen = Bool() 139 val vecWen = Bool() 140 val isXSTrap = Bool() 141 val waitForward = Bool() // no speculate execution 142 val blockBackward = Bool() 143 val flushPipe = Bool() // This inst will flush all the pipe when commit, like exception but can commit 144 val selImm = SelImm() 145 val imm = UInt(XLEN.W) // Todo: check if it need minimized 146 val fpu = new FPUCtrlSignals 147 val vpu = new VPUCtrlSignals 148 val isMove = Bool() 149 val uopIdx = UInt(5.W) 150 val isVset = Bool() 151 val firstUop = Bool() 152 val lastUop = Bool() 153 val numUops = UInt(log2Up(MaxUopSize).W) // rob need this 154 val commitType = CommitType() 155 // rename 156 val srcState = Vec(numSrc, SrcState()) 157 val psrc = Vec(numSrc, UInt(PhyRegIdxWidth.W)) 158 val pdest = UInt(PhyRegIdxWidth.W) 159 val oldPdest = UInt(PhyRegIdxWidth.W) 160 val robIdx = new RobPtr 161 162 val eliminatedMove = Bool() 163 val debugInfo = new PerfDebugInfo 164 val storeSetHit = Bool() // inst has been allocated an store set 165 val waitForRobIdx = new RobPtr // store set predicted previous store robIdx 166 // Load wait is needed 167 // load inst will not be executed until former store (predicted by mdp) addr calcuated 168 val loadWaitBit = Bool() 169 // If (loadWaitBit && loadWaitStrict), strict load wait is needed 170 // load inst will not be executed until ALL former store addr calcuated 171 val loadWaitStrict = Bool() 172 val ssid = UInt(SSIDWidth.W) 173 // Todo 174 val lqIdx = new LqPtr 175 val sqIdx = new SqPtr 176 // debug module 177 val singleStep = Bool() 178 // schedule 179 val replayInst = Bool() 180 181 def isLUI: Bool = this.fuType === FuType.alu.U && this.selImm === SelImm.IMM_U 182 def isWFI: Bool = this.fuType === FuType.csr.U && fuOpType === CSROpType.wfi 183 184 def isSvinvalBegin(flush: Bool) = FuType.isFence(fuType) && fuOpType === FenceOpType.nofence && !flush 185 def isSvinval(flush: Bool) = FuType.isFence(fuType) && fuOpType === FenceOpType.sfence && !flush 186 def isSvinvalEnd(flush: Bool) = FuType.isFence(fuType) && fuOpType === FenceOpType.nofence && flush 187 188 def srcIsReady: Vec[Bool] = { 189 VecInit(this.srcType.zip(this.srcState).map { 190 case (t, s) => SrcType.isNotReg(t) || SrcState.isReady(s) 191 }) 192 } 193 194 def clearExceptions( 195 exceptionBits: Seq[Int] = Seq(), 196 flushPipe : Boolean = false, 197 replayInst : Boolean = false 198 ): DynInst = { 199 this.exceptionVec.zipWithIndex.filterNot(x => exceptionBits.contains(x._2)).foreach(_._1 := false.B) 200 if (!flushPipe) { this.flushPipe := false.B } 201 if (!replayInst) { this.replayInst := false.B } 202 this 203 } 204 205 def needWriteRf: Bool = (rfWen && ldest =/= 0.U) || fpWen || vecWen 206 } 207 208 trait BundleSource { 209 var wakeupSource = "undefined" 210 var idx = 0 211 } 212 213 /** 214 * 215 * @param pregIdxWidth index width of preg 216 * @param exuIndices exu indices of wakeup bundle 217 */ 218 sealed abstract class IssueQueueWakeUpBaseBundle(pregIdxWidth: Int, val exuIndices: Seq[Int]) extends Bundle { 219 val rfWen = Bool() 220 val fpWen = Bool() 221 val vecWen = Bool() 222 val pdest = UInt(pregIdxWidth.W) 223 224 /** 225 * @param successor Seq[(psrc, srcType)] 226 * @return Seq[if wakeup psrc] 227 */ 228 def wakeUp(successor: Seq[(UInt, UInt)], valid: Bool): Seq[Bool] = { 229 successor.map { case (thatPsrc, srcType) => 230 val pdestMatch = pdest === thatPsrc 231 pdestMatch && ( 232 SrcType.isFp(srcType) && this.fpWen || 233 SrcType.isXp(srcType) && this.rfWen || 234 SrcType.isVp(srcType) && this.vecWen 235 ) && valid 236 } 237 } 238 239 def hasOnlyOneSource: Boolean = exuIndices.size == 1 240 241 def hasMultiSources: Boolean = exuIndices.size > 1 242 243 def isWBWakeUp = this.isInstanceOf[IssueQueueWBWakeUpBundle] 244 245 def isIQWakeUp = this.isInstanceOf[IssueQueueIQWakeUpBundle] 246 247 def exuIdx: Int = { 248 require(hasOnlyOneSource) 249 this.exuIndices.head 250 } 251 } 252 253 class IssueQueueWBWakeUpBundle(exuIndices: Seq[Int], backendParams: BackendParams) extends IssueQueueWakeUpBaseBundle(backendParams.pregIdxWidth, exuIndices) { 254 255 } 256 257 class IssueQueueIQWakeUpBundle(exuIdx: Int, backendParams: BackendParams) extends IssueQueueWakeUpBaseBundle(backendParams.pregIdxWidth, Seq(exuIdx)) { 258 val l2ExuVec: Vec[Bool] = ExuVec(backendParams.numExu) 259 260 def fromExuInput(exuInput: ExuInput, l2ExuVecs: Vec[Vec[Bool]]): Unit = { 261 this.rfWen := exuInput.rfWen.getOrElse(false.B) 262 this.fpWen := exuInput.fpWen.getOrElse(false.B) 263 this.vecWen := exuInput.vecWen.getOrElse(false.B) 264 this.pdest := exuInput.pdest 265 this.l2ExuVec := l2ExuVecs.reduce { (x: Vec[Bool], y: Vec[Bool]) => VecInit((x.asUInt | y.asUInt).asBools) } 266 } 267 } 268 269 /** 270 * This bundle is used to set srcState as NotReady. 271 * @param cancelSeq cancel stage seq 272 */ 273 class IssueQueueCancelBundle(val exuIdx: Int, cancelSeq: Seq[String]) extends Bundle { 274 val cancelVec: Vec[Bool] = Vec(cancelSeq.size, Bool()) 275 276 def apply(cancelStage: String): Bool = { 277 this.cancelVec(cancelSeq.indexOf(cancelStage.toUpperCase)) 278 } 279 } 280 281 class VPUCtrlSignals(implicit p: Parameters) extends XSBundle { 282 // vtype 283 val vill = Bool() 284 val vma = Bool() // 1: agnostic, 0: undisturbed 285 val vta = Bool() // 1: agnostic, 0: undisturbed 286 val vsew = VSew() 287 val vlmul = VLmul() // 1/8~8 --> -3~3 288 289 val vm = Bool() // 0: need v0.t 290 val vstart = Vl() 291 292 // float rounding mode 293 val frm = Frm() 294 // vector fix int rounding mode 295 val vxrm = Vxrm() 296 // vector uop index, exclude other non-vector uop 297 val vuopIdx = UopIdx() 298 // maybe used if data dependancy 299 val vmask = UInt(MaskSrcData().dataWidth.W) 300 val vl = Vl() 301 302 // vector load/store 303 val nf = Nf() 304 305 val needScalaSrc = Bool() 306 val permImmTruncate = Bool() // opivi 307 308 val isReverse = Bool() // vrsub, vrdiv 309 val isExt = Bool() 310 val isNarrow = Bool() 311 val isDstMask = Bool() // vvm, vvvm, mmm 312 val isMove = Bool() // vmv.s.x, vmv.v.v, vmv.v.x, vmv.v.i 313 314 def vtype: VType = { 315 val res = Wire(VType()) 316 res.illegal := this.vill 317 res.vma := this.vma 318 res.vta := this.vta 319 res.vsew := this.vsew 320 res.vlmul := this.vlmul 321 res 322 } 323 324 def vconfig: VConfig = { 325 val res = Wire(VConfig()) 326 res.vtype := this.vtype 327 res.vl := this.vl 328 res 329 } 330 } 331 332 // DynInst --[IssueQueue]--> DataPath 333 class IssueQueueIssueBundle( 334 iqParams: IssueBlockParams, 335 exuParams: ExeUnitParams, 336 addrWidth: Int, 337 vaddrBits: Int 338 )(implicit 339 p: Parameters 340 ) extends Bundle { 341 private val rfReadDataCfgSet: Seq[Set[DataConfig]] = exuParams.getRfReadDataCfgSet 342 343 val rf: MixedVec[MixedVec[RfReadPortWithConfig]] = Flipped(MixedVec( 344 rfReadDataCfgSet.map((set: Set[DataConfig]) => 345 MixedVec(set.map((x: DataConfig) => new RfReadPortWithConfig(x, addrWidth)).toSeq) 346 ) 347 )) 348 349 val srcType = Vec(exuParams.numRegSrc, SrcType()) // used to select imm or reg data 350 val immType = SelImm() // used to select imm extractor 351 val common = new ExuInput(exuParams) 352 val jmp = if (exuParams.needPc) Some(Flipped(new IssueQueueJumpBundle)) else None 353 val addrOH = UInt(iqParams.numEntries.W) 354 355 def exuIdx = exuParams.exuIdx 356 def getSource: SchedulerType = exuParams.getWBSource 357 def getIntWbBusyBundle = common.rfWen.toSeq 358 def getVfWbBusyBundle = common.getVfWen.toSeq 359 def getIntRfReadBundle: Seq[RfReadPortWithConfig] = rf.flatten.filter(_.readInt) 360 def getVfRfReadBundle: Seq[RfReadPortWithConfig] = rf.flatten.filter(_.readVf) 361 } 362 363 class OGRespBundle(implicit p:Parameters, params: IssueBlockParams) extends XSBundle { 364 val issueQueueParams = this.params 365 val og0resp = Valid(new StatusArrayDeqRespBundle) 366 val og1resp = Valid(new StatusArrayDeqRespBundle) 367 } 368 369 class fuBusyRespBundle(implicit p: Parameters, params: IssueBlockParams) extends Bundle { 370 val respType = RSFeedbackType() // update credit if needs replay 371 val rfWen = Bool() // TODO: use params to identify IntWB/VfWB 372 val fuType = FuType() 373 } 374 375 class WbFuBusyTableWriteBundle(val params: ExeUnitParams)(implicit p: Parameters) extends XSBundle { 376 private val intCertainLat = params.intLatencyCertain 377 private val vfCertainLat = params.vfLatencyCertain 378 private val intLat = params.intLatencyValMax 379 private val vfLat = params.vfLatencyValMax 380 381 val intWbBusyTable = OptionWrapper(intCertainLat, UInt((intLat + 1).W)) 382 val vfWbBusyTable = OptionWrapper(vfCertainLat, UInt((vfLat + 1).W)) 383 val intDeqRespSet = OptionWrapper(intCertainLat, UInt((intLat + 1).W)) 384 val vfDeqRespSet = OptionWrapper(vfCertainLat, UInt((vfLat + 1).W)) 385 } 386 387 class WbFuBusyTableReadBundle(val params: ExeUnitParams)(implicit p: Parameters) extends XSBundle { 388 private val intCertainLat = params.intLatencyCertain 389 private val vfCertainLat = params.vfLatencyCertain 390 private val intLat = params.intLatencyValMax 391 private val vfLat = params.vfLatencyValMax 392 393 val intWbBusyTable = OptionWrapper(intCertainLat, UInt((intLat + 1).W)) 394 val vfWbBusyTable = OptionWrapper(vfCertainLat, UInt((vfLat + 1).W)) 395 } 396 397 class WbConflictBundle(val params: ExeUnitParams)(implicit p: Parameters) extends XSBundle { 398 private val intCertainLat = params.intLatencyCertain 399 private val vfCertainLat = params.vfLatencyCertain 400 401 val intConflict = OptionWrapper(intCertainLat, Bool()) 402 val vfConflict = OptionWrapper(vfCertainLat, Bool()) 403 } 404 405 // DataPath --[ExuInput]--> Exu 406 class ExuInput(val params: ExeUnitParams)(implicit p: Parameters) extends XSBundle { 407 val fuType = FuType() 408 val fuOpType = FuOpType() 409 val src = Vec(params.numRegSrc, UInt(params.dataBitsMax.W)) 410 val imm = UInt(XLEN.W) 411 val robIdx = new RobPtr 412 val iqIdx = UInt(log2Up(MemIQSizeMax).W)// Only used by store yet 413 val isFirstIssue = Bool() // Only used by store yet 414 val pdest = UInt(params.wbPregIdxWidth.W) 415 val rfWen = if (params.writeIntRf) Some(Bool()) else None 416 val fpWen = if (params.writeFpRf) Some(Bool()) else None 417 val vecWen = if (params.writeVecRf) Some(Bool()) else None 418 val fpu = if (params.needFPUCtrl) Some(new FPUCtrlSignals) else None 419 val vpu = if (params.needVPUCtrl) Some(new VPUCtrlSignals) else None 420 val flushPipe = if (params.flushPipe) Some(Bool()) else None 421 val pc = if (params.needPc) Some(UInt(VAddrData().dataWidth.W)) else None 422 val jalrTarget = if (params.hasJmpFu) Some(UInt(VAddrData().dataWidth.W)) else None 423 val preDecode = if (params.hasPredecode) Some(new PreDecodeInfo) else None 424 val ftqIdx = if (params.needPc || params.replayInst) 425 Some(new FtqPtr) else None 426 val ftqOffset = if (params.needPc || params.replayInst) 427 Some(UInt(log2Up(PredictWidth).W)) else None 428 val predictInfo = if (params.hasPredecode) Some(new Bundle { 429 val target = UInt(VAddrData().dataWidth.W) 430 val taken = Bool() 431 }) else None 432 val sqIdx = if (params.hasMemAddrFu || params.hasStdFu) Some(new SqPtr) else None 433 val lqIdx = if (params.hasMemAddrFu) Some(new LqPtr) else None 434 val dataSources = Vec(params.numRegSrc, DataSource()) 435 val l1ExuVec = OptionWrapper(params.isIQWakeUpSink, Vec(params.numRegSrc, ExuVec())) 436 val l2ExuVec = OptionWrapper(params.isIQWakeUpSink, Vec(params.numRegSrc, ExuVec())) 437 438 def exuIdx = this.params.exuIdx 439 440 def needCancel(og0CancelVec: Vec[Bool], og1CancelVec: Vec[Bool]) : Bool = { 441 if (params.isIQWakeUpSink) { 442 require( 443 og0CancelVec.size == l1ExuVec.get.head.size && og1CancelVec.size == l2ExuVec.get.head.size, 444 s"cancelVecSize: {og0: ${og0CancelVec.size}, og1: ${og1CancelVec.size}}" 445 ) 446 val l1Cancel: Bool = l1ExuVec.get.map { x: Vec[Bool] => (x.asUInt & og0CancelVec.asUInt).orR }.reduce(_ | _) 447 val l2Cancel: Bool = l2ExuVec.get.map { x: Vec[Bool] => (x.asUInt & og1CancelVec.asUInt).orR }.reduce(_ | _) 448 l1Cancel | l2Cancel 449 } else { 450 false.B 451 } 452 } 453 454 def getVfWen = { 455 if (params.writeFpRf) this.fpWen 456 else if(params.writeVecRf) this.vecWen 457 else None 458 } 459 460 def fromIssueBundle(source: IssueQueueIssueBundle): Unit = { 461 // src is assigned to rfReadData 462 this.fuType := source.common.fuType 463 this.fuOpType := source.common.fuOpType 464 this.imm := source.common.imm 465 this.robIdx := source.common.robIdx 466 this.pdest := source.common.pdest 467 this.isFirstIssue := source.common.isFirstIssue // Only used by mem debug log 468 this.iqIdx := source.common.iqIdx // Only used by mem feedback 469 this.dataSources := source.common.dataSources 470 this.rfWen .foreach(_ := source.common.rfWen.get) 471 this.fpWen .foreach(_ := source.common.fpWen.get) 472 this.vecWen .foreach(_ := source.common.vecWen.get) 473 this.fpu .foreach(_ := source.common.fpu.get) 474 this.vpu .foreach(_ := source.common.vpu.get) 475 this.flushPipe .foreach(_ := source.common.flushPipe.get) 476 this.pc .foreach(_ := source.jmp.get.pc) 477 this.jalrTarget .foreach(_ := source.jmp.get.target) 478 this.preDecode .foreach(_ := source.common.preDecode.get) 479 this.ftqIdx .foreach(_ := source.common.ftqIdx.get) 480 this.ftqOffset .foreach(_ := source.common.ftqOffset.get) 481 this.predictInfo .foreach(_ := source.common.predictInfo.get) 482 this.lqIdx .foreach(_ := source.common.lqIdx.get) 483 this.sqIdx .foreach(_ := source.common.sqIdx.get) 484 this.l1ExuVec .foreach(_ := source.common.l1ExuVec.get) 485 this.l2ExuVec .foreach(_ := source.common.l2ExuVec.get) 486 } 487 } 488 489 // ExuInput --[FuncUnit]--> ExuOutput 490 class ExuOutput( 491 val params: ExeUnitParams, 492 )(implicit 493 val p: Parameters 494 ) extends Bundle with BundleSource with HasXSParameter { 495 val data = UInt(params.dataBitsMax.W) 496 val pdest = UInt(params.wbPregIdxWidth.W) 497 val robIdx = new RobPtr 498 val intWen = if (params.writeIntRf) Some(Bool()) else None 499 val fpWen = if (params.writeFpRf) Some(Bool()) else None 500 val vecWen = if (params.writeVecRf) Some(Bool()) else None 501 val redirect = if (params.hasRedirect) Some(ValidIO(new Redirect)) else None 502 val fflags = if (params.writeFflags) Some(UInt(5.W)) else None 503 val vxsat = if (params.writeVxsat) Some(Bool()) else None 504 val exceptionVec = if (params.exceptionOut.nonEmpty) Some(ExceptionVec()) else None 505 val flushPipe = if (params.flushPipe) Some(Bool()) else None 506 val replay = if (params.replayInst) Some(Bool()) else None 507 val lqIdx = if (params.hasLoadFu) Some(new LqPtr()) else None 508 val sqIdx = if (params.hasStoreAddrFu || params.hasStdFu) 509 Some(new SqPtr()) else None 510 val ftqIdx = if (params.needPc || params.replayInst) 511 Some(new FtqPtr) else None 512 val ftqOffset = if (params.needPc || params.replayInst) 513 Some(UInt(log2Up(PredictWidth).W)) else None 514 // uop info 515 val predecodeInfo = if(params.hasPredecode) Some(new PreDecodeInfo) else None 516 val debug = new DebugBundle 517 val debugInfo = new PerfDebugInfo 518 } 519 520 // ExuOutput + DynInst --> WriteBackBundle 521 class WriteBackBundle(val params: WbConfig)(implicit p: Parameters) extends Bundle with BundleSource { 522 val rfWen = Bool() 523 val fpWen = Bool() 524 val vecWen = Bool() 525 val pdest = UInt(params.pregIdxWidth.W) 526 val data = UInt(params.dataWidth.W) 527 val robIdx = new RobPtr()(p) 528 val flushPipe = Bool() 529 val replayInst = Bool() 530 val redirect = ValidIO(new Redirect) 531 val fflags = UInt(5.W) 532 val vxsat = Bool() 533 val exceptionVec = ExceptionVec() 534 val debug = new DebugBundle 535 val debugInfo = new PerfDebugInfo 536 537 this.wakeupSource = s"WB(${params.toString})" 538 539 def fromExuOutput(source: ExuOutput) = { 540 this.rfWen := source.intWen.getOrElse(false.B) 541 this.fpWen := source.fpWen.getOrElse(false.B) 542 this.vecWen := source.vecWen.getOrElse(false.B) 543 this.pdest := source.pdest 544 this.data := source.data 545 this.robIdx := source.robIdx 546 this.flushPipe := source.flushPipe.getOrElse(false.B) 547 this.replayInst := source.replay.getOrElse(false.B) 548 this.redirect := source.redirect.getOrElse(0.U.asTypeOf(this.redirect)) 549 this.fflags := source.fflags.getOrElse(0.U.asTypeOf(this.fflags)) 550 this.vxsat := source.vxsat.getOrElse(0.U.asTypeOf(this.vxsat)) 551 this.exceptionVec := source.exceptionVec.getOrElse(0.U.asTypeOf(this.exceptionVec)) 552 this.debug := source.debug 553 this.debugInfo := source.debugInfo 554 } 555 556 def asIntRfWriteBundle(fire: Bool): RfWritePortWithConfig = { 557 val rfWrite = Wire(Output(new RfWritePortWithConfig(this.params.dataCfg, this.params.pregIdxWidth))) 558 rfWrite.wen := this.rfWen && fire 559 rfWrite.addr := this.pdest 560 rfWrite.data := this.data 561 rfWrite.intWen := this.rfWen 562 rfWrite.fpWen := false.B 563 rfWrite.vecWen := false.B 564 rfWrite 565 } 566 567 def asVfRfWriteBundle(fire: Bool): RfWritePortWithConfig = { 568 val rfWrite = Wire(Output(new RfWritePortWithConfig(this.params.dataCfg, this.params.pregIdxWidth))) 569 rfWrite.wen := (this.fpWen || this.vecWen) && fire 570 rfWrite.addr := this.pdest 571 rfWrite.data := this.data 572 rfWrite.intWen := false.B 573 rfWrite.fpWen := this.fpWen 574 rfWrite.vecWen := this.vecWen 575 rfWrite 576 } 577 } 578 579 // ExuOutput --> ExuBypassBundle --[DataPath]-->ExuInput 580 // / 581 // [IssueQueue]--> ExuInput -- 582 class ExuBypassBundle( 583 val params: ExeUnitParams, 584 )(implicit 585 val p: Parameters 586 ) extends Bundle { 587 val data = UInt(params.dataBitsMax.W) 588 val pdest = UInt(params.wbPregIdxWidth.W) 589 } 590 591 class ExceptionInfo extends Bundle { 592 val pc = UInt(VAddrData().dataWidth.W) 593 val instr = UInt(32.W) 594 val commitType = CommitType() 595 val exceptionVec = ExceptionVec() 596 val singleStep = Bool() 597 val crossPageIPFFix = Bool() 598 val isInterrupt = Bool() 599 } 600 601 object UopIdx { 602 def apply()(implicit p: Parameters): UInt = UInt(log2Up(p(XSCoreParamsKey).MaxUopSize + 1).W) 603 } 604 605 object FuLatency { 606 def apply(): UInt = UInt(width.W) 607 608 def width = 4 // 0~15 // Todo: assosiate it with FuConfig 609 } 610 611 object ExuVec { 612 def apply(exuNum: Int): Vec[Bool] = Vec(exuNum, Bool()) 613 614 def apply()(implicit p: Parameters): Vec[Bool] = Vec(width, Bool()) 615 616 def width(implicit p: Parameters): Int = p(XSCoreParamsKey).backendParams.numExu 617 } 618 619 class MemExuInput(isVector: Boolean = false)(implicit p: Parameters) extends XSBundle { 620 val uop = new DynInst 621 val src = if (isVector) Vec(5, UInt(VLEN.W)) else Vec(3, UInt(XLEN.W)) 622 val iqIdx = UInt(log2Up(MemIQSizeMax).W) 623 val isFirstIssue = Bool() 624 } 625 626 class MemExuOutput(isVector: Boolean = false)(implicit p: Parameters) extends XSBundle { 627 val uop = new DynInst 628 val data = if (isVector) UInt(VLEN.W) else UInt(XLEN.W) 629 val debug = new DebugBundle 630 } 631 632 class MemMicroOpRbExt(implicit p: Parameters) extends XSBundle { 633 val uop = new DynInst 634 val flag = UInt(1.W) 635 } 636} 637