Dispatch.scala 5.3 KB
Newer Older
1 2 3 4 5
package xiangshan.backend.dispatch

import chisel3._
import chisel3.util._
import xiangshan._
L
LinJiawei 已提交
6
import utils._
7
import xiangshan.backend.regfile.RfReadPort
8
import chisel3.ExcitingUtils._
Y
Yinan Xu 已提交
9
import xiangshan.backend.roq.RoqPtr
10
import xiangshan.backend.rename.RenameBypassInfo
11

12 13 14 15 16 17 18 19
case class DispatchParameters
(
  DqEnqWidth: Int,
  IntDqSize: Int,
  FpDqSize: Int,
  LsDqSize: Int,
  IntDqDeqWidth: Int,
  FpDqDeqWidth: Int,
Y
Yinan Xu 已提交
20
  LsDqDeqWidth: Int
21 22
)

23
class Dispatch extends XSModule {
24
  val io = IO(new Bundle() {
L
LinJiawei 已提交
25
    // flush or replay
26 27 28
    val redirect = Flipped(ValidIO(new Redirect))
    // from rename
    val fromRename = Vec(RenameWidth, Flipped(DecoupledIO(new MicroOp)))
29
    val renameBypass = Input(new RenameBypassInfo)
Y
Yinan Xu 已提交
30 31
    // to busytable: set pdest to busy (not ready) when they are dispatched
    val allocPregs = Vec(RenameWidth, Output(new ReplayPregReq))
32
    // enq Roq
33 34
    val enqRoq = new Bundle {
      val canAccept = Input(Bool())
35
      val isEmpty = Input(Bool())
36 37 38 39
      val extraWalk = Vec(RenameWidth, Output(Bool()))
      val req = Vec(RenameWidth, ValidIO(new MicroOp))
      val resp = Vec(RenameWidth, Input(new RoqPtr))
    }
Y
Yinan Xu 已提交
40
    // enq Lsq
41 42 43 44 45
    val enqLsq = new Bundle() {
      val canAccept = Input(Bool())
      val req = Vec(RenameWidth, ValidIO(new MicroOp))
      val resp = Vec(RenameWidth, Input(new LSIdx))
    }
46
    // read regfile
47 48
    val readIntRf = Vec(NRIntReadPorts, Flipped(new RfReadPort))
    val readFpRf = Vec(NRFpReadPorts, Flipped(new RfReadPort))
49
    // read reg status (busy/ready)
50 51
    val intPregRdy = Vec(NRIntReadPorts, Input(Bool()))
    val fpPregRdy = Vec(NRFpReadPorts, Input(Bool()))
52
    // to reservation stations
53
    val numExist = Input(Vec(exuParameters.ExuCnt, UInt(log2Ceil(IssQueSize).W)))
L
LinJiawei 已提交
54
    val enqIQCtrl = Vec(exuParameters.ExuCnt, DecoupledIO(new MicroOp))
55
    val enqIQData = Vec(exuParameters.ExuCnt, Output(new ExuInput))
56
  })
57

58
  val dispatch1 = Module(new Dispatch1)
Y
Yinan Xu 已提交
59 60 61
  val intDq = Module(new DispatchQueue(dpParams.IntDqSize, dpParams.DqEnqWidth, dpParams.IntDqDeqWidth))
  val fpDq = Module(new DispatchQueue(dpParams.FpDqSize, dpParams.DqEnqWidth, dpParams.FpDqDeqWidth))
  val lsDq = Module(new DispatchQueue(dpParams.LsDqSize, dpParams.DqEnqWidth, dpParams.LsDqDeqWidth))
62

63 64
  // pipeline between rename and dispatch
  // accepts all at once
Y
Yinan Xu 已提交
65
  val redirectValid = io.redirect.valid// && !io.redirect.bits.isReplay
66
  for (i <- 0 until RenameWidth) {
67
    PipelineConnect(io.fromRename(i), dispatch1.io.fromRename(i), dispatch1.io.recv(i), redirectValid)
68 69 70
  }

  // dispatch 1: accept uops from rename and dispatch them to the three dispatch queues
71
  dispatch1.io.redirect <> io.redirect
72
  dispatch1.io.renameBypass := RegEnable(io.renameBypass, io.fromRename(0).valid && dispatch1.io.fromRename(0).ready)
73
  dispatch1.io.enqRoq <> io.enqRoq
74
  dispatch1.io.enqLsq <> io.enqLsq
75
  dispatch1.io.toIntDqReady <> intDq.io.enqReady
76
  dispatch1.io.toIntDq <> intDq.io.enq
77
  dispatch1.io.toFpDqReady <> fpDq.io.enqReady
78
  dispatch1.io.toFpDq <> fpDq.io.enq
79
  dispatch1.io.toLsDqReady <> lsDq.io.enqReady
80
  dispatch1.io.toLsDq <> lsDq.io.enq
Y
Yinan Xu 已提交
81
  dispatch1.io.allocPregs <> io.allocPregs
82

83 84
  // dispatch queue: queue uops and dispatch them to different reservation stations or issue queues
  // it may cancel the uops
85 86 87
  intDq.io.redirect <> io.redirect
  fpDq.io.redirect <> io.redirect
  lsDq.io.redirect <> io.redirect
88

89
  // Int dispatch queue to Int reservation stations
90
  val intDispatch = Module(new Dispatch2Int)
91
  intDispatch.io.fromDq <> intDq.io.deq
92 93
  intDispatch.io.readRf.zipWithIndex.map({case (r, i) => r <> io.readIntRf(i)})
  intDispatch.io.regRdy.zipWithIndex.map({case (r, i) => r <> io.intPregRdy(i)})
Y
Yinan Xu 已提交
94 95 96
  intDispatch.io.numExist.zipWithIndex.map({case (num, i) => num := io.numExist(i)})
  intDispatch.io.enqIQCtrl.zipWithIndex.map({case (enq, i) => enq <> io.enqIQCtrl(i)})
  intDispatch.io.enqIQData.zipWithIndex.map({case (enq, i) => enq <> io.enqIQData(i)})
97

98
  // Fp dispatch queue to Fp reservation stations
99
  val fpDispatch = Module(new Dispatch2Fp)
100 101 102 103 104 105
  fpDispatch.io.fromDq <> fpDq.io.deq
  fpDispatch.io.readRf.zipWithIndex.map({case (r, i) => r <> io.readFpRf(i)})
  fpDispatch.io.regRdy.zipWithIndex.map({case (r, i) => r <> io.fpPregRdy(i)})
  fpDispatch.io.numExist.zipWithIndex.map({case (num, i) => num := io.numExist(i + exuParameters.IntExuCnt)})
  fpDispatch.io.enqIQCtrl.zipWithIndex.map({case (enq, i) => enq <> io.enqIQCtrl(i + exuParameters.IntExuCnt)})
  fpDispatch.io.enqIQData.zipWithIndex.map({case (enq, i) => enq <> io.enqIQData(i + exuParameters.IntExuCnt)})
106
  
107
  // Load/store dispatch queue to load/store issue queues
108
  val lsDispatch = Module(new Dispatch2Ls)
109
  lsDispatch.io.fromDq <> lsDq.io.deq
110 111 112 113
  lsDispatch.io.readIntRf.zipWithIndex.map({case (r, i) => r <> io.readIntRf(i + 8)})
  lsDispatch.io.readFpRf.zipWithIndex.map({case (r, i) => r <> io.readFpRf(i + 12)})
  lsDispatch.io.intRegRdy.zipWithIndex.map({case (r, i) => r <> io.intPregRdy(i + 8)})
  lsDispatch.io.fpRegRdy.zipWithIndex.map({case (r, i) => r <> io.fpPregRdy(i + 12)})
Y
Yinan Xu 已提交
114 115
  lsDispatch.io.numExist.zipWithIndex.map({case (num, i) => num := io.numExist(exuParameters.IntExuCnt + exuParameters.FpExuCnt + i)})
  lsDispatch.io.enqIQCtrl.zipWithIndex.map({case (enq, i) => enq <> io.enqIQCtrl(exuParameters.IntExuCnt + exuParameters.FpExuCnt + i)})
116
  lsDispatch.io.enqIQData.zipWithIndex.map({case (enq, i) => enq <> io.enqIQData(exuParameters.IntExuCnt + exuParameters.FpExuCnt + i)})
117
}