xref: /XiangShan/src/main/scala/xiangshan/backend/datapath/Og2ForVector.scala (revision 42b6cdf9744fdb03eb7e5a7e7505d0c89eb40abd)
1c38df446SzhanglyGitpackage xiangshan.backend.datapath
2c38df446SzhanglyGit
3c38df446SzhanglyGitimport org.chipsalliance.cde.config.Parameters
4c38df446SzhanglyGitimport chisel3._
5c38df446SzhanglyGitimport chisel3.util._
6c38df446SzhanglyGitimport utility._
7c38df446SzhanglyGitimport xiangshan._
8c38df446SzhanglyGitimport xiangshan.backend.BackendParams
9c38df446SzhanglyGitimport xiangshan.backend.Bundles._
10c38df446SzhanglyGitimport xiangshan.backend.issue.EntryBundles.{EntryDeqRespBundle, RespType}
11*42b6cdf9Ssinsanctionimport xiangshan.backend.issue.{MemScheduler, VfScheduler}
12*42b6cdf9Ssinsanctionimport xiangshan.mem.{SqPtr, LqPtr}
13c38df446SzhanglyGit
14c38df446SzhanglyGit
15c38df446SzhanglyGitclass Og2ForVector(params: BackendParams)(implicit p: Parameters) extends XSModule {
16c38df446SzhanglyGit  val io = IO(new Og2ForVectorIO(params))
17c38df446SzhanglyGit
18*42b6cdf9Ssinsanction  private val fromOg1             = io.fromOg1VfArith ++ io.fromOg1VecMem
19*42b6cdf9Ssinsanction  private val toExu               = io.toVfArithExu ++ io.toVecMemExu
20*42b6cdf9Ssinsanction  private val toIQOg2Resp         = io.toVfIQOg2Resp ++ io.toMemIQOg2Resp
21c38df446SzhanglyGit
22*42b6cdf9Ssinsanction  private val s1_validVec2        = fromOg1.map(_.map(_.valid))
23*42b6cdf9Ssinsanction  private val s1_dataVec2         = fromOg1.map(_.map(_.bits))
24*42b6cdf9Ssinsanction  private val s1_readyVec2        = fromOg1.map(_.map(_.ready))
25*42b6cdf9Ssinsanction  private val toExuFire           = toExu.map(_.map(_.fire))
26*42b6cdf9Ssinsanction  private val toExuReady          = toExu.map(_.map(_.ready))
27*42b6cdf9Ssinsanction  private val og2IQNum: Int       = fromOg1.size
28*42b6cdf9Ssinsanction  private val og2IQPerExuNum      = fromOg1.map(_.size).toSeq
29*42b6cdf9Ssinsanction
30*42b6cdf9Ssinsanction  val s2_toExuValid               = Reg(MixedVec(
31c38df446SzhanglyGit    s1_validVec2.map(x => MixedVec(x.map(_.cloneType).toSeq)).toSeq
32c38df446SzhanglyGit  ))
33*42b6cdf9Ssinsanction  val s2_toExuData                = Reg(MixedVec(
34c38df446SzhanglyGit    s1_dataVec2.map(x => MixedVec(x.map(_.cloneType).toSeq)).toSeq
35c38df446SzhanglyGit  ))
36c38df446SzhanglyGit
37*42b6cdf9Ssinsanction  for(i <- 0 until og2IQNum) {
38*42b6cdf9Ssinsanction    for (j <- 0 until og2IQPerExuNum(i)) {
39c38df446SzhanglyGit      val s2_flush = s1_dataVec2(i)(j).robIdx.needFlush(Seq(io.flush, RegNextWithEnable(io.flush)))
40c38df446SzhanglyGit      val s1_ldCancel = LoadShouldCancel(s1_dataVec2(i)(j).loadDependency, io.ldCancel)
41*42b6cdf9Ssinsanction      when(s1_validVec2(i)(j) && s1_readyVec2(i)(j) && !s2_flush && !s1_ldCancel) {
42*42b6cdf9Ssinsanction        s2_toExuValid(i)(j) := true.B
43*42b6cdf9Ssinsanction        s2_toExuData(i)(j) := s1_dataVec2(i)(j)
44*42b6cdf9Ssinsanction        s2_toExuData(i)(j).loadDependency.foreach(_ := s1_dataVec2(i)(j).loadDependency.get.map(_ << 1))
45c38df446SzhanglyGit      }.otherwise {
46*42b6cdf9Ssinsanction        s2_toExuValid(i)(j) := false.B
47c38df446SzhanglyGit      }
48*42b6cdf9Ssinsanction      s1_readyVec2(i)(j) := true.B
49*42b6cdf9Ssinsanction      toExu(i)(j).valid := s2_toExuValid(i)(j)
50*42b6cdf9Ssinsanction      toExu(i)(j).bits := s2_toExuData(i)(j)
51c38df446SzhanglyGit    }
52c38df446SzhanglyGit  }
53*42b6cdf9Ssinsanction  toIQOg2Resp.zipWithIndex.foreach {
54*42b6cdf9Ssinsanction    case (toIQ, iqId) =>
55*42b6cdf9Ssinsanction      toIQ.zipWithIndex.foreach {
56c38df446SzhanglyGit        case (og2Resp, exuId) =>
57*42b6cdf9Ssinsanction          val og2Failed = s2_toExuValid(iqId)(exuId) && !toExuReady(iqId)(exuId)
58*42b6cdf9Ssinsanction          og2Resp.valid := s2_toExuValid(iqId)(exuId)
59*42b6cdf9Ssinsanction          og2Resp.bits.robIdx := s2_toExuData(iqId)(exuId).robIdx
60*42b6cdf9Ssinsanction          og2Resp.bits.uopIdx.foreach(_ := s2_toExuData(iqId)(exuId).vpu.get.vuopIdx)
61*42b6cdf9Ssinsanction          og2Resp.bits.resp := Mux(og2Failed, RespType.block,
62*42b6cdf9Ssinsanction            if (og2Resp.bits.params match { case x => x.isVecMemIQ })
63*42b6cdf9Ssinsanction              RespType.uncertain
64*42b6cdf9Ssinsanction            else
65*42b6cdf9Ssinsanction              RespType.success
66*42b6cdf9Ssinsanction          )
67*42b6cdf9Ssinsanction          og2Resp.bits.fuType := s2_toExuData(iqId)(exuId).fuType
68*42b6cdf9Ssinsanction          og2Resp.bits.sqIdx.foreach(_ := 0.U.asTypeOf(new SqPtr))
69*42b6cdf9Ssinsanction          og2Resp.bits.lqIdx.foreach(_ := 0.U.asTypeOf(new LqPtr))
70c38df446SzhanglyGit      }
71c38df446SzhanglyGit  }
72*42b6cdf9Ssinsanction  io.toBypassNetworkImmInfo := io.fromOg1ImmInfo.zip(s1_validVec2.flatten).map{
73d1da1584Ssinsanction    case (imm, valid) => RegEnable(imm, valid)
74d1da1584Ssinsanction  }
75c38df446SzhanglyGit}
76c38df446SzhanglyGit
77c38df446SzhanglyGitclass Og2ForVectorIO(params: BackendParams)(implicit p: Parameters) extends XSBundle {
78c38df446SzhanglyGit  private val vfSchdParams = params.schdParams(VfScheduler())
79*42b6cdf9Ssinsanction  private val memSchdParams = params.schdParams(MemScheduler())
80c38df446SzhanglyGit
81c38df446SzhanglyGit  val flush: ValidIO[Redirect]                                    = Flipped(ValidIO(new Redirect))
82c38df446SzhanglyGit  val ldCancel                                                    = Vec(backendParams.LduCnt + backendParams.HyuCnt, Flipped(new LoadCancelIO))
83*42b6cdf9Ssinsanction
84*42b6cdf9Ssinsanction  val fromOg1VfArith: MixedVec[MixedVec[DecoupledIO[ExuInput]]]   = Flipped(vfSchdParams.genExuInputBundle)
85*42b6cdf9Ssinsanction  val fromOg1VecMem: MixedVec[MixedVec[DecoupledIO[ExuInput]]]    = Flipped(MixedVec(memSchdParams.issueBlockParams.filter(_.needOg2Resp).map(_.genExuInputDecoupledBundle)))
86*42b6cdf9Ssinsanction  val fromOg1ImmInfo: Vec[ImmInfo]                                = Input(Vec(params.allIssueParams.filter(_.needOg2Resp).flatMap(_.exuBlockParams).size, new ImmInfo))
87*42b6cdf9Ssinsanction
88*42b6cdf9Ssinsanction  val toVfArithExu                                                = MixedVec(vfSchdParams.genExuInputBundle)
89*42b6cdf9Ssinsanction  val toVecMemExu                                                 = MixedVec(memSchdParams.issueBlockParams.filter(_.needOg2Resp).map(_.genExuInputDecoupledBundle))
90*42b6cdf9Ssinsanction  val toVfIQOg2Resp                                               = MixedVec(vfSchdParams.issueBlockParams.map(_.genOG2RespBundle))
91*42b6cdf9Ssinsanction  val toMemIQOg2Resp                                              = MixedVec(memSchdParams.issueBlockParams.filter(_.needOg2Resp).map(_.genOG2RespBundle))
92*42b6cdf9Ssinsanction  val toBypassNetworkImmInfo: Vec[ImmInfo]                        = Output(Vec(params.allIssueParams.filter(_.needOg2Resp).flatMap(_.exuBlockParams).size, new ImmInfo))
93c38df446SzhanglyGit}