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