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