FloatBlock.scala 5.7 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._
Z
ZhangZifei 已提交
9
import xiangshan.backend.issue.{ReservationStationCtrl, ReservationStationData}
10 11 12


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

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

31 32 33
    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 已提交
34 35 36

    // from csr
    val frm = Input(UInt(3.W))
Y
Yinan Xu 已提交
37
  })
L
LinJiawei 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50

  val redirect = io.fromCtrlBlock.redirect

  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 已提交
51 52 53
  fmacExeUnits.foreach(_.frm := io.frm)
  fmiscExeUnits.foreach(_.frm := io.frm)

L
LinJiawei 已提交
54 55 56 57 58 59 60 61
  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)

62
  val readPortIndex = RegNext(io.fromCtrlBlock.readPortIndex)
L
LinJiawei 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  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)
    val writeBackData = inBlockWbData ++ io.wakeUpIn.fast.map(_.bits.data)
    val wakeupCnt = writeBackData.length

    val inBlockListenPorts = exeUnits.filter(e => e.config.hasUncertainlatency && readFpRf).map(_.io.toFp)
    val extraListenPorts = inBlockListenPorts ++ io.wakeUpIn.slow
    val extraListenPortsCnt = extraListenPorts.length

    println(s"${i}: exu:${cfg.name} wakeupCnt: ${wakeupCnt} " +
      s"extraListenPorts: ${extraListenPortsCnt} " +
      s"delay:${certainLatency}"
    )

Z
ZhangZifei 已提交
84 85
    val rsCtrl = Module(new ReservationStationCtrl(cfg, wakeupCnt, extraListenPortsCnt, fixedDelay = certainLatency, feedback = false))
    val rsData = Module(new ReservationStationData(cfg, wakeupCnt, extraListenPortsCnt, fixedDelay = certainLatency, feedback = false))
L
LinJiawei 已提交
86

Z
ZhangZifei 已提交
87 88 89 90
    rsCtrl.io.data <> rsData.io.ctrl
    rsCtrl.io.redirect <> redirect // TODO: remove it
    rsCtrl.io.numExist <> io.toCtrlBlock.numExist(i)
    rsCtrl.io.enqCtrl <> io.fromCtrlBlock.enqIqCtrl(i)
91 92

    rsData.io.srcRegValue := DontCare
Y
YikeZhou 已提交
93 94 95 96
    val srcIndex = List.tabulate(3)(Range(_, 12, 3).map(_.U))
    rsData.io.srcRegValue(0) := fpRf.io.readPorts(LookupTree(readPortIndex(i), (0 until 4).map(_.U).zip(srcIndex(0)))).data
    rsData.io.srcRegValue(1) := fpRf.io.readPorts(LookupTree(readPortIndex(i), (0 until 4).map(_.U).zip(srcIndex(1)))).data
    rsData.io.srcRegValue(2) := fpRf.io.readPorts(LookupTree(readPortIndex(i), (0 until 4).map(_.U).zip(srcIndex(2)))).data
Z
ZhangZifei 已提交
97
    rsData.io.redirect <> redirect
L
LinJiawei 已提交
98

Z
ZhangZifei 已提交
99 100
    rsData.io.writeBackedData <> writeBackData
    for ((x, y) <- rsData.io.extraListenPorts.zip(extraListenPorts)) {
L
LinJiawei 已提交
101 102 103 104 105
      x.valid := y.fire()
      x.bits := y.bits
    }

    exeUnits(i).io.redirect <> redirect
Z
ZhangZifei 已提交
106 107
    exeUnits(i).io.fromFp <> rsData.io.deq
    rsData.io.feedback := DontCare
L
LinJiawei 已提交
108

Z
ZhangZifei 已提交
109 110
    rsCtrl.suggestName(s"rsc_${cfg.name}")
    rsData.suggestName(s"rsd_${cfg.name}")
L
LinJiawei 已提交
111

Z
ZhangZifei 已提交
112
    rsData
L
LinJiawei 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  })

  for(rs <- reservedStations){
    val inBlockUops = reservedStations.filter(x =>
      x.exuCfg.hasCertainLatency && x.exuCfg.writeFpRf
    ).map(x => {
      val raw = WireInit(x.io.selectedUop)
      raw.valid := x.io.selectedUop.valid && raw.bits.ctrl.fpWen
      raw
    })
    rs.io.broadcastedUops <> inBlockUops ++ io.wakeUpIn.fastUops
  }

  io.wakeUpFpOut.fastUops <> reservedStations.filter(
    rs => fpFastFilter(rs.exuCfg)
128
  ).map(_.io.selectedUop).map(fpValid)
L
LinJiawei 已提交
129 130 131 132 133 134 135 136 137 138 139

  io.wakeUpFpOut.fast <> exeUnits.filter(
    x => fpFastFilter(x.config)
  ).map(_.io.toFp)

  io.wakeUpFpOut.slow <> exeUnits.filter(
    x => fpSlowFilter(x.config)
  ).map(_.io.toFp)

  io.wakeUpIntOut.fastUops <> reservedStations.filter(
    rs => intFastFilter(rs.exuCfg)
140
  ).map(_.io.selectedUop).map(intValid)
L
LinJiawei 已提交
141 142 143 144 145 146 147 148 149 150

  io.wakeUpIntOut.fast <> exeUnits.filter(
    x => intFastFilter(x.config)
  ).map(_.io.toInt)

  io.wakeUpIntOut.slow <> exeUnits.filter(
    x => intSlowFilter(x.config)
  ).map(_.io.toInt)


L
LinJiawei 已提交
151
  // read fp rf from ctrl block
L
LinJiawei 已提交
152
  fpRf.io.readPorts <> io.fromCtrlBlock.readRf
153
  (0 until exuParameters.StuCnt).foreach(i => io.toMemBlock.readFpRf(i).data := fpRf.io.readPorts(i + 12).data)
L
LinJiawei 已提交
154
  // write fp rf arbiter
L
LinJiawei 已提交
155
  val fpWbArbiter = Module(new Wb(
L
LinJiawei 已提交
156
    (exeUnits.map(_.config) ++ fastWakeUpIn ++ slowWakeUpIn).map(_.wbFpPriority),
L
LinJiawei 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170
    NRFpWritePorts
  ))
  fpWbArbiter.io.in <> exeUnits.map(_.io.toFp) ++ io.wakeUpIn.fast ++ io.wakeUpIn.slow

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