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 intWbBusyArbiter = Module(new WbBusyArbiter(true)) 163 private val vfWbBusyArbiter = Module(new WbBusyArbiter(false)) 164 private val intRFReadArbiter = Module(new RFReadArbiter(true)) 165 private val vfRFReadArbiter = Module(new RFReadArbiter(false)) 166 167 private val og0FailedVec: Vec[Bool] = Wire(Vec(backendParams.numExu, Bool())) 168 private val og1FailedVec: Vec[Bool] = Wire(Vec(backendParams.numExu, Bool())) 169 private val og0FailedVec2: MixedVec[Vec[Bool]] = Wire(MixedVec(fromIQ.map(x => Vec(x.size, Bool())))) 170 private val og1FailedVec2: MixedVec[Vec[Bool]] = Wire(MixedVec(fromIQ.map(x => Vec(x.size, Bool())))) 171 172 private val issuePortsIn = fromIQ.flatten 173 private val intNotBlocksW = fromIQ.map { case iq => Wire(Vec(iq.size, Bool())) } 174 private val intNotBlocksSeqW = intNotBlocksW.flatten 175 private val vfNotBlocksW = fromIQ.map { case iq => Wire(Vec(iq.size, Bool())) } 176 private val vfNotBlocksSeqW = vfNotBlocksW.flatten 177 private val intBlocks = fromIQ.map{ case iq => Wire(Vec(iq.size, Bool())) } 178 private val intBlocksSeq = intBlocks.flatten 179 private val vfBlocks = fromIQ.map { case iq => Wire(Vec(iq.size, Bool())) } 180 private val vfBlocksSeq = vfBlocks.flatten 181 private val intWbConflictReads = io.wbConfictRead.flatten.flatten.map(_.intConflict) 182 private val vfWbConflictReads = io.wbConfictRead.flatten.flatten.map(_.vfConflict) 183 184 val intWbBusyInSize = issuePortsIn.map(issuePortIn => issuePortIn.bits.getIntWbBusyBundle.size).scan(0)(_ + _) 185 val intReadPortInSize: IndexedSeq[Int] = issuePortsIn.map(issuePortIn => issuePortIn.bits.getIntRfReadBundle.size).scan(0)(_ + _) 186 issuePortsIn.zipWithIndex.foreach{ 187 case (issuePortIn, idx) => 188 val wbBusyIn: Seq[Bool] = issuePortIn.bits.getIntWbBusyBundle 189 val lw = intWbBusyInSize(idx) 190 val rw = intWbBusyInSize(idx + 1) 191 val arbiterInW = intWbBusyArbiter.io.in.slice(lw, rw) 192 arbiterInW.zip(wbBusyIn).foreach { 193 case (sink, source) => 194 sink.bits := DontCare 195 sink.valid := issuePortIn.valid && source 196 } 197 val notBlockFlag = if (rw > lw) { 198 val arbiterRes = arbiterInW.zip(wbBusyIn).map { 199 case (sink, source) => sink.ready 200 }.reduce(_ & _) 201 if (intWbConflictReads(idx).isDefined) { 202 Mux(intWbConflictReads(idx).get, arbiterRes, true.B) 203 } else arbiterRes 204 } else true.B 205 intNotBlocksSeqW(idx) := notBlockFlag 206 val readPortIn = issuePortIn.bits.getIntRfReadBundle 207 val l = intReadPortInSize(idx) 208 val r = intReadPortInSize(idx + 1) 209 val arbiterIn = intRFReadArbiter.io.in.slice(l, r) 210 arbiterIn.zip(readPortIn).foreach{ 211 case(sink, source) => 212 sink.bits.addr := source.addr 213 sink.valid := issuePortIn.valid && SrcType.isXp(source.srcType) 214 } 215 if(r > l){ 216 intBlocksSeq(idx) := !arbiterIn.zip(readPortIn).map { 217 case (sink, source) => Mux(SrcType.isXp(source.srcType), sink.ready, true.B) 218 }.reduce(_ & _) 219 } 220 else{ 221 intBlocksSeq(idx) := false.B 222 } 223 } 224 intWbBusyArbiter.io.flush := io.flush 225 intRFReadArbiter.io.flush := io.flush 226 227 val vfWbBusyInSize = issuePortsIn.map(issuePortIn => issuePortIn.bits.getVfWbBusyBundle.size).scan(0)(_ + _) 228 val vfReadPortInSize: IndexedSeq[Int] = issuePortsIn.map(issuePortIn => issuePortIn.bits.getVfRfReadBundle.size).scan(0)(_ + _) 229 println(s"vfReadPortInSize: $vfReadPortInSize") 230 231 issuePortsIn.zipWithIndex.foreach { 232 case (issuePortIn, idx) => 233 val wbBusyIn = issuePortIn.bits.getVfWbBusyBundle 234 val lw = vfWbBusyInSize(idx) 235 val rw = vfWbBusyInSize(idx + 1) 236 val arbiterInW = vfWbBusyArbiter.io.in.slice(lw, rw) 237 arbiterInW.zip(wbBusyIn).foreach { 238 case (sink, source) => 239 sink.bits := DontCare 240 sink.valid := issuePortIn.valid && source 241 } 242 val notBlockFlag = if (rw > lw){ 243 val arbiterRes = arbiterInW.zip(wbBusyIn).map { 244 case (sink, source) => sink.ready 245 }.reduce(_ & _) 246 if(vfWbConflictReads(idx).isDefined) { 247 Mux(vfWbConflictReads(idx).get, arbiterRes, true.B) 248 }else arbiterRes 249 }else true.B 250 vfNotBlocksSeqW(idx) := notBlockFlag 251 252 val readPortIn = issuePortIn.bits.getVfRfReadBundle 253 val l = vfReadPortInSize(idx) 254 val r = vfReadPortInSize(idx + 1) 255 val arbiterIn = vfRFReadArbiter.io.in.slice(l, r) 256 arbiterIn.zip(readPortIn).foreach { 257 case (sink, source) => 258 sink.bits.addr := source.addr 259 sink.valid := issuePortIn.valid && SrcType.isVfp(source.srcType) 260 } 261 if (r > l) { 262 vfBlocksSeq(idx) := !arbiterIn.zip(readPortIn).map { 263 case (sink, source) => Mux(SrcType.isVfp(source.srcType), sink.ready, true.B) 264 }.reduce(_ & _) 265 } 266 else { 267 vfBlocksSeq(idx) := false.B 268 } 269 } 270 vfWbBusyArbiter.io.flush := io.flush 271 vfRFReadArbiter.io.flush := io.flush 272 273 private val intSchdParams = params.schdParams(IntScheduler()) 274 private val vfSchdParams = params.schdParams(VfScheduler()) 275 private val memSchdParams = params.schdParams(MemScheduler()) 276 277 private val numIntRfReadByExu = intSchdParams.numIntRfReadByExu + memSchdParams.numIntRfReadByExu 278 private val numVfRfReadByExu = vfSchdParams.numVfRfReadByExu + memSchdParams.numVfRfReadByExu 279 // Todo: limit read port 280 private val numIntR = numIntRfReadByExu 281 private val numVfR = numVfRfReadByExu 282 println(s"[DataPath] RegFile read req needed by Exu: Int(${numIntRfReadByExu}), Vf(${numVfRfReadByExu})") 283 println(s"[DataPath] RegFile read port: Int(${numIntR}), Vf(${numVfR})") 284 285 private val schdParams = params.allSchdParams 286 287 private val intRfRaddr = Wire(Vec(params.numRfRead, UInt(intSchdParams.pregIdxWidth.W))) 288 private val intRfRdata = Wire(Vec(params.numRfRead, UInt(intSchdParams.rfDataWidth.W))) 289 private val intRfWen = Wire(Vec(io.fromIntWb.length, Bool())) 290 private val intRfWaddr = Wire(Vec(io.fromIntWb.length, UInt(intSchdParams.pregIdxWidth.W))) 291 private val intRfWdata = Wire(Vec(io.fromIntWb.length, UInt(intSchdParams.rfDataWidth.W))) 292 293 private val vfRfSplitNum = VLEN / XLEN 294 private val vfRfRaddr = Wire(Vec(params.numRfRead, UInt(vfSchdParams.pregIdxWidth.W))) 295 private val vfRfRdata = Wire(Vec(params.numRfRead, UInt(vfSchdParams.rfDataWidth.W))) 296 private val vfRfWen = Wire(Vec(vfRfSplitNum, Vec(io.fromVfWb.length, Bool()))) 297 private val vfRfWaddr = Wire(Vec(io.fromVfWb.length, UInt(vfSchdParams.pregIdxWidth.W))) 298 private val vfRfWdata = Wire(Vec(io.fromVfWb.length, UInt(vfSchdParams.rfDataWidth.W))) 299 300 private val intDebugRead: Option[(Vec[UInt], Vec[UInt])] = 301 if (env.AlwaysBasicDiff || env.EnableDifftest) { 302 Some(Wire(Vec(32, UInt(intSchdParams.pregIdxWidth.W))), Wire(Vec(32, UInt(XLEN.W)))) 303 } else { None } 304 private val vfDebugRead: Option[(Vec[UInt], Vec[UInt])] = 305 if (env.AlwaysBasicDiff || env.EnableDifftest) { 306 Some(Wire(Vec(32 + 32 + 1, UInt(vfSchdParams.pregIdxWidth.W))), Wire(Vec(32 + 32 + 1, UInt(VLEN.W)))) 307 } else { None } 308 309 private val fpDebugReadData: Option[Vec[UInt]] = 310 if (env.AlwaysBasicDiff || env.EnableDifftest) { 311 Some(Wire(Vec(32, UInt(XLEN.W)))) 312 } else { None } 313 private val vecDebugReadData: Option[Vec[UInt]] = 314 if (env.AlwaysBasicDiff || env.EnableDifftest) { 315 Some(Wire(Vec(64, UInt(64.W)))) // v0 = Cat(Vec(1), Vec(0)) 316 } else { None } 317 private val vconfigDebugReadData: Option[UInt] = 318 if (env.AlwaysBasicDiff || env.EnableDifftest) { 319 Some(Wire(UInt(64.W))) 320 } else { None } 321 322 323 fpDebugReadData.foreach(_ := vfDebugRead 324 .get._2 325 .slice(0, 32) 326 .map(_(63, 0)) 327 ) // fp only used [63, 0] 328 vecDebugReadData.foreach(_ := vfDebugRead 329 .get._2 330 .slice(32, 64) 331 .map(x => Seq(x(63, 0), x(127, 64))).flatten 332 ) 333 vconfigDebugReadData.foreach(_ := vfDebugRead 334 .get._2(64)(63, 0) 335 ) 336 337 io.debugVconfig := vconfigDebugReadData.get 338 339 IntRegFile("IntRegFile", intSchdParams.numPregs, intRfRaddr, intRfRdata, intRfWen, intRfWaddr, intRfWdata, 340 debugReadAddr = intDebugRead.map(_._1), 341 debugReadData = intDebugRead.map(_._2)) 342 VfRegFile("VfRegFile", vfSchdParams.numPregs, vfRfSplitNum, vfRfRaddr, vfRfRdata, vfRfWen, vfRfWaddr, vfRfWdata, 343 debugReadAddr = vfDebugRead.map(_._1), 344 debugReadData = vfDebugRead.map(_._2)) 345 346 intRfWaddr := io.fromIntWb.map(_.addr) 347 intRfWdata := io.fromIntWb.map(_.data) 348 intRfWen := io.fromIntWb.map(_.wen) 349 350 intRFReadArbiter.io.out.map(_.bits.addr).zip(intRfRaddr).foreach{ case(source, sink) => sink := source } 351 352 vfRfWaddr := io.fromVfWb.map(_.addr) 353 vfRfWdata := io.fromVfWb.map(_.data) 354 vfRfWen.foreach(_.zip(io.fromVfWb.map(_.wen)).foreach { case (wenSink, wenSource) => wenSink := wenSource } )// Todo: support fp multi-write 355 356 vfRFReadArbiter.io.out.map(_.bits.addr).zip(vfRfRaddr).foreach{ case(source, sink) => sink := source } 357 vfRfRaddr(VCONFIG_PORT) := io.vconfigReadPort.addr 358 io.vconfigReadPort.data := vfRfRdata(VCONFIG_PORT) 359 360 intDebugRead.foreach { case (addr, _) => 361 addr := io.debugIntRat 362 } 363 364 vfDebugRead.foreach { case (addr, _) => 365 addr := io.debugFpRat ++ io.debugVecRat :+ io.debugVconfigRat 366 } 367 println(s"[DataPath] " + 368 s"has intDebugRead: ${intDebugRead.nonEmpty}, " + 369 s"has vfDebugRead: ${vfDebugRead.nonEmpty}") 370 371 val s1_addrOHs = Reg(MixedVec( 372 fromIQ.map(x => MixedVec(x.map(_.bits.addrOH.cloneType))) 373 )) 374 val s1_toExuValid: MixedVec[MixedVec[Bool]] = Reg(MixedVec( 375 toExu.map(x => MixedVec(x.map(_.valid.cloneType))) 376 )) 377 val s1_toExuData: MixedVec[MixedVec[ExuInput]] = Reg(MixedVec(toExu.map(x => MixedVec(x.map(_.bits.cloneType))))) 378 val s1_toExuReady = Wire(MixedVec(toExu.map(x => MixedVec(x.map(_.ready.cloneType))))) // Todo 379 val s1_srcType: MixedVec[MixedVec[Vec[UInt]]] = MixedVecInit(fromIQ.map(x => MixedVecInit(x.map(xx => RegEnable(xx.bits.srcType, xx.fire))))) 380 381 val s1_intPregRData: MixedVec[MixedVec[Vec[UInt]]] = Wire(MixedVec(toExu.map(x => MixedVec(x.map(_.bits.src.cloneType))))) 382 val s1_vfPregRData: MixedVec[MixedVec[Vec[UInt]]] = Wire(MixedVec(toExu.map(x => MixedVec(x.map(_.bits.src.cloneType))))) 383 384 val rfrPortConfigs = schdParams.map(_.issueBlockParams).flatten.map(_.exuBlockParams.map(_.rfrPortConfigs)) 385 386 println(s"[DataPath] s1_intPregRData.flatten.flatten.size: ${s1_intPregRData.flatten.flatten.size}, intRfRdata.size: ${intRfRdata.size}") 387 s1_intPregRData.foreach(_.foreach(_.foreach(_ := 0.U))) 388 s1_intPregRData.zip(rfrPortConfigs).foreach { case (iqRdata, iqCfg) => 389 iqRdata.zip(iqCfg).foreach { case (iuRdata, iuCfg) => 390 val realIuCfg = iuCfg.map(x => if(x.size > 1) x.filter(_.isInstanceOf[IntRD]) else x).flatten 391 assert(iuRdata.size == realIuCfg.size, "iuRdata.size != realIuCfg.size") 392 iuRdata.zip(realIuCfg) 393 .filter { case (_, rfrPortConfig) => rfrPortConfig.isInstanceOf[IntRD] } 394 .foreach { case (sink, cfg) => sink := intRfRdata(cfg.port) } 395 } 396 } 397 398 println(s"[DataPath] s1_vfPregRData.flatten.flatten.size: ${s1_vfPregRData.flatten.flatten.size}, vfRfRdata.size: ${vfRfRdata.size}") 399 s1_vfPregRData.foreach(_.foreach(_.foreach(_ := 0.U))) 400 s1_vfPregRData.zip(rfrPortConfigs).foreach{ case(iqRdata, iqCfg) => 401 iqRdata.zip(iqCfg).foreach{ case(iuRdata, iuCfg) => 402 val realIuCfg = iuCfg.map(x => if(x.size > 1) x.filter(_.isInstanceOf[VfRD]) else x).flatten 403 assert(iuRdata.size == realIuCfg.size, "iuRdata.size != realIuCfg.size") 404 iuRdata.zip(realIuCfg) 405 .filter { case (_, rfrPortConfig) => rfrPortConfig.isInstanceOf[VfRD] } 406 .foreach { case (sink, cfg) => sink := vfRfRdata(cfg.port) } 407 } 408 } 409 410 for (i <- fromIQ.indices) { 411 for (j <- fromIQ(i).indices) { 412 // IQ(s0) --[Ctrl]--> s1Reg ---------- begin 413 // refs 414 val s1_valid = s1_toExuValid(i)(j) 415 val s1_ready = s1_toExuReady(i)(j) 416 val s1_data = s1_toExuData(i)(j) 417 val s1_addrOH = s1_addrOHs(i)(j) 418 val s0 = fromIQ(i)(j) // s0 419 val block = (intBlocks(i)(j) || !intNotBlocksW(i)(j)) || (vfBlocks(i)(j) || !vfNotBlocksW(i)(j)) 420 val s1_flush = s0.bits.common.robIdx.needFlush(Seq(io.flush, RegNextWithEnable(io.flush))) 421 val s1_cancel = og1FailedVec2(i)(j) 422 when (s0.fire && !s1_flush && !block && !s1_cancel) { 423 s1_valid := s0.valid 424 s1_data.fromIssueBundle(s0.bits) // no src data here 425 s1_addrOH := s0.bits.addrOH 426 }.otherwise { 427 s1_valid := false.B 428 } 429 dontTouch(block) 430 s0.ready := (s1_ready || !s1_valid) && !block 431 // IQ(s0) --[Ctrl]--> s1Reg ---------- end 432 433 // IQ(s0) --[Data]--> s1Reg ---------- begin 434 // imm extract 435 when (s0.fire && !s1_flush && !block) { 436 if (s1_data.params.immType.nonEmpty && s1_data.src.size > 1) { 437 // rs1 is always int reg, rs2 may be imm 438 when(SrcType.isImm(s0.bits.srcType(1))) { 439 s1_data.src(1) := ImmExtractor( 440 s0.bits.common.imm, 441 s0.bits.immType, 442 s1_data.params.dataBitsMax, 443 s1_data.params.immType.map(_.litValue) 444 ) 445 } 446 } 447 if (s1_data.params.hasJmpFu) { 448 when(SrcType.isPc(s0.bits.srcType(0))) { 449 s1_data.src(0) := SignExt(s0.bits.jmp.get.pc, XLEN) 450 } 451 } else if (s1_data.params.hasVecFu) { 452 // Fuck off riscv vector imm!!! Why not src1??? 453 when(SrcType.isImm(s0.bits.srcType(0))) { 454 s1_data.src(0) := ImmExtractor( 455 s0.bits.common.imm, 456 s0.bits.immType, 457 s1_data.params.dataBitsMax, 458 s1_data.params.immType.map(_.litValue) 459 ) 460 } 461 } 462 } 463 // IQ(s0) --[Data]--> s1Reg ---------- end 464 } 465 } 466 467 private val fromIQFire = fromIQ.map(_.map(_.fire)) 468 private val toExuFire = toExu.map(_.map(_.fire)) 469 toIQs.zipWithIndex.foreach { 470 case(toIQ, iqIdx) => 471 toIQ.zipWithIndex.foreach { 472 case (toIU, iuIdx) => 473 // IU: issue unit 474 val og0resp = toIU.og0resp 475 og0FailedVec2(iqIdx)(iuIdx) := fromIQ(iqIdx)(iuIdx).valid && (!fromIQFire(iqIdx)(iuIdx)) 476 og0resp.valid := og0FailedVec2(iqIdx)(iuIdx) 477 og0resp.bits.respType := RSFeedbackType.rfArbitFail 478 og0resp.bits.addrOH := fromIQ(iqIdx)(iuIdx).bits.addrOH 479 og0resp.bits.rfWen := fromIQ(iqIdx)(iuIdx).bits.common.rfWen.getOrElse(false.B) 480 og0resp.bits.fuType := fromIQ(iqIdx)(iuIdx).bits.common.fuType 481 482 val og1resp = toIU.og1resp 483 og1FailedVec2(iqIdx)(iuIdx) := s1_toExuValid(iqIdx)(iuIdx) && !toExuFire(iqIdx)(iuIdx) 484 og1resp.valid := s1_toExuValid(iqIdx)(iuIdx) 485 og1resp.bits.respType := Mux(!og1FailedVec2(iqIdx)(iuIdx), 486 if (toIU.issueQueueParams.isMemAddrIQ) RSFeedbackType.fuUncertain else RSFeedbackType.fuIdle, 487 RSFeedbackType.fuBusy) 488 og1resp.bits.addrOH := s1_addrOHs(iqIdx)(iuIdx) 489 og1resp.bits.rfWen := s1_toExuData(iqIdx)(iuIdx).rfWen.getOrElse(false.B) 490 og1resp.bits.fuType := s1_toExuData(iqIdx)(iuIdx).fuType 491 } 492 } 493 494 io.toIQCancelVec.zipWithIndex.foreach { case (cancelBundle: IssueQueueCancelBundle, i) => 495 og0FailedVec(i) := (fromIQ.flatten.find(_.bits.exuIdx == cancelBundle.exuIdx).get match { case x => x.valid && !x.fire }) 496 og1FailedVec(i) := (toExu.flatten.find(_.bits.exuIdx == cancelBundle.exuIdx).get match { case x => x.valid && !x.fire }) 497 cancelBundle("OG0") := og0FailedVec(i) 498 cancelBundle("OG1") := og1FailedVec(i) 499 cancelBundle("IS") := false.B 500 } 501 502 for (i <- toExu.indices) { 503 for (j <- toExu(i).indices) { 504 // s1Reg --[Ctrl]--> exu(s1) ---------- begin 505 // refs 506 val sinkData = toExu(i)(j).bits 507 // assign 508 toExu(i)(j).valid := s1_toExuValid(i)(j) 509 s1_toExuReady(i)(j) := toExu(i)(j).ready 510 sinkData := s1_toExuData(i)(j) 511 // s1Reg --[Ctrl]--> exu(s1) ---------- end 512 513 // s1Reg --[Data]--> exu(s1) ---------- begin 514 // data source1: preg read data 515 for (k <- sinkData.src.indices) { 516 val srcDataTypeSet: Set[DataConfig] = sinkData.params.getSrcDataType(k) 517 518 val readRfMap: Seq[(Bool, UInt)] = (Seq(None) :+ 519 (if (s1_intPregRData(i)(j).isDefinedAt(k) && srcDataTypeSet.intersect(IntRegSrcDataSet).nonEmpty) 520 Some(SrcType.isXp(s1_srcType(i)(j)(k)) -> s1_intPregRData(i)(j)(k)) 521 else None) :+ 522 (if (s1_vfPregRData(i)(j).isDefinedAt(k) && srcDataTypeSet.intersect(VfRegSrcDataSet).nonEmpty) 523 Some(SrcType.isVfp(s1_srcType(i)(j)(k))-> s1_vfPregRData(i)(j)(k)) 524 else None) 525 ).filter(_.nonEmpty).map(_.get) 526 if (readRfMap.nonEmpty) 527 sinkData.src(k) := Mux1H(readRfMap) 528 } 529 530 // data source2: extracted imm and pc saved in s1Reg 531 if (sinkData.params.immType.nonEmpty && sinkData.src.size > 1) { 532 when(SrcType.isImm(s1_srcType(i)(j)(1))) { 533 sinkData.src(1) := s1_toExuData(i)(j).src(1) 534 } 535 } 536 if (sinkData.params.hasJmpFu) { 537 when(SrcType.isPc(s1_srcType(i)(j)(0))) { 538 sinkData.src(0) := s1_toExuData(i)(j).src(0) 539 } 540 } else if (sinkData.params.hasVecFu) { 541 when(SrcType.isImm(s1_srcType(i)(j)(0))) { 542 sinkData.src(0) := s1_toExuData(i)(j).src(0) 543 } 544 } 545 // s1Reg --[Data]--> exu(s1) ---------- end 546 } 547 } 548 549 if (env.AlwaysBasicDiff || env.EnableDifftest) { 550 val delayedCnt = 2 551 val difftestArchIntRegState = Module(new DifftestArchIntRegState) 552 difftestArchIntRegState.io.clock := clock 553 difftestArchIntRegState.io.coreid := io.hartId 554 difftestArchIntRegState.io.gpr := DelayN(intDebugRead.get._2, delayedCnt) 555 556 val difftestArchFpRegState = Module(new DifftestArchFpRegState) 557 difftestArchFpRegState.io.clock := clock 558 difftestArchFpRegState.io.coreid := io.hartId 559 difftestArchFpRegState.io.fpr := DelayN(fpDebugReadData.get, delayedCnt) 560 561 val difftestArchVecRegState = Module(new DifftestArchVecRegState) 562 difftestArchVecRegState.io.clock := clock 563 difftestArchVecRegState.io.coreid := io.hartId 564 difftestArchVecRegState.io.vpr := DelayN(vecDebugReadData.get, delayedCnt) 565 } 566} 567 568class DataPathIO()(implicit p: Parameters, params: BackendParams) extends XSBundle { 569 // params 570 private val intSchdParams = params.schdParams(IntScheduler()) 571 private val vfSchdParams = params.schdParams(VfScheduler()) 572 private val memSchdParams = params.schdParams(MemScheduler()) 573 private val exuParams = params.allExuParams 574 // bundles 575 val hartId = Input(UInt(8.W)) 576 577 val flush: ValidIO[Redirect] = Flipped(ValidIO(new Redirect)) 578 579 // Todo: check if this can be removed 580 val vconfigReadPort = new RfReadPort(XLEN, PhyRegIdxWidth) 581 582 val wbConfictRead = Input(MixedVec(params.allSchdParams.map(x => MixedVec(x.issueBlockParams.map(x => x.genWbConflictBundle()))))) 583 584 val fromIntIQ: MixedVec[MixedVec[DecoupledIO[IssueQueueIssueBundle]]] = 585 Flipped(MixedVec(intSchdParams.issueBlockParams.map(_.genIssueDecoupledBundle))) 586 587 val fromMemIQ: MixedVec[MixedVec[DecoupledIO[IssueQueueIssueBundle]]] = 588 Flipped(MixedVec(memSchdParams.issueBlockParams.map(_.genIssueDecoupledBundle))) 589 590 val fromVfIQ = Flipped(MixedVec(vfSchdParams.issueBlockParams.map(_.genIssueDecoupledBundle))) 591 592 val toIntIQ = MixedVec(intSchdParams.issueBlockParams.map(_.genOGRespBundle)) 593 594 val toMemIQ = MixedVec(memSchdParams.issueBlockParams.map(_.genOGRespBundle)) 595 596 val toVfIQ = MixedVec(vfSchdParams.issueBlockParams.map(_.genOGRespBundle)) 597 598 val toIQCancelVec = Output(MixedVec(exuParams.map(x => new IssueQueueCancelBundle(x.exuIdx, cancelStages)))) 599 600 val toIntExu: MixedVec[MixedVec[DecoupledIO[ExuInput]]] = intSchdParams.genExuInputBundle 601 602 val toFpExu: MixedVec[MixedVec[DecoupledIO[ExuInput]]] = MixedVec(vfSchdParams.genExuInputBundle) 603 604 val toMemExu: MixedVec[MixedVec[DecoupledIO[ExuInput]]] = memSchdParams.genExuInputBundle 605 606 val fromIntWb: MixedVec[RfWritePortWithConfig] = MixedVec(params.genIntWriteBackBundle) 607 608 val fromVfWb: MixedVec[RfWritePortWithConfig] = MixedVec(params.genVfWriteBackBundle) 609 610 val fromIntExus = Flipped(intSchdParams.genExuOutputValidBundle) 611 612 val fromVfExus = Flipped(intSchdParams.genExuOutputValidBundle) 613 614 val debugIntRat = Input(Vec(32, UInt(intSchdParams.pregIdxWidth.W))) 615 val debugFpRat = Input(Vec(32, UInt(vfSchdParams.pregIdxWidth.W))) 616 val debugVecRat = Input(Vec(32, UInt(vfSchdParams.pregIdxWidth.W))) 617 val debugVconfigRat = Input(UInt(vfSchdParams.pregIdxWidth.W)) 618 val debugVconfig = Output(UInt(XLEN.W)) 619 620} 621