FloatBlock.scala 6.0 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 22 23 24 25
  fastWakeUpIn: Seq[ExuConfig],
  slowWakeUpIn: Seq[ExuConfig],
  fastFpOut: Seq[ExuConfig],
  slowFpOut: Seq[ExuConfig],
  fastIntOut: Seq[ExuConfig],
  slowIntOut: Seq[ExuConfig]
26
) extends XSModule with HasExeBlockHelper with HasLoadHelper {
27 28 29
  val io = IO(new Bundle {
    val fromCtrlBlock = Flipped(new CtrlToFpBlockIO)
    val toCtrlBlock = new FpBlockToCtrlIO
30
    val toMemBlock = new FpBlockToMemBlockIO
Y
Yinan Xu 已提交
31

32 33 34
    val wakeUpIn = new WakeUpBundle(fastWakeUpIn.size, slowWakeUpIn.size)
    val wakeUpFpOut = Flipped(new WakeUpBundle(fastFpOut.size, slowFpOut.size))
    val wakeUpIntOut = Flipped(new WakeUpBundle(fastIntOut.size, slowIntOut.size))
L
LinJiawei 已提交
35 36 37

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

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

43 44 45 46 47 48 49 50 51 52 53 54 55
  require(fastWakeUpIn.isEmpty)
  val wakeUpInReg = Wire(Flipped(new WakeUpBundle(fastWakeUpIn.size, slowWakeUpIn.size)))
  for((in, inReg) <- io.wakeUpIn.slow.zip(wakeUpInReg.slow)){
    inReg.ready := true.B
    PipelineConnect(in, inReg, inReg.fire(), in.bits.uop.roqIdx.needFlush(redirect, flush))
  }
  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)
    }
  }

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

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

77 78
  // val readPortIndex = RegNext(io.fromCtrlBlock.readPortIndex)
  val readPortIndex = Seq(0, 1, 2, 3, 2, 3)
L
LinJiawei 已提交
79 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

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

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

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

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

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

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

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

115
    rs.io.fastDatas <> inBlockWbData
116
    for ((x, y) <- rs.io.slowPorts.zip(slowPorts)) {
L
LinJiawei 已提交
117 118 119 120 121
      x.valid := y.fire()
      x.bits := y.bits
    }

    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
  def connectAndConvertToIEEE(in: DecoupledIO[ExuOutput]) = {
    val outReg = Wire(DecoupledIO(new ExuOutput))
    outReg.ready := true.B
    PipelineConnect(in, outReg, outReg.fire(), in.bits.uop.roqIdx.needFlush(redirect, flush))
    val outIeee = WireInit(outReg)
    outIeee.bits.data := ieee(outReg.bits.data)
    outIeee
  }
L
LinJiawei 已提交
150

151
  io.wakeUpFpOut.slow <> exeUnits.filter(_.config.writeFpRf).map(_.io.toFp).map(connectAndConvertToIEEE)
L
LinJiawei 已提交
152

153
  io.wakeUpIntOut.slow <> exeUnits.filter(_.config.writeIntRf).map(_.io.toInt)
L
LinJiawei 已提交
154 155


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

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