FloatBlock.scala 6.3 KB
Newer Older
1 2 3 4 5
package xiangshan.backend

import chisel3._
import chisel3.util._
import xiangshan._
6
import utils._
7 8
import xiangshan.backend.regfile.Regfile
import xiangshan.backend.exu._
9 10
import xiangshan.backend.issue.ReservationStation
import xiangshan.mem.HasLoadHelper
11 12 13


class FpBlockToCtrlIO extends XSBundle {
L
LinJiawei 已提交
14
  val wbRegs = Vec(NRFpWritePorts, ValidIO(new ExuOutput))
15 16 17
  val numExist = Vec(exuParameters.FpExuCnt, Output(UInt(log2Ceil(IssQueSize).W)))
}

L
LinJiawei 已提交
18 19
class FloatBlock
(
20 21
  fastWakeUpIn: Seq[ExuConfig],
  slowWakeUpIn: Seq[ExuConfig],
22 23
  fastWakeUpOut: Seq[ExuConfig],
  slowWakeUpOut: Seq[ExuConfig],
24
) extends XSModule with HasExeBlockHelper with HasLoadHelper {
25 26 27
  val io = IO(new Bundle {
    val fromCtrlBlock = Flipped(new CtrlToFpBlockIO)
    val toCtrlBlock = new FpBlockToCtrlIO
28
    val toMemBlock = new FpBlockToMemBlockIO
Y
Yinan Xu 已提交
29

30
    val wakeUpIn = new WakeUpBundle(fastWakeUpIn.size, slowWakeUpIn.size)
31
    val wakeUpOut = Flipped(new WakeUpBundle(fastWakeUpOut.size, slowWakeUpOut.size))
L
LinJiawei 已提交
32 33 34

    // from csr
    val frm = Input(UInt(3.W))
Y
Yinan Xu 已提交
35
  })
L
LinJiawei 已提交
36 37

  val redirect = io.fromCtrlBlock.redirect
38
  val flush = io.fromCtrlBlock.flush
L
LinJiawei 已提交
39

40 41
  require(fastWakeUpIn.isEmpty)
  val wakeUpInReg = Wire(Flipped(new WakeUpBundle(fastWakeUpIn.size, slowWakeUpIn.size)))
42
  wakeUpInReg.slow.zip(io.wakeUpIn.slow).foreach{
43 44
    case (inReg, in) =>
      PipelineConnect(in, inReg, inReg.fire(), in.bits.uop.roqIdx.needFlush(redirect, flush))
45 46
  }
  val wakeUpInRecode = WireInit(wakeUpInReg)
47 48 49 50 51 52 53
  for(((rec, reg), cfg) <- wakeUpInRecode.slow.zip(wakeUpInReg.slow).zip(slowWakeUpIn)){
    rec.bits.data := {
      if(cfg == Exu.ldExeUnitCfg) fpRdataHelper(reg.bits.uop, reg.bits.data)
      else Mux(reg.bits.uop.ctrl.fpu.typeTagOut === S,
        recode(reg.bits.data(31, 0), S),
        recode(reg.bits.data(63, 0), D)
      )
54
    }
55 56
    rec.bits.redirectValid := false.B
    reg.ready := rec.ready
57 58
  }

L
LinJiawei 已提交
59 60 61 62 63 64 65 66 67 68
  val fpRf = Module(new Regfile(
    numReadPorts = NRFpReadPorts,
    numWirtePorts = NRFpWritePorts,
    hasZero = false,
    len = XLEN + 1
  ))

  val fmacExeUnits = Array.tabulate(exuParameters.FmacCnt)(_ => Module(new FmacExeUnit))
  val fmiscExeUnits = Array.tabulate(exuParameters.FmiscCnt)(_ => Module(new FmiscExeUnit))

L
LinJiawei 已提交
69 70 71
  fmacExeUnits.foreach(_.frm := io.frm)
  fmiscExeUnits.foreach(_.frm := io.frm)

L
LinJiawei 已提交
72 73 74 75 76 77 78 79
  val exeUnits = fmacExeUnits ++ fmiscExeUnits

  def needWakeup(cfg: ExuConfig): Boolean =
    (cfg.readIntRf && cfg.writeIntRf) || (cfg.readFpRf && cfg.writeFpRf)

  def needData(a: ExuConfig, b: ExuConfig): Boolean =
    (a.readIntRf && b.writeIntRf) || (a.readFpRf && b.writeFpRf)

80 81
  // val readPortIndex = RegNext(io.fromCtrlBlock.readPortIndex)
  val readPortIndex = Seq(0, 1, 2, 3, 2, 3)
L
LinJiawei 已提交
82 83 84 85 86 87 88 89
  val reservedStations = exeUnits.map(_.config).zipWithIndex.map({ case (cfg, i) =>
    var certainLatency = -1
    if (cfg.hasCertainLatency) {
      certainLatency = cfg.latency.latencyVal.get
    }

    val readFpRf = cfg.readFpRf

90
    val inBlockWbData = exeUnits.filter(e => e.config.hasCertainLatency).map(_.io.out.bits.data)
91
    val fastPortsCnt = inBlockWbData.length
L
LinJiawei 已提交
92

93 94
    val inBlockListenPorts = exeUnits.filter(e => e.config.hasUncertainlatency).map(_.io.out)
    val slowPorts = (inBlockListenPorts ++ wakeUpInRecode.slow).map(decoupledIOToValidIO)
95
    val slowPortsCnt = slowPorts.length
L
LinJiawei 已提交
96

97 98
    println(s"${i}: exu:${cfg.name} fastPortsCnt: ${fastPortsCnt} " +
      s"slowPorts: ${slowPortsCnt} " +
L
LinJiawei 已提交
99 100 101
      s"delay:${certainLatency}"
    )

102
    val rs = Module(new ReservationStation(cfg, XLEN + 1, fastPortsCnt, slowPortsCnt, fixedDelay = certainLatency, fastWakeup = certainLatency >= 0, feedback = false))
L
LinJiawei 已提交
103

104
    rs.io.redirect <> redirect // TODO: remove it
Z
ZhangZifei 已提交
105
    rs.io.flush <> flush // TODO: remove it
106 107
    rs.io.numExist <> io.toCtrlBlock.numExist(i)
    rs.io.fromDispatch <> io.fromCtrlBlock.enqIqCtrl(i)
108

109
    rs.io.srcRegValue := DontCare
110 111 112
    val src1Value = VecInit((0 until 4).map(i => fpRf.io.readPorts(i * 3).data))
    val src2Value = VecInit((0 until 4).map(i => fpRf.io.readPorts(i * 3 + 1).data))
    val src3Value = VecInit((0 until 4).map(i => fpRf.io.readPorts(i * 3 + 2).data))
113 114 115 116 117

    rs.io.srcRegValue(0) := src1Value(readPortIndex(i))
    rs.io.srcRegValue(1) := src2Value(readPortIndex(i))
    if (cfg.fpSrcCnt > 2) rs.io.srcRegValue(2) := src3Value(readPortIndex(i))

118
    rs.io.fastDatas <> inBlockWbData
119
    rs.io.slowPorts <> slowPorts
L
LinJiawei 已提交
120 121

    exeUnits(i).io.redirect <> redirect
122
    exeUnits(i).io.flush <> flush
123
    exeUnits(i).io.fromFp <> rs.io.deq
124
    // rs.io.memfeedback := DontCare
L
LinJiawei 已提交
125

126
    rs.suggestName(s"rs_${cfg.name}")
L
LinJiawei 已提交
127

128
    rs
L
LinJiawei 已提交
129 130 131 132 133 134
  })

  for(rs <- reservedStations){
    val inBlockUops = reservedStations.filter(x =>
      x.exuCfg.hasCertainLatency && x.exuCfg.writeFpRf
    ).map(x => {
135 136
      val raw = WireInit(x.io.fastUopOut)
      raw.valid := x.io.fastUopOut.valid && raw.bits.ctrl.fpWen
L
LinJiawei 已提交
137 138
      raw
    })
139
    rs.io.fastUopsIn <> inBlockUops
L
LinJiawei 已提交
140 141
  }

142 143 144 145 146 147 148 149 150 151 152 153
  val (recodeOut, ieeeOutReg) = exeUnits.map(e => {
    val rec = WireInit(e.io.out)
    val recReg = Wire(DecoupledIO(new ExuOutput))
    PipelineConnect(
      rec, recReg, recReg.fire(),
      rec.bits.uop.roqIdx.needFlush(redirect, flush)
    )
    val ieeeReg = WireInit(recReg)
    recReg.ready := ieeeReg.ready
    ieeeReg.bits.data := Mux(recReg.bits.uop.ctrl.fpWen, ieee(recReg.bits.data), recReg.bits.data)
    ieeeReg.bits.redirectValid := false.B
    (rec, ieeeReg)
154
  }).unzip
155 156

  io.wakeUpOut.slow <> ieeeOutReg
L
LinJiawei 已提交
157

L
LinJiawei 已提交
158
  // read fp rf from ctrl block
Y
Yinan Xu 已提交
159
  fpRf.io.readPorts.zipWithIndex.map{ case (r, i) => r.addr := io.fromCtrlBlock.readRf(i) }
160 161 162
  (0 until exuParameters.StuCnt).foreach(i =>
    io.toMemBlock.readFpRf(i).data := RegNext(ieee(fpRf.io.readPorts(i + 12).data))
  )
L
LinJiawei 已提交
163
  // write fp rf arbiter
L
LinJiawei 已提交
164
  val fpWbArbiter = Module(new Wb(
L
LinJiawei 已提交
165 166 167
    (exeUnits.map(_.config) ++ fastWakeUpIn ++ slowWakeUpIn),
    NRFpWritePorts,
    isFp = true
L
LinJiawei 已提交
168
  ))
169 170
  fpWbArbiter.io.in <> exeUnits.map(e =>
    if(e.config.writeIntRf) WireInit(e.io.out) else e.io.out
171
  ) ++ wakeUpInRecode.slow
172

173 174
  exeUnits.zip(recodeOut).zip(fpWbArbiter.io.in).filter(_._1._1.config.writeIntRf).foreach {
    case ((exu, wInt), wFp) =>
175 176
      exu.io.out.ready := wInt.fire() || wFp.fire()
  }
L
LinJiawei 已提交
177 178 179 180 181 182 183 184 185 186 187

  // set busytable and update roq
  io.toCtrlBlock.wbRegs <> fpWbArbiter.io.out

  fpRf.io.writePorts.zip(fpWbArbiter.io.out).foreach{
    case (rf, wb) =>
      rf.wen := wb.valid && wb.bits.uop.ctrl.fpWen
      rf.addr := wb.bits.uop.pdest
      rf.data := wb.bits.data
  }

Z
ZhangZifei 已提交
188
}