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