1package xiangshan.backend.datapath 2 3import chipsalliance.rocketchip.config.Parameters 4import chisel3.{Data, _} 5import chisel3.util._ 6import difftest.{DifftestArchFpRegState, DifftestArchIntRegState, DifftestArchVecRegState} 7import freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp} 8import utility._ 9import xiangshan._ 10import xiangshan.backend.BackendParams 11import xiangshan.backend.datapath.DataConfig._ 12import xiangshan.backend.datapath.RdConfig._ 13import xiangshan.backend.issue.{ImmExtractor, IntScheduler, MemScheduler, VfScheduler} 14import xiangshan.backend.Bundles._ 15import xiangshan.backend.regfile._ 16import xiangshan.backend.datapath.WbConfig.{IntWB, PregWB, VfWB} 17 18class WbBusyArbiterIO(inPortSize: Int, outPortSize: Int)(implicit p: Parameters) extends XSBundle { 19 val in = Vec(inPortSize, Flipped(DecoupledIO(new Bundle{}))) // TODO: remote the bool 20 val flush = Flipped(ValidIO(new Redirect)) 21} 22 23class WbBusyArbiter(isInt: Boolean)(implicit p: Parameters) extends XSModule { 24 val allExuParams = backendParams.allExuParams 25 26 val portConfigs = allExuParams.flatMap(_.wbPortConfigs).filter{ 27 wbPortConfig => 28 if(isInt){ 29 wbPortConfig.isInstanceOf[IntWB] 30 } 31 else{ 32 wbPortConfig.isInstanceOf[VfWB] 33 } 34 } 35 36 val numRfWrite = if (isInt) backendParams.numIntWb else backendParams.numVfWb 37 38 val io = IO(new WbBusyArbiterIO(portConfigs.size, numRfWrite)) 39 // inGroup[port -> Bundle] 40 val inGroup = io.in.zip(portConfigs).groupBy{ case(port, config) => config.port} 41 // sort by priority 42 val inGroupSorted = inGroup.map{ 43 case(key, value) => (key -> value.sortBy{ case(port, config) => config.asInstanceOf[PregWB].priority}) 44 } 45 46 private val arbiters = Seq.tabulate(numRfWrite) { x => { 47 if (inGroupSorted.contains(x)) { 48 Some(Module(new Arbiter( new Bundle{} ,n = inGroupSorted(x).length))) 49 } else { 50 None 51 } 52 }} 53 54 arbiters.zipWithIndex.foreach { case (arb, i) => 55 if (arb.nonEmpty) { 56 arb.get.io.in.zip(inGroupSorted(i).map(_._1)).foreach { case (arbIn, addrIn) => 57 arbIn <> addrIn 58 } 59 } 60 } 61 62 arbiters.foreach(_.foreach(_.io.out.ready := true.B)) 63} 64 65class RFArbiterBundle(addrWidth: Int)(implicit p: Parameters) extends XSBundle { 66 val addr = UInt(addrWidth.W) 67} 68 69class RFReadArbiterIO(inPortSize: Int, outPortSize: Int, pregWidth: Int)(implicit p: Parameters) extends XSBundle { 70 val in = Vec(inPortSize, Flipped(DecoupledIO(new RFArbiterBundle(pregWidth)))) 71 val out = Vec(outPortSize, Valid(new RFArbiterBundle(pregWidth))) 72 val flush = Flipped(ValidIO(new Redirect)) 73} 74 75class RFReadArbiter(isInt: Boolean)(implicit p: Parameters) extends XSModule { 76 val allExuParams = backendParams.allExuParams 77 78 val portConfigs: Seq[RdConfig] = allExuParams.map(_.rfrPortConfigs.flatten).flatten.filter{ 79 rfrPortConfigs => 80 if(isInt){ 81 rfrPortConfigs.isInstanceOf[IntRD] 82 } 83 else{ 84 rfrPortConfigs.isInstanceOf[VfRD] 85 } 86 } 87 88 private val moduleName = this.getClass.getName + (if (isInt) "Int" else "Vf") 89 90 println(s"[$moduleName] ports(${portConfigs.size})") 91 for (portCfg <- portConfigs) { 92 println(s"[$moduleName] port: ${portCfg.port}, priority: ${portCfg.priority}") 93 } 94 95 val pregParams = if(isInt) backendParams.intPregParams else backendParams.vfPregParams 96 97 val io = IO(new RFReadArbiterIO(portConfigs.size, backendParams.numRfRead, pregParams.addrWidth)) 98 // inGroup[port -> Bundle] 99 val inGroup: Map[Int, IndexedSeq[(DecoupledIO[RFArbiterBundle], RdConfig)]] = io.in.zip(portConfigs).groupBy{ case(port, config) => config.port} 100 // sort by priority 101 val inGroupSorted: Map[Int, IndexedSeq[(DecoupledIO[RFArbiterBundle], RdConfig)]] = inGroup.map{ 102 case(key, value) => (key -> value.sortBy{ case(port, config) => config.priority}) 103 } 104 105 private val arbiters: Seq[Option[Arbiter[RFArbiterBundle]]] = Seq.tabulate(backendParams.numRfRead) { x => { 106 if (inGroupSorted.contains(x)) { 107 Some(Module(new Arbiter(new RFArbiterBundle(pregParams.addrWidth), inGroupSorted(x).length))) 108 } else { 109 None 110 } 111 }} 112 113 arbiters.zipWithIndex.foreach { case (arb, i) => 114 if (arb.nonEmpty) { 115 arb.get.io.in.zip(inGroupSorted(i).map(_._1)).foreach { case (arbIn, addrIn) => 116 arbIn <> addrIn 117 } 118 } 119 } 120 121 io.out.zip(arbiters).foreach { case (addrOut, arb) => 122 if (arb.nonEmpty) { 123 val arbOut = arb.get.io.out 124 arbOut.ready := true.B 125 addrOut.valid := arbOut.valid 126 addrOut.bits := arbOut.bits 127 } else { 128 addrOut := 0.U.asTypeOf(addrOut) 129 } 130 } 131} 132 133class DataPath(params: BackendParams)(implicit p: Parameters) extends LazyModule { 134 private implicit val dpParams: BackendParams = params 135 lazy val module = new DataPathImp(this) 136} 137 138class DataPathImp(override val wrapper: DataPath)(implicit p: Parameters, params: BackendParams) 139 extends LazyModuleImp(wrapper) with HasXSParameter { 140 141 private val VCONFIG_PORT = params.vconfigPort 142 143 val io = IO(new DataPathIO()) 144 145 private val (fromIntIQ, toIntIQ, toIntExu) = (io.fromIntIQ, io.toIntIQ, io.toIntExu) 146 private val (fromMemIQ, toMemIQ, toMemExu) = (io.fromMemIQ, io.toMemIQ, io.toMemExu) 147 private val (fromVfIQ , toVfIQ , toVfExu ) = (io.fromVfIQ , io.toVfIQ , io.toFpExu) 148 private val (fromIntExus, fromVfExus) = (io.fromIntExus, io.fromVfExus) 149 150 println(s"[DataPath] IntIQ(${fromIntIQ.size}), MemIQ(${fromMemIQ.size})") 151 println(s"[DataPath] IntExu(${fromIntIQ.map(_.size).sum}), MemExu(${fromMemIQ.map(_.size).sum})") 152 153 // just refences for convience 154 private val fromIQ = fromIntIQ ++ fromVfIQ ++ fromMemIQ 155 156 private val toIQs = toIntIQ ++ toVfIQ ++ toMemIQ 157 158 private val toExu = toIntExu ++ toVfExu ++ toMemExu 159 160 private val fromExus = fromIntExus ++ fromVfExus 161 162 private val fromFlattenIQ: Seq[DecoupledIO[IssueQueueIssueBundle]] = fromIQ.flatten 163 164 private val toFlattenExu: Seq[DecoupledIO[ExuInput]] = toExu.flatten 165 166 private val intWbBusyArbiter = Module(new WbBusyArbiter(true)) 167 private val vfWbBusyArbiter = Module(new WbBusyArbiter(false)) 168 private val intRFReadArbiter = Module(new RFReadArbiter(true)) 169 private val vfRFReadArbiter = Module(new RFReadArbiter(false)) 170 171 private val og0FailedVec2: MixedVec[Vec[Bool]] = Wire(MixedVec(fromIQ.map(x => Vec(x.size, Bool())))) 172 private val og1FailedVec2: MixedVec[Vec[Bool]] = Wire(MixedVec(fromIQ.map(x => Vec(x.size, Bool())))) 173 174 private val issuePortsIn = fromIQ.flatten 175 private val intNotBlocksW = fromIQ.map { case iq => Wire(Vec(iq.size, Bool())) } 176 private val intNotBlocksSeqW = intNotBlocksW.flatten 177 private val vfNotBlocksW = fromIQ.map { case iq => Wire(Vec(iq.size, Bool())) } 178 private val vfNotBlocksSeqW = vfNotBlocksW.flatten 179 private val intBlocks = fromIQ.map{ case iq => Wire(Vec(iq.size, Bool())) } 180 private val intBlocksSeq = intBlocks.flatten 181 private val vfBlocks = fromIQ.map { case iq => Wire(Vec(iq.size, Bool())) } 182 private val vfBlocksSeq = vfBlocks.flatten 183 private val intWbConflictReads = io.wbConfictRead.flatten.flatten.map(_.intConflict) 184 private val vfWbConflictReads = io.wbConfictRead.flatten.flatten.map(_.vfConflict) 185 186 val intWbBusyInSize = issuePortsIn.map(issuePortIn => issuePortIn.bits.getIntWbBusyBundle.size).scan(0)(_ + _) 187 val intReadPortInSize: IndexedSeq[Int] = issuePortsIn.map(issuePortIn => issuePortIn.bits.getIntRfReadBundle.size).scan(0)(_ + _) 188 issuePortsIn.zipWithIndex.foreach{ 189 case (issuePortIn, idx) => 190 val wbBusyIn: Seq[Bool] = issuePortIn.bits.getIntWbBusyBundle 191 val lw = intWbBusyInSize(idx) 192 val rw = intWbBusyInSize(idx + 1) 193 val arbiterInW = intWbBusyArbiter.io.in.slice(lw, rw) 194 arbiterInW.zip(wbBusyIn).foreach { 195 case (sink, source) => 196 sink.bits := DontCare 197 sink.valid := issuePortIn.valid && source 198 } 199 val notBlockFlag = if (rw > lw) { 200 val arbiterRes = arbiterInW.zip(wbBusyIn).map { 201 case (sink, source) => sink.ready 202 }.reduce(_ & _) 203 if (intWbConflictReads(idx).isDefined) { 204 Mux(intWbConflictReads(idx).get, arbiterRes, true.B) 205 } else arbiterRes 206 } else true.B 207 intNotBlocksSeqW(idx) := notBlockFlag 208 val readPortIn = issuePortIn.bits.getIntRfReadBundle 209 val l = intReadPortInSize(idx) 210 val r = intReadPortInSize(idx + 1) 211 val arbiterIn = intRFReadArbiter.io.in.slice(l, r) 212 arbiterIn.zip(readPortIn).foreach{ 213 case(sink, source) => 214 sink.bits.addr := source.addr 215 sink.valid := issuePortIn.valid && SrcType.isXp(source.srcType) 216 } 217 if(r > l){ 218 intBlocksSeq(idx) := !arbiterIn.zip(readPortIn).map { 219 case (sink, source) => Mux(SrcType.isXp(source.srcType), sink.ready, true.B) 220 }.reduce(_ & _) 221 } 222 else{ 223 intBlocksSeq(idx) := false.B 224 } 225 } 226 intWbBusyArbiter.io.flush := io.flush 227 intRFReadArbiter.io.flush := io.flush 228 229 val vfWbBusyInSize = issuePortsIn.map(issuePortIn => issuePortIn.bits.getVfWbBusyBundle.size).scan(0)(_ + _) 230 val vfReadPortInSize: IndexedSeq[Int] = issuePortsIn.map(issuePortIn => issuePortIn.bits.getVfRfReadBundle.size).scan(0)(_ + _) 231 println(s"vfReadPortInSize: $vfReadPortInSize") 232 233 issuePortsIn.zipWithIndex.foreach { 234 case (issuePortIn, idx) => 235 val wbBusyIn = issuePortIn.bits.getVfWbBusyBundle 236 val lw = vfWbBusyInSize(idx) 237 val rw = vfWbBusyInSize(idx + 1) 238 val arbiterInW = vfWbBusyArbiter.io.in.slice(lw, rw) 239 arbiterInW.zip(wbBusyIn).foreach { 240 case (sink, source) => 241 sink.bits := DontCare 242 sink.valid := issuePortIn.valid && source 243 } 244 val notBlockFlag = if (rw > lw){ 245 val arbiterRes = arbiterInW.zip(wbBusyIn).map { 246 case (sink, source) => sink.ready 247 }.reduce(_ & _) 248 if(vfWbConflictReads(idx).isDefined) { 249 Mux(vfWbConflictReads(idx).get, arbiterRes, true.B) 250 }else arbiterRes 251 }else true.B 252 vfNotBlocksSeqW(idx) := notBlockFlag 253 254 val readPortIn = issuePortIn.bits.getVfRfReadBundle 255 val l = vfReadPortInSize(idx) 256 val r = vfReadPortInSize(idx + 1) 257 val arbiterIn = vfRFReadArbiter.io.in.slice(l, r) 258 arbiterIn.zip(readPortIn).foreach { 259 case (sink, source) => 260 sink.bits.addr := source.addr 261 sink.valid := issuePortIn.valid && SrcType.isVfp(source.srcType) 262 } 263 if (r > l) { 264 vfBlocksSeq(idx) := !arbiterIn.zip(readPortIn).map { 265 case (sink, source) => Mux(SrcType.isVfp(source.srcType), sink.ready, true.B) 266 }.reduce(_ & _) 267 } 268 else { 269 vfBlocksSeq(idx) := false.B 270 } 271 } 272 vfWbBusyArbiter.io.flush := io.flush 273 vfRFReadArbiter.io.flush := io.flush 274 275 private val intSchdParams = params.schdParams(IntScheduler()) 276 private val vfSchdParams = params.schdParams(VfScheduler()) 277 private val memSchdParams = params.schdParams(MemScheduler()) 278 279 private val numIntRfReadByExu = intSchdParams.numIntRfReadByExu + memSchdParams.numIntRfReadByExu 280 private val numVfRfReadByExu = vfSchdParams.numVfRfReadByExu + memSchdParams.numVfRfReadByExu 281 // Todo: limit read port 282 private val numIntR = numIntRfReadByExu 283 private val numVfR = numVfRfReadByExu 284 println(s"[DataPath] RegFile read req needed by Exu: Int(${numIntRfReadByExu}), Vf(${numVfRfReadByExu})") 285 println(s"[DataPath] RegFile read port: Int(${numIntR}), Vf(${numVfR})") 286 287 private val schdParams = params.allSchdParams 288 289 private val intRfRaddr = Wire(Vec(params.numRfRead, UInt(intSchdParams.pregIdxWidth.W))) 290 private val intRfRdata = Wire(Vec(params.numRfRead, UInt(intSchdParams.rfDataWidth.W))) 291 private val intRfWen = Wire(Vec(io.fromIntWb.length, Bool())) 292 private val intRfWaddr = Wire(Vec(io.fromIntWb.length, UInt(intSchdParams.pregIdxWidth.W))) 293 private val intRfWdata = Wire(Vec(io.fromIntWb.length, UInt(intSchdParams.rfDataWidth.W))) 294 295 private val vfRfSplitNum = VLEN / XLEN 296 private val vfRfRaddr = Wire(Vec(params.numRfRead, UInt(vfSchdParams.pregIdxWidth.W))) 297 private val vfRfRdata = Wire(Vec(params.numRfRead, UInt(vfSchdParams.rfDataWidth.W))) 298 private val vfRfWen = Wire(Vec(vfRfSplitNum, Vec(io.fromVfWb.length, Bool()))) 299 private val vfRfWaddr = Wire(Vec(io.fromVfWb.length, UInt(vfSchdParams.pregIdxWidth.W))) 300 private val vfRfWdata = Wire(Vec(io.fromVfWb.length, UInt(vfSchdParams.rfDataWidth.W))) 301 302 private val intDebugRead: Option[(Vec[UInt], Vec[UInt])] = 303 if (env.AlwaysBasicDiff || env.EnableDifftest) { 304 Some(Wire(Vec(32, UInt(intSchdParams.pregIdxWidth.W))), Wire(Vec(32, UInt(XLEN.W)))) 305 } else { None } 306 private val vfDebugRead: Option[(Vec[UInt], Vec[UInt])] = 307 if (env.AlwaysBasicDiff || env.EnableDifftest) { 308 Some(Wire(Vec(32 + 32 + 1, UInt(vfSchdParams.pregIdxWidth.W))), Wire(Vec(32 + 32 + 1, UInt(VLEN.W)))) 309 } else { None } 310 311 private val fpDebugReadData: Option[Vec[UInt]] = 312 if (env.AlwaysBasicDiff || env.EnableDifftest) { 313 Some(Wire(Vec(32, UInt(XLEN.W)))) 314 } else { None } 315 private val vecDebugReadData: Option[Vec[UInt]] = 316 if (env.AlwaysBasicDiff || env.EnableDifftest) { 317 Some(Wire(Vec(64, UInt(64.W)))) // v0 = Cat(Vec(1), Vec(0)) 318 } else { None } 319 private val vconfigDebugReadData: Option[UInt] = 320 if (env.AlwaysBasicDiff || env.EnableDifftest) { 321 Some(Wire(UInt(64.W))) 322 } else { None } 323 324 325 fpDebugReadData.foreach(_ := vfDebugRead 326 .get._2 327 .slice(0, 32) 328 .map(_(63, 0)) 329 ) // fp only used [63, 0] 330 vecDebugReadData.foreach(_ := vfDebugRead 331 .get._2 332 .slice(32, 64) 333 .map(x => Seq(x(63, 0), x(127, 64))).flatten 334 ) 335 vconfigDebugReadData.foreach(_ := vfDebugRead 336 .get._2(64)(63, 0) 337 ) 338 339 io.debugVconfig := vconfigDebugReadData.get 340 341 IntRegFile("IntRegFile", intSchdParams.numPregs, intRfRaddr, intRfRdata, intRfWen, intRfWaddr, intRfWdata, 342 debugReadAddr = intDebugRead.map(_._1), 343 debugReadData = intDebugRead.map(_._2)) 344 VfRegFile("VfRegFile", vfSchdParams.numPregs, vfRfSplitNum, vfRfRaddr, vfRfRdata, vfRfWen, vfRfWaddr, vfRfWdata, 345 debugReadAddr = vfDebugRead.map(_._1), 346 debugReadData = vfDebugRead.map(_._2)) 347 348 intRfWaddr := io.fromIntWb.map(_.addr) 349 intRfWdata := io.fromIntWb.map(_.data) 350 intRfWen := io.fromIntWb.map(_.wen) 351 352 intRFReadArbiter.io.out.map(_.bits.addr).zip(intRfRaddr).foreach{ case(source, sink) => sink := source } 353 354 vfRfWaddr := io.fromVfWb.map(_.addr) 355 vfRfWdata := io.fromVfWb.map(_.data) 356 vfRfWen.foreach(_.zip(io.fromVfWb.map(_.wen)).foreach { case (wenSink, wenSource) => wenSink := wenSource } )// Todo: support fp multi-write 357 358 vfRFReadArbiter.io.out.map(_.bits.addr).zip(vfRfRaddr).foreach{ case(source, sink) => sink := source } 359 vfRfRaddr(VCONFIG_PORT) := io.vconfigReadPort.addr 360 io.vconfigReadPort.data := vfRfRdata(VCONFIG_PORT) 361 362 intDebugRead.foreach { case (addr, _) => 363 addr := io.debugIntRat 364 } 365 366 vfDebugRead.foreach { case (addr, _) => 367 addr := io.debugFpRat ++ io.debugVecRat :+ io.debugVconfigRat 368 } 369 println(s"[DataPath] " + 370 s"has intDebugRead: ${intDebugRead.nonEmpty}, " + 371 s"has vfDebugRead: ${vfDebugRead.nonEmpty}") 372 373 val s1_addrOHs = Reg(MixedVec( 374 fromIQ.map(x => MixedVec(x.map(_.bits.addrOH.cloneType))) 375 )) 376 val s1_toExuValid: MixedVec[MixedVec[Bool]] = Reg(MixedVec( 377 toExu.map(x => MixedVec(x.map(_.valid.cloneType))) 378 )) 379 val s1_toExuData: MixedVec[MixedVec[ExuInput]] = Reg(MixedVec(toExu.map(x => MixedVec(x.map(_.bits.cloneType))))) 380 val s1_toExuReady = Wire(MixedVec(toExu.map(x => MixedVec(x.map(_.ready.cloneType))))) // Todo 381 val s1_srcType: MixedVec[MixedVec[Vec[UInt]]] = MixedVecInit(fromIQ.map(x => MixedVecInit(x.map(xx => RegEnable(xx.bits.srcType, xx.fire))))) 382 383 val s1_intPregRData: MixedVec[MixedVec[Vec[UInt]]] = Wire(MixedVec(toExu.map(x => MixedVec(x.map(_.bits.src.cloneType))))) 384 val s1_vfPregRData: MixedVec[MixedVec[Vec[UInt]]] = Wire(MixedVec(toExu.map(x => MixedVec(x.map(_.bits.src.cloneType))))) 385 386 val rfrPortConfigs = schdParams.map(_.issueBlockParams).flatten.map(_.exuBlockParams.map(_.rfrPortConfigs)) 387 388 println(s"[DataPath] s1_intPregRData.flatten.flatten.size: ${s1_intPregRData.flatten.flatten.size}, intRfRdata.size: ${intRfRdata.size}") 389 s1_intPregRData.foreach(_.foreach(_.foreach(_ := 0.U))) 390 s1_intPregRData.zip(rfrPortConfigs).foreach { case (iqRdata, iqCfg) => 391 iqRdata.zip(iqCfg).foreach { case (iuRdata, iuCfg) => 392 val realIuCfg = iuCfg.map(x => if(x.size > 1) x.filter(_.isInstanceOf[IntRD]) else x).flatten 393 assert(iuRdata.size == realIuCfg.size, "iuRdata.size != realIuCfg.size") 394 iuRdata.zip(realIuCfg) 395 .filter { case (_, rfrPortConfig) => rfrPortConfig.isInstanceOf[IntRD] } 396 .foreach { case (sink, cfg) => sink := intRfRdata(cfg.port) } 397 } 398 } 399 400 println(s"[DataPath] s1_vfPregRData.flatten.flatten.size: ${s1_vfPregRData.flatten.flatten.size}, vfRfRdata.size: ${vfRfRdata.size}") 401 s1_vfPregRData.foreach(_.foreach(_.foreach(_ := 0.U))) 402 s1_vfPregRData.zip(rfrPortConfigs).foreach{ case(iqRdata, iqCfg) => 403 iqRdata.zip(iqCfg).foreach{ case(iuRdata, iuCfg) => 404 val realIuCfg = iuCfg.map(x => if(x.size > 1) x.filter(_.isInstanceOf[VfRD]) else x).flatten 405 assert(iuRdata.size == realIuCfg.size, "iuRdata.size != realIuCfg.size") 406 iuRdata.zip(realIuCfg) 407 .filter { case (_, rfrPortConfig) => rfrPortConfig.isInstanceOf[VfRD] } 408 .foreach { case (sink, cfg) => sink := vfRfRdata(cfg.port) } 409 } 410 } 411 412 for (i <- fromIQ.indices) { 413 for (j <- fromIQ(i).indices) { 414 // IQ(s0) --[Ctrl]--> s1Reg ---------- begin 415 // refs 416 val s1_valid = s1_toExuValid(i)(j) 417 val s1_ready = s1_toExuReady(i)(j) 418 val s1_data = s1_toExuData(i)(j) 419 val s1_addrOH = s1_addrOHs(i)(j) 420 val s0 = fromIQ(i)(j) // s0 421 val block = (intBlocks(i)(j) || !intNotBlocksW(i)(j)) || (vfBlocks(i)(j) || !vfNotBlocksW(i)(j)) 422 val s1_flush = s0.bits.common.robIdx.needFlush(Seq(io.flush, RegNextWithEnable(io.flush))) 423 val s1_cancel = og1FailedVec2(i)(j) 424 when (s0.fire && !s1_flush && !block && !s1_cancel) { 425 s1_valid := s0.valid 426 s1_data.fromIssueBundle(s0.bits) // no src data here 427 s1_addrOH := s0.bits.addrOH 428 }.otherwise { 429 s1_valid := false.B 430 } 431 dontTouch(block) 432 s0.ready := (s1_ready || !s1_valid) && !block 433 // IQ(s0) --[Ctrl]--> s1Reg ---------- end 434 435 // IQ(s0) --[Data]--> s1Reg ---------- begin 436 // imm extract 437 when (s0.fire && !s1_flush && !block) { 438 if (s1_data.params.immType.nonEmpty && s1_data.src.size > 1) { 439 // rs1 is always int reg, rs2 may be imm 440 when(SrcType.isImm(s0.bits.srcType(1))) { 441 s1_data.src(1) := ImmExtractor( 442 s0.bits.common.imm, 443 s0.bits.immType, 444 s1_data.params.dataBitsMax, 445 s1_data.params.immType.map(_.litValue) 446 ) 447 } 448 } 449 if (s1_data.params.hasJmpFu) { 450 when(SrcType.isPc(s0.bits.srcType(0))) { 451 s1_data.src(0) := SignExt(s0.bits.jmp.get.pc, XLEN) 452 } 453 } else if (s1_data.params.hasVecFu) { 454 // Fuck off riscv vector imm!!! Why not src1??? 455 when(SrcType.isImm(s0.bits.srcType(0))) { 456 s1_data.src(0) := ImmExtractor( 457 s0.bits.common.imm, 458 s0.bits.immType, 459 s1_data.params.dataBitsMax, 460 s1_data.params.immType.map(_.litValue) 461 ) 462 } 463 } 464 } 465 // IQ(s0) --[Data]--> s1Reg ---------- end 466 } 467 } 468 469 private val fromIQFire = fromIQ.map(_.map(_.fire)) 470 private val toExuFire = toExu.map(_.map(_.fire)) 471 toIQs.zipWithIndex.foreach { 472 case(toIQ, iqIdx) => 473 toIQ.zipWithIndex.foreach { 474 case (toIU, iuIdx) => 475 // IU: issue unit 476 val og0resp = toIU.og0resp 477 og0FailedVec2(iqIdx)(iuIdx) := fromIQ(iqIdx)(iuIdx).valid && (!fromIQFire(iqIdx)(iuIdx)) 478 og0resp.valid := og0FailedVec2(iqIdx)(iuIdx) 479 og0resp.bits.respType := RSFeedbackType.rfArbitFail 480 og0resp.bits.addrOH := fromIQ(iqIdx)(iuIdx).bits.addrOH 481 og0resp.bits.rfWen := fromIQ(iqIdx)(iuIdx).bits.common.rfWen.getOrElse(false.B) 482 og0resp.bits.fuType := fromIQ(iqIdx)(iuIdx).bits.common.fuType 483 484 val og1resp = toIU.og1resp 485 og1FailedVec2(iqIdx)(iuIdx) := s1_toExuValid(iqIdx)(iuIdx) && !toExuFire(iqIdx)(iuIdx) 486 og1resp.valid := s1_toExuValid(iqIdx)(iuIdx) 487 og1resp.bits.respType := Mux(!og1FailedVec2(iqIdx)(iuIdx), 488 if (toIU.issueQueueParams.isMemAddrIQ) RSFeedbackType.fuUncertain else RSFeedbackType.fuIdle, 489 RSFeedbackType.fuBusy) 490 og1resp.bits.addrOH := s1_addrOHs(iqIdx)(iuIdx) 491 og1resp.bits.rfWen := s1_toExuData(iqIdx)(iuIdx).rfWen.getOrElse(false.B) 492 og1resp.bits.fuType := s1_toExuData(iqIdx)(iuIdx).fuType 493 } 494 } 495 496 io.og0CancelVec.zip(io.og1CancelVec).zipWithIndex.foreach { case ((og0Cancel, og1Cancel), i) => 497 og0Cancel := fromFlattenIQ(i).valid && !fromFlattenIQ(i).fire 498 og1Cancel := toFlattenExu(i).valid && !toFlattenExu(i).fire 499 } 500 501 for (i <- toExu.indices) { 502 for (j <- toExu(i).indices) { 503 // s1Reg --[Ctrl]--> exu(s1) ---------- begin 504 // refs 505 val sinkData = toExu(i)(j).bits 506 // assign 507 toExu(i)(j).valid := s1_toExuValid(i)(j) 508 s1_toExuReady(i)(j) := toExu(i)(j).ready 509 sinkData := s1_toExuData(i)(j) 510 // s1Reg --[Ctrl]--> exu(s1) ---------- end 511 512 // s1Reg --[Data]--> exu(s1) ---------- begin 513 // data source1: preg read data 514 for (k <- sinkData.src.indices) { 515 val srcDataTypeSet: Set[DataConfig] = sinkData.params.getSrcDataType(k) 516 517 val readRfMap: Seq[(Bool, UInt)] = (Seq(None) :+ 518 (if (s1_intPregRData(i)(j).isDefinedAt(k) && srcDataTypeSet.intersect(IntRegSrcDataSet).nonEmpty) 519 Some(SrcType.isXp(s1_srcType(i)(j)(k)) -> s1_intPregRData(i)(j)(k)) 520 else None) :+ 521 (if (s1_vfPregRData(i)(j).isDefinedAt(k) && srcDataTypeSet.intersect(VfRegSrcDataSet).nonEmpty) 522 Some(SrcType.isVfp(s1_srcType(i)(j)(k))-> s1_vfPregRData(i)(j)(k)) 523 else None) 524 ).filter(_.nonEmpty).map(_.get) 525 if (readRfMap.nonEmpty) 526 sinkData.src(k) := Mux1H(readRfMap) 527 } 528 529 // data source2: extracted imm and pc saved in s1Reg 530 if (sinkData.params.immType.nonEmpty && sinkData.src.size > 1) { 531 when(SrcType.isImm(s1_srcType(i)(j)(1))) { 532 sinkData.src(1) := s1_toExuData(i)(j).src(1) 533 } 534 } 535 if (sinkData.params.hasJmpFu) { 536 when(SrcType.isPc(s1_srcType(i)(j)(0))) { 537 sinkData.src(0) := s1_toExuData(i)(j).src(0) 538 } 539 } else if (sinkData.params.hasVecFu) { 540 when(SrcType.isImm(s1_srcType(i)(j)(0))) { 541 sinkData.src(0) := s1_toExuData(i)(j).src(0) 542 } 543 } 544 // s1Reg --[Data]--> exu(s1) ---------- end 545 } 546 } 547 548 if (env.AlwaysBasicDiff || env.EnableDifftest) { 549 val delayedCnt = 2 550 val difftestArchIntRegState = Module(new DifftestArchIntRegState) 551 difftestArchIntRegState.io.clock := clock 552 difftestArchIntRegState.io.coreid := io.hartId 553 difftestArchIntRegState.io.gpr := DelayN(intDebugRead.get._2, delayedCnt) 554 555 val difftestArchFpRegState = Module(new DifftestArchFpRegState) 556 difftestArchFpRegState.io.clock := clock 557 difftestArchFpRegState.io.coreid := io.hartId 558 difftestArchFpRegState.io.fpr := DelayN(fpDebugReadData.get, delayedCnt) 559 560 val difftestArchVecRegState = Module(new DifftestArchVecRegState) 561 difftestArchVecRegState.io.clock := clock 562 difftestArchVecRegState.io.coreid := io.hartId 563 difftestArchVecRegState.io.vpr := DelayN(vecDebugReadData.get, delayedCnt) 564 } 565} 566 567class DataPathIO()(implicit p: Parameters, params: BackendParams) extends XSBundle { 568 // params 569 private val intSchdParams = params.schdParams(IntScheduler()) 570 private val vfSchdParams = params.schdParams(VfScheduler()) 571 private val memSchdParams = params.schdParams(MemScheduler()) 572 private val exuParams = params.allExuParams 573 // bundles 574 val hartId = Input(UInt(8.W)) 575 576 val flush: ValidIO[Redirect] = Flipped(ValidIO(new Redirect)) 577 578 // Todo: check if this can be removed 579 val vconfigReadPort = new RfReadPort(XLEN, PhyRegIdxWidth) 580 581 val wbConfictRead = Input(MixedVec(params.allSchdParams.map(x => MixedVec(x.issueBlockParams.map(x => x.genWbConflictBundle()))))) 582 583 val fromIntIQ: MixedVec[MixedVec[DecoupledIO[IssueQueueIssueBundle]]] = 584 Flipped(MixedVec(intSchdParams.issueBlockParams.map(_.genIssueDecoupledBundle))) 585 586 val fromMemIQ: MixedVec[MixedVec[DecoupledIO[IssueQueueIssueBundle]]] = 587 Flipped(MixedVec(memSchdParams.issueBlockParams.map(_.genIssueDecoupledBundle))) 588 589 val fromVfIQ = Flipped(MixedVec(vfSchdParams.issueBlockParams.map(_.genIssueDecoupledBundle))) 590 591 val toIntIQ = MixedVec(intSchdParams.issueBlockParams.map(_.genOGRespBundle)) 592 593 val toMemIQ = MixedVec(memSchdParams.issueBlockParams.map(_.genOGRespBundle)) 594 595 val toVfIQ = MixedVec(vfSchdParams.issueBlockParams.map(_.genOGRespBundle)) 596 597 val og0CancelVec = Output(ExuVec(backendParams.numExu)) 598 599 val og1CancelVec = Output(ExuVec(backendParams.numExu)) 600 601 val toIntExu: MixedVec[MixedVec[DecoupledIO[ExuInput]]] = intSchdParams.genExuInputBundle 602 603 val toFpExu: MixedVec[MixedVec[DecoupledIO[ExuInput]]] = MixedVec(vfSchdParams.genExuInputBundle) 604 605 val toMemExu: MixedVec[MixedVec[DecoupledIO[ExuInput]]] = memSchdParams.genExuInputBundle 606 607 val fromIntWb: MixedVec[RfWritePortWithConfig] = MixedVec(params.genIntWriteBackBundle) 608 609 val fromVfWb: MixedVec[RfWritePortWithConfig] = MixedVec(params.genVfWriteBackBundle) 610 611 val fromIntExus = Flipped(intSchdParams.genExuOutputValidBundle) 612 613 val fromVfExus = Flipped(intSchdParams.genExuOutputValidBundle) 614 615 val debugIntRat = Input(Vec(32, UInt(intSchdParams.pregIdxWidth.W))) 616 val debugFpRat = Input(Vec(32, UInt(vfSchdParams.pregIdxWidth.W))) 617 val debugVecRat = Input(Vec(32, UInt(vfSchdParams.pregIdxWidth.W))) 618 val debugVconfigRat = Input(UInt(vfSchdParams.pregIdxWidth.W)) 619 val debugVconfig = Output(UInt(XLEN.W)) 620 621} 622