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