FloatBlock.scala 6.8 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 32 33
    val wakeUpOut = Flipped(new WakeUpBundle(fastWakeUpOut.size, slowWakeUpOut.size))
    val outWriteFpRf = Vec(slowWakeUpIn.size, Flipped(DecoupledIO(new ExuOutput)))
    val fpWriteIntRf = Vec(slowWakeUpOut.count(_.writeIntRf), DecoupledIO(new ExuOutput))
L
LinJiawei 已提交
34 35 36

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

  val redirect = io.fromCtrlBlock.redirect
40
  val flush = io.fromCtrlBlock.flush
L
LinJiawei 已提交
41

42 43
  require(fastWakeUpIn.isEmpty)
  val wakeUpInReg = Wire(Flipped(new WakeUpBundle(fastWakeUpIn.size, slowWakeUpIn.size)))
44 45 46 47
  wakeUpInReg.slow.zip(io.wakeUpIn.slow).foreach{
    case(inReg, in) =>
      inReg.bits := RegEnable(in.bits, in.valid)
      inReg.valid := RegNext(in.valid && !in.bits.uop.roqIdx.needFlush(redirect, flush))
48 49 50 51 52 53
  }
  val wakeUpInRecode = WireInit(wakeUpInReg)
  for(i <- wakeUpInReg.slow.indices){
    if(i != 0){
      wakeUpInRecode.slow(i).bits.data := fpRdataHelper(wakeUpInReg.slow(i).bits.uop, wakeUpInReg.slow(i).bits.data)
    }
54
    wakeUpInRecode.slow(i).bits.redirectValid := false.B
55 56
  }

L
LinJiawei 已提交
57 58 59 60 61 62 63 64 65 66
  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 已提交
67 68 69
  fmacExeUnits.foreach(_.frm := io.frm)
  fmiscExeUnits.foreach(_.frm := io.frm)

L
LinJiawei 已提交
70 71 72 73 74 75 76 77
  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)

78 79
  // val readPortIndex = RegNext(io.fromCtrlBlock.readPortIndex)
  val readPortIndex = Seq(0, 1, 2, 3, 2, 3)
L
LinJiawei 已提交
80 81 82 83 84 85 86 87
  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

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

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

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

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

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

107
    rs.io.srcRegValue := DontCare
108 109 110
    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))
111 112 113 114 115

    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))

116
    rs.io.fastDatas <> inBlockWbData
117
    rs.io.slowPorts <> slowPorts
L
LinJiawei 已提交
118 119

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

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

126
    rs
L
LinJiawei 已提交
127 128 129 130 131 132
  })

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

140 141
  val (fmiscOut, fmiscOutReg) = exeUnits.filter(_.config.writeIntRf).map(e => {
    val input = WireInit(e.io.out)
142
    val outReg = Wire(DecoupledIO(new ExuOutput))
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    PipelineConnect(input, outReg, outReg.fire(), input.bits.uop.roqIdx.needFlush(redirect, flush))
    val outIeee = Wire(DecoupledIO(new ExuOutput))
    outReg.ready := outIeee.ready
    outIeee.valid := outReg.valid
    outIeee.bits := outReg.bits
    outIeee.bits.data := Mux(outReg.bits.uop.ctrl.fpWen, ieee(outReg.bits.data), outReg.bits.data)
    (input, outIeee)
  }).unzip
  io.fpWriteIntRf <> fmiscOutReg.map(o => {
    val toInt = intOutValid(o)
    o.ready := toInt.ready
    toInt
  })
  io.wakeUpOut.slow <> exeUnits.filterNot(_.config.writeIntRf).map(e => {
    val recodeOut = Wire(Valid(new ExuOutput))
    recodeOut.bits := RegEnable(e.io.out.bits, e.io.out.valid)
    recodeOut.valid := RegNext(e.io.out.valid, e.io.out.bits.uop.roqIdx.needFlush(redirect, flush))
    val ieeeOut = WireInit(recodeOut)
    ieeeOut.bits.data := ieee(recodeOut.bits.data)
    ieeeOut
  }) ++ fmiscOutReg.map(decoupledIOToValidIO)
L
LinJiawei 已提交
164

L
LinJiawei 已提交
165
  // read fp rf from ctrl block
Y
Yinan Xu 已提交
166
  fpRf.io.readPorts.zipWithIndex.map{ case (r, i) => r.addr := io.fromCtrlBlock.readRf(i) }
167 168 169
  (0 until exuParameters.StuCnt).foreach(i =>
    io.toMemBlock.readFpRf(i).data := RegNext(ieee(fpRf.io.readPorts(i + 12).data))
  )
L
LinJiawei 已提交
170
  // write fp rf arbiter
L
LinJiawei 已提交
171
  val fpWbArbiter = Module(new Wb(
L
LinJiawei 已提交
172 173 174
    (exeUnits.map(_.config) ++ fastWakeUpIn ++ slowWakeUpIn),
    NRFpWritePorts,
    isFp = true
L
LinJiawei 已提交
175
  ))
176 177 178 179 180 181 182 183
  fpWbArbiter.io.in <> exeUnits.map(e =>
    if(e.config.writeIntRf) WireInit(e.io.out) else e.io.out
  ) ++ io.outWriteFpRf

  exeUnits.zip(fpWbArbiter.io.in).filter(_._1.config.writeIntRf).zip(fmiscOut).foreach {
    case ((exu, wFp), wInt) =>
      exu.io.out.ready := wInt.fire() || wFp.fire()
  }
L
LinJiawei 已提交
184 185 186 187 188 189 190 191 192 193 194

  // 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 已提交
195
}