ReservationStationNew.scala 18.4 KB
Newer Older
1 2 3 4 5
package xiangshan.backend.issue

import chisel3._
import chisel3.util._
import xiangshan._
6
import utils._
7 8
import xiangshan.backend.exu.{Exu, ExuConfig}

9 10 11 12
class BypassQueue(number: Int) extends XSModule {
  val io = IO(new Bundle {
    val in  = Flipped(ValidIO(new MicroOp))
    val out = ValidIO(new MicroOp)
13
    val redirect = Flipped(ValidIO(new Redirect))
14
  })
15 16 17 18
  if (number < 0) {
    io.out.valid := false.B
    io.out.bits := DontCare
  } else if(number == 0) {
19
    io.in <> io.out
20
    io.out.valid := io.in.valid
21
  } else {
22
    val queue = Seq.fill(number)(RegInit(0.U.asTypeOf(new Bundle{
23 24 25 26 27
      val valid = Bool()
      val bits = new MicroOp
    })))
    queue(0).valid := io.in.valid
    queue(0).bits  := io.in.bits
28
    (0 until (number-1)).map{i =>
29 30 31
      queue(i+1) := queue(i)
      queue(i+1).valid := queue(i).valid && !queue(i).bits.roqIdx.needFlush(io.redirect)
    }
32
    io.out.valid := queue(number-1).valid
33
    io.out.bits := queue(number-1).bits
34
    for (i <- 0 until number) {
35
      XSDebug(queue(i).valid, p"BPQue(${i.U}): pc:${Hexadecimal(queue(i).bits.cf.pc)} roqIdx:${queue(i).bits.roqIdx}" +
36
        p" pdest:${queue(i).bits.pdest} rfWen:${queue(i).bits.ctrl.rfWen} fpWen${queue(i).bits.ctrl.fpWen}\n")
37
    }
Z
ZhangZifei 已提交
38 39
  }
}
40

41 42 43 44 45 46 47 48 49 50 51 52
class RSCtrlDataIO extends XSBundle {
  // TODO: current: Ctrl to Data, next: Data to Ctrl
  val enqPtr = Output(UInt(log2Up(IssQueSize).W))
  val deqPtr = ValidIO(UInt(log2Up(IssQueSize).W)) // one cycle earlier
  val enqCtrl = ValidIO(new MicroOp)

  val fuReady   = Input(Bool())
  val srcUpdate = Input(Vec(IssQueSize+1, Vec(3, Bool()))) // Note: the last one for enq
  val redVec    = Input(UInt(IssQueSize.W))
  val feedback  = Input(Vec(IssQueSize+1, Bool())) // Note: the last one for hit
}

53
class ReservationStationCtrl
54 55 56
(
  val exuCfg: ExuConfig,
  wakeupCnt: Int,
57
  extraListenPortsCnt: Int,
58
  srcNum: Int = 3,
59
  feedback: Boolean,
60
  fixedDelay: Int,
61
  replayDelay: Int = 10
Z
ZhangZifei 已提交
62
) extends XSModule with HasCircularQueuePtrHelper {
63 64 65

  val iqSize = IssQueSize
  val iqIdxWidth = log2Up(iqSize)
66
  val fastWakeup = fixedDelay >= 0 // NOTE: if do not enable fastWakeup(bypass), set fixedDelay to -1
67
  val nonBlocked = fastWakeup
68 69

  val io = IO(new XSBundle {
70
    // flush
71 72
    val redirect = Flipped(ValidIO(new Redirect))

73
    // enq Ctrl sigs at dispatch-2, only use srcState
74 75
    val enqCtrl = Flipped(DecoupledIO(new MicroOp))

76
    // to DataPart
77
    val data = new RSCtrlDataIO
78 79 80 81 82

    // to Dispatch
    val numExist = Output(UInt(iqIdxWidth.W))
  })

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
  /* there two kind of data
   * 0 : indexed by indexed queue, such as data queue
   * 1 : indexed like indexed queue
   * TODO : all the queue turn to 0 type except indexed queue
   */

  /* queue in ctrl part
   * index queue : index
   * state queue : use for replay
   * valid queue : from state queue, valid or not
   * empty queue : from state queue, empty or not(not valid and not replay)
   * src   queue : record rdy or not
   * cnt   queue : record replay cycle
   */

98 99

  val s_idle :: s_valid :: s_wait :: s_replay :: Nil = Enum(4)
100

101
  val needFeedback  = if (feedback) true.B else false.B
102
  val notBlock      = if (nonBlocked) true.B else false.B
103
  val stateQueue    = RegInit(VecInit(Seq.fill(iqSize)(s_idle)))
104 105
  val validQueue    = VecInit(stateQueue.map(_ === s_valid))
  val emptyQueue    = VecInit(stateQueue.map(_ === s_idle))
106
  val srcQueue      = Reg(Vec(iqSize, Vec(srcNum, Bool())))
107
  val cntQueue      = Reg(Vec(iqSize, UInt(log2Up(replayDelay).W)))
Z
ZhangZifei 已提交
108 109

  // rs queue part:
Z
ZhangZifei 已提交
110 111
  // val tailPtr       = RegInit(0.U((iqIdxWidth+1).W))
  val tailPtr       = RegInit(0.U.asTypeOf(new CircularQueuePtr(iqSize)))
112
  val idxQueue      = RegInit(VecInit((0 until iqSize).map(_.U(iqIdxWidth.W))))
113 114 115 116 117 118 119 120 121

  // turn to indexed index
  def widthMap[T <: Data](f: Int => T) = VecInit((0 until iqSize).map(f))
  val stateIdxQue = widthMap(i => stateQueue(idxQueue(i))) // NOTE: only use for debug, remove it later
  val validIdxQue = widthMap(i => validQueue(idxQueue(i)))
  val emptyIdxQue = widthMap(i => emptyQueue(idxQueue(i)))
  val srcIdxQue   = widthMap(i => srcQueue(idxQueue(i)))
  val cntIdxQue   = widthMap(i => cntQueue(idxQueue(i))) // NOTE: only use for debug, remove it later
  val readyIdxQue = VecInit(srcIdxQue.zip(validIdxQue).map{ case (a,b) => Cat(a).andR & b })
122

123
  // redirect
124 125 126
  val redHit      = io.data.redVec
  val redHitIdx   = widthMap(i => io.data.redVec(idxQueue(i)))
  val fbMatchVec  = widthMap(i => needFeedback && io.data.feedback(i) && (stateQueue(i) === s_wait || stateQueue(i)===s_valid))
127
  val fbHit       = io.data.feedback(IssQueSize)
128

Z
ZhangZifei 已提交
129
  // select ready
Z
ZhangZifei 已提交
130 131
  // for no replay, select just equal to deq (attached)
  // with   replay, select is just two stage with deq.
132
  val issFire = Wire(Bool())
Z
ZhangZifei 已提交
133 134 135 136
  val moveMask = WireInit(0.U(iqSize.W))
  val selectedIdxRegOH = Wire(UInt(iqSize.W))
  val selectMask = WireInit(VecInit(
    (0 until iqSize).map(i =>
137
      readyIdxQue(i) && Mux(notBlock, true.B, !(selectedIdxRegOH(i) && (issFire)))
138
      // NOTE: if nonBlocked, then change state at sel stage
Z
ZhangZifei 已提交
139 140
    )
  ))
141
  val haveBubble = Wire(Bool())
Z
ZhangZifei 已提交
142
  val (selectedIdxWire, selected) = PriorityEncoderWithFlag(selectMask)
143
  val redSel = redHitIdx(selectedIdxWire)
144
  val selValid = !redSel && selected && !haveBubble
145
  val selReg = RegNext(selValid)
Z
ZhangZifei 已提交
146 147
  val selectedIdxReg = RegNext(selectedIdxWire - moveMask(selectedIdxWire))
  selectedIdxRegOH := UIntToOH(selectedIdxReg)
Z
ZhangZifei 已提交
148

Z
ZhangZifei 已提交
149 150 151 152
  // sel bubble
  // TODO:
  val bubIdxRegOH = Wire(UInt(iqSize.W))
  val bubMask = WireInit(VecInit(
153
    (0 until iqSize).map(i => emptyIdxQue(i) && !bubIdxRegOH(i) &&
154 155
                              Mux(notBlock, !selectedIdxRegOH(i), true.B)
  )))
Z
ZhangZifei 已提交
156
  val (firstBubble, findBubble) = PriorityEncoderWithFlag(bubMask)
Z
ZhangZifei 已提交
157
  haveBubble := findBubble && (firstBubble < tailPtr.asUInt)
Z
ZhangZifei 已提交
158 159 160 161 162 163
  val bubValid = haveBubble
  val bubReg = RegNext(bubValid)
  val bubIdxReg = RegNext(firstBubble - moveMask(firstBubble))
  bubIdxRegOH := UIntToOH(bubIdxReg)

  // deq
164
  // TODO: divide needFeedback and not needFeedback
165
  // TODO: mem's rs will issue but not deq( the bub), so just divide issue and deq
166
  val deqValid = bubReg/*fire an bubble*/ || (issFire && !needFeedback/*fire an rdy*/)
Z
ZhangZifei 已提交
167
  val deqIdx = Mux(bubReg, bubIdxReg, selectedIdxReg) // TODO: may have one more cycle delay than fire slot
Z
ZhangZifei 已提交
168
  moveMask := {
169
    (Fill(iqSize, 1.U(1.W)) << deqIdx)(iqSize-1, 0)
Z
ZhangZifei 已提交
170
  } & Fill(iqSize, deqValid)
Z
ZhangZifei 已提交
171

172
  // move, move happens when deq
173
  for(i <- 0 until iqSize-1){
Z
ZhangZifei 已提交
174
    when(moveMask(i)){
175
      idxQueue(i) := idxQueue(i+1)
Z
ZhangZifei 已提交
176 177
    }
  }
178
  // before issue and fu do not block and do not need feedback, reset state queue
179
  when (notBlock && selValid) { // if notBlock, disable at select stage
180
    stateQueue(idxQueue(selectedIdxWire)) := s_idle
181
  }
182
  // when deq, reset index queue and state queue
183 184
  when(deqValid){
    idxQueue.last := idxQueue(deqIdx)
185
    stateQueue(idxQueue(deqIdx)) := s_idle
Z
ZhangZifei 已提交
186
  }
187
  // when issue, but need feedback, set state queue
188
  when (issFire && needFeedback) {
189
    stateQueue(idxQueue(selectedIdxReg)) := s_wait
190 191
  }

192

Z
ZhangZifei 已提交
193
  // redirect and feedback && wakeup
194
  for (i <- 0 until iqSize) {
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    // replay
    val cnt = cntQueue(i)
    when (stateQueue(i) === s_replay) {
      when (cnt === 0.U) { stateQueue(i) := s_valid }
      .otherwise { cnt := cnt - 1.U }
    }
    // feedback
    when (fbMatchVec(i)) {
      stateQueue(i) := Mux(fbHit, s_idle, s_replay)
      cntQueue(i) := Mux(fbHit, cnt, (replayDelay-1).U)
    }
    // wakeup
    val hitVec = io.data.srcUpdate(i)
    for (j <- 0 until srcNum) {
      when (hitVec(j) && validQueue(i)) {
        srcQueue(i)(j) := true.B
        XSDebug(p"srcHit: i:${i.U} j:${j.U} src:${srcQueue(i)(j)}\n")
Z
ZhangZifei 已提交
212
      }
213
    }
Z
ZhangZifei 已提交
214 215 216 217
    // redirect
    when (redHit(i)) {
      stateQueue(i) := s_idle
    }
218
  }
219

220
  // output
221
  val issValid = selReg && !redHitIdx(selectedIdxReg)
222
  issFire := issValid && Mux(notBlock, true.B, io.data.fuReady)
223
  if (nonBlocked) { assert(RegNext(io.data.fuReady), "if fu wanna fast wakeup, it should not block")}
Z
ZhangZifei 已提交
224 225

  // enq
226
  val tailAfterRealDeq = tailPtr - (issFire && !needFeedback|| bubReg)
Z
ZhangZifei 已提交
227
  val isFull = tailAfterRealDeq.flag // tailPtr===qsize.U
Y
Yinan Xu 已提交
228 229 230
  // agreement with dispatch: don't fire when io.redirect.valid
  val enqFire = io.enqCtrl.fire() && !io.redirect.valid
  tailPtr := tailAfterRealDeq + enqFire
231

Y
Yinan Xu 已提交
232
  io.enqCtrl.ready := !isFull
233 234 235
  val enqUop      = io.enqCtrl.bits
  val srcSeq      = Seq(enqUop.psrc1, enqUop.psrc2, enqUop.psrc3)
  val srcTypeSeq  = Seq(enqUop.ctrl.src1Type, enqUop.ctrl.src2Type, enqUop.ctrl.src3Type)
236
  val srcStateSeq = Seq(enqUop.src1State, enqUop.src2State, enqUop.src3State)
237

238 239
  val enqPtr = Mux(tailPtr.flag, deqIdx, tailPtr.value)
  val enqIdx = idxQueue(enqPtr)
240 241 242 243 244 245
  val enqBpVec = io.data.srcUpdate(IssQueSize)

  def stateCheck(src: UInt, srcType: UInt): Bool = {
    (srcType =/= SrcType.reg && srcType =/= SrcType.fp) ||
    (srcType === SrcType.reg && src === 0.U)
  }
246

Y
Yinan Xu 已提交
247
  when (enqFire) {
248 249
    stateQueue(enqIdx) := s_valid
    srcQueue(enqIdx).zipWithIndex.map{ case (s, i) =>
250
      s := Mux(enqBpVec(i) || stateCheck(srcSeq(i), srcTypeSeq(i)), true.B,
Z
ZhangZifei 已提交
251
               srcStateSeq(i)===SrcState.rdy)
252
    }
Z
ZhangZifei 已提交
253
    XSDebug(p"EnqCtrl: roqIdx:${enqUop.roqIdx} pc:0x${Hexadecimal(enqUop.cf.pc)} " +
254 255 256
      p"src1:${srcSeq(0)} state:${srcStateSeq(0)} type:${srcTypeSeq(0)} src2:${srcSeq(1)} " +
      p" state:${srcStateSeq(1)} type:${srcTypeSeq(1)} src3:${srcSeq(2)} state:${srcStateSeq(2)} " +
      p"type:${srcTypeSeq(2)}\n")
Z
ZhangZifei 已提交
257 258
  }

259
  // other to Data
260
  io.data.enqPtr := enqIdx
261 262
  io.data.deqPtr.valid  := selValid
  io.data.deqPtr.bits   := idxQueue(selectedIdxWire)
Y
Yinan Xu 已提交
263
  io.data.enqCtrl.valid := enqFire
264
  io.data.enqCtrl.bits  := io.enqCtrl.bits
265

266
  // other io
Z
ZhangZifei 已提交
267
  io.numExist := Mux(tailPtr.flag, (iqSize-1).U, tailPtr.value) // NOTE: numExist is iqIdxWidth.W, maybe a bug
268

Z
ZhangZifei 已提交
269
  // assert
Z
ZhangZifei 已提交
270
  assert(RegNext(Mux(tailPtr.flag, tailPtr.value===0.U, true.B)))
Z
ZhangZifei 已提交
271

Z
ZhangZifei 已提交
272
  val print = !(tailPtr.asUInt===0.U) || io.enqCtrl.valid
273
  XSDebug(print || true.B, p"In(${io.enqCtrl.valid} ${io.enqCtrl.ready}) Out(${issValid} ${io.data.fuReady}) notBlock:${notBlock} needfb:${needFeedback}\n")
Z
ZhangZifei 已提交
274
  XSDebug(print , p"tailPtr:${tailPtr} tailPtrAdq:${tailAfterRealDeq} isFull:${isFull} " +
275 276 277
    p"needFeed:${needFeedback} vIdxQue:${Binary(validIdxQue.asUInt)} rIdxQue:${Binary(readyIdxQue.asUInt)}\n")
  XSDebug(print && Cat(redHitIdx).orR, p"Redirect: ${Hexadecimal(redHitIdx.asUInt)}\n")
  XSDebug(print && Cat(fbMatchVec).orR, p"Feedback: ${Hexadecimal(fbMatchVec.asUInt)} Hit:${fbHit}\n")
Z
ZhangZifei 已提交
278 279 280 281 282
  XSDebug(print, p"moveMask:${Binary(moveMask)} selMask:${Binary(selectMask.asUInt)} haveBub:${haveBubble}\n")
  XSDebug(print, p"selIdxWire:${selectedIdxWire} selected:${selected} redSel:${redSel}" +
    p"selV:${selValid} selReg:${selReg} selIdxReg:${selectedIdxReg} selIdxRegOH:${Binary(selectedIdxRegOH)}\n")
  XSDebug(print, p"bubMask:${Binary(bubMask.asUInt)} firstBub:${firstBubble} findBub:${findBubble} " +
    p"bubReg:${bubReg} bubIdxReg:${bubIdxReg} bubIdxRegOH:${Binary(bubIdxRegOH)}\n")
283
  XSDebug(print, p"issValid:${issValid} issueFire:${issFire} deqValid:${deqValid} deqIdx:${deqIdx}\n")
Z
ZhangZifei 已提交
284
  XSDebug(p" :Idx|v|r|s |cnt|s1:s2:s3\n")
Z
ZhangZifei 已提交
285
  for(i <- srcQueue.indices) {
286 287
    XSDebug(p"${i.U}: ${idxQueue(i)}|${validIdxQue(i)}|${readyIdxQue(i)}|${stateIdxQue(i)}|" +
      p"${cntIdxQue(i)}|${srcIdxQue(i)(0)}:${srcIdxQue(i)(1)}:${srcIdxQue(i)(2)}\n")
Z
ZhangZifei 已提交
288
  }
289 290 291 292 293 294 295
}

class ReservationStationData
(
  val exuCfg: ExuConfig,
  wakeupCnt: Int,
  extraListenPortsCnt: Int,
296
  fixedDelay: Int,
297
  feedback: Boolean,
298 299
  srcNum: Int = 3
) extends XSModule {
300

301 302
  val iqSize = IssQueSize
  val iqIdxWidth = log2Up(iqSize)
303 304 305
  val fastWakeup = fixedDelay >= 0 // NOTE: if do not enable fastWakeup(bypass), set fixedDelay to -1
  val nonBlocked = fastWakeup
  val notBlock   = if (nonBlocked) true.B else false.B
306 307 308

  val io = IO(new XSBundle {
    // flush
309
    val redirect = Flipped(ValidIO(new Redirect))
310 311 312 313 314

    // enq Data at next cycle (regfile has 1 cycle latency)
    val enqData = Input(new ExuInput)

    // send to exu
315
    val deq = DecoupledIO(new ExuInput)
316 317

    // listen to RSCtrl
318 319 320 321 322 323 324 325 326
    val ctrl = Flipped(new RSCtrlDataIO)

    // broadcast selected uop to other issue queues
    val selectedUop = ValidIO(new MicroOp)

    // recv broadcasted uops form any relative issue queue,
    // to simplify wake up logic, the uop broadcasted by this queue self
    // are also in 'boradcastedUops'
    val broadcastedUops = Vec(wakeupCnt, Flipped(ValidIO(new MicroOp)))
327 328

    // listen to write back data bus(certain latency)
329
    // and extra wrtie back(uncertan latency)
330
    val writeBackedData = Vec(wakeupCnt, Input(UInt(XLEN.W)))
331 332 333 334
    val extraListenPorts = Vec(extraListenPortsCnt, Flipped(ValidIO(new ExuOutput)))

    // tlb feedback
    val feedback = Flipped(ValidIO(new TlbFeedback))
335 336 337
  })

  val uop     = Reg(Vec(iqSize, new MicroOp))
338
  val data    = Reg(Vec(iqSize, Vec(srcNum, UInt(XLEN.W))))
339

340
  // TODO: change srcNum
341

342 343 344 345 346 347 348
  val enq   = io.ctrl.enqPtr
  val sel   = io.ctrl.deqPtr
  val deq   = RegEnable(sel.bits, sel.valid)
  val enqCtrl = io.ctrl.enqCtrl
  val enqUop = enqCtrl.bits

  // enq
349
  val enqPtr = enq(log2Up(IssQueSize)-1,0)
Y
Yinan Xu 已提交
350 351
  val enqPtrReg = RegEnable(enqPtr, enqCtrl.valid)
  val enqEn  = enqCtrl.valid
352 353
  val enqEnReg = RegNext(enqEn)
  when (enqEn) {
354
    uop(enqPtr) := enqUop
Z
ZhangZifei 已提交
355 356 357
    XSDebug(p"enqCtrl: enqPtr:${enqPtr} src1:${enqUop.psrc1}|${enqUop.src1State}|${enqUop.ctrl.src1Type}" +
      p" src2:${enqUop.psrc2}|${enqUop.src2State}|${enqUop.ctrl.src2Type} src3:${enqUop.psrc3}|" +
      p"${enqUop.src3State}|${enqUop.ctrl.src3Type} pc:0x${Hexadecimal(enqUop.cf.pc)} roqIdx:${enqUop.roqIdx}\n")
358
  }
359
  when (enqEnReg) { // TODO: turn to srcNum, not the 3
360 361 362
    data(enqPtrReg)(0) := io.enqData.src1
    data(enqPtrReg)(1) := io.enqData.src2
    data(enqPtrReg)(2) := io.enqData.src3
Z
ZhangZifei 已提交
363
    XSDebug(p"enqData: enqPtrReg:${enqPtrReg} src1:${Hexadecimal(io.enqData.src1)}" +
364
            p" src2:${Hexadecimal(io.enqData.src2)} src3:${Hexadecimal(io.enqData.src2)}\n")
365 366
  }

367
  def wbHit(uop: MicroOp, src: UInt, srctype: UInt): Bool = {
368
    (src === uop.pdest) &&
369 370 371
    ((srctype === SrcType.reg && uop.ctrl.rfWen && src=/=0.U) ||
     (srctype === SrcType.fp  && uop.ctrl.fpWen))
  }
372

373
  // wakeup and bypass
374 375
  def wakeup(src: UInt, srcType: UInt, valid: Bool = true.B) : (Bool, UInt) = {
    val hitVec = io.extraListenPorts.map(port => wbHit(port.bits.uop, src, srcType) && port.valid && valid)
376 377 378 379 380 381
    assert(RegNext(PopCount(hitVec)===0.U || PopCount(hitVec)===1.U))

    val hit = ParallelOR(hitVec)
    (hit, ParallelMux(hitVec zip io.extraListenPorts.map(_.bits.data)))
  }

382 383
  def bypass(src: UInt, srcType: UInt, valid: Bool = true.B) : (Bool, Bool, UInt) = {
    val hitVec = io.broadcastedUops.map(port => wbHit(port.bits, src, srcType) && port.valid && valid)
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
    assert(RegNext(PopCount(hitVec)===0.U || PopCount(hitVec)===1.U))

    val hit = ParallelOR(hitVec)
    (hit, RegNext(hit), ParallelMux(hitVec.map(RegNext(_)) zip io.writeBackedData))
  }

  io.ctrl.srcUpdate.map(a => a.map(_ := false.B))
  for (i <- 0 until iqSize) {
    val srcSeq = Seq(uop(i).psrc1, uop(i).psrc2, uop(i).psrc3)
    val srcTypeSeq = Seq(uop(i).ctrl.src1Type, uop(i).ctrl.src2Type, uop(i).ctrl.src3Type)
    for (j <- 0 until 3) {
      val (wuHit, wuData) = wakeup(srcSeq(j), srcTypeSeq(j))
      val (bpHit, bpHitReg, bpData) = bypass(srcSeq(j), srcTypeSeq(j))
      when (wuHit || bpHit) { io.ctrl.srcUpdate(i)(j) := true.B }
      when (wuHit) { data(i)(j) := wuData }
399
      when (bpHitReg && !(enqPtrReg===i.U && enqEnReg)) { data(i)(j) := bpData }
400 401 402 403
      // NOTE: the hit is from data's info, so there is an erro that:
      //       when enq, hit use last instr's info not the enq info.
      //       it will be long latency to add correct here, so add it to ctrl or somewhere else
      //       enq bp is done at below
404 405 406
      XSDebug(wuHit, p"WUHit: (${i.U})(${j.U}) Data:0x${Hexadecimal(wuData)}\n")
      XSDebug(bpHit, p"BPHit: (${i.U})(${j.U})\n")
      XSDebug(bpHitReg, p"BPHitData: (${i.U})(${j.U}) Data:0x${Hexadecimal(bpData)}\n")
407 408 409 410 411 412 413 414
    }
  }

  // deq
  io.deq.bits.uop  := uop(deq)
  io.deq.bits.src1 := data(deq)(0)
  io.deq.bits.src2 := data(deq)(1)
  io.deq.bits.src3 := data(deq)(2)
415
  io.deq.valid := RegNext(sel.valid)
416
  if (nonBlocked) { assert(RegNext(io.deq.ready), s"${name} if fu wanna fast wakeup, it should not block")}
417 418 419 420 421

  // to ctrl
  val srcSeq = Seq(enqUop.psrc1, enqUop.psrc2, enqUop.psrc3)
  val srcTypeSeq = Seq(enqUop.ctrl.src1Type, enqUop.ctrl.src2Type, enqUop.ctrl.src3Type)
  io.ctrl.srcUpdate(IssQueSize).zipWithIndex.map{ case (h, i) =>
Y
Yinan Xu 已提交
422
    val (bpHit, bpHitReg, bpData)= bypass(srcSeq(i), srcTypeSeq(i), enqCtrl.valid)
423 424
    when (bpHitReg) { data(enqPtrReg)(i) := bpData }
    h := bpHit
425
    // NOTE: enq bp is done here
426 427 428
    XSDebug(bpHit, p"EnqBPHit: (${i.U})\n")
    XSDebug(bpHitReg, p"EnqBPHitData: (${i.U}) data:${Hexadecimal(bpData)}\n")
  }
429
  io.ctrl.fuReady  := Mux(notBlock, true.B, io.deq.ready)
430
  io.ctrl.redVec   := VecInit(uop.map(_.roqIdx.needFlush(io.redirect))).asUInt
431 432 433 434 435 436 437 438

  io.ctrl.feedback := DontCare
  if (feedback) {
    (0 until IssQueSize).map(i =>
      io.ctrl.feedback(i) := uop(i).roqIdx.asUInt === io.feedback.bits.roqIdx.asUInt && io.feedback.valid)
    io.ctrl.feedback(IssQueSize) := io.feedback.bits.hit
  }

439 440

  // bypass send
441 442 443 444 445 446 447 448 449 450 451 452
  io.selectedUop <> DontCare
  if (fastWakeup) {
    val bpQueue = Module(new BypassQueue(fixedDelay))
    bpQueue.io.in.valid := sel.valid // FIXME: error when function is blocked => fu should not be blocked
    bpQueue.io.in.bits := uop(sel.bits)
    bpQueue.io.redirect := io.redirect
    io.selectedUop.valid := bpQueue.io.out.valid
    io.selectedUop.bits  := bpQueue.io.out.bits

    XSDebug(io.selectedUop.valid, p"SelUop: pc:0x${Hexadecimal(io.selectedUop.bits.cf.pc)}" +
      p" roqIdx:${io.selectedUop.bits.roqIdx} pdest:${io.selectedUop.bits.pdest} " +
      p"rfWen:${io.selectedUop.bits.ctrl.rfWen} fpWen:${io.selectedUop.bits.ctrl.fpWen}\n" )
453
  }
454

455

Z
ZhangZifei 已提交
456
  // log
Z
ZhangZifei 已提交
457
  XSDebug(io.ctrl.redVec.orR, p"Red: ${Binary(io.ctrl.redVec)}\n")
Z
ZhangZifei 已提交
458
  XSDebug(io.feedback.valid, p"feedback: roqIdx:${io.feedback.bits.roqIdx} hit:${io.feedback.bits.hit}\n")
459
  XSDebug(true.B, p"out(${io.deq.valid} ${io.deq.ready})\n")
Z
ZhangZifei 已提交
460
  XSDebug(io.deq.valid, p"Deq(${io.deq.valid} ${io.deq.ready}): deqPtr:${deq} pc:${Hexadecimal(io.deq.bits.uop.cf.pc)}" +
461 462
    p" roqIdx:${io.deq.bits.uop.roqIdx} src1:${Hexadecimal(io.deq.bits.src1)} " +
    p" src2:${Hexadecimal(io.deq.bits.src2)} src3:${Hexadecimal(io.deq.bits.src3)}\n")
Z
ZhangZifei 已提交
463
  XSDebug(p"Data:  | src1:data | src2:data | src3:data |hit|pdest:rf:fp| roqIdx | pc\n")
464
  for(i <- data.indices) {
Z
ZhangZifei 已提交
465 466 467 468
    XSDebug(p"${i.U}:|${uop(i).psrc1}:${Hexadecimal(data(i)(0))}|${uop(i).psrc2}:" +
      p"${Hexadecimal(data(i)(1))}|${uop(i).psrc3}:${Hexadecimal(data(i)(2))}|" +
      p"${Binary(io.ctrl.srcUpdate(i).asUInt)}|${uop(i).pdest}:${uop(i).ctrl.rfWen}:" +
      p"${uop(i).ctrl.fpWen}|${uop(i).roqIdx} |${Hexadecimal(uop(i).cf.pc)}\n")
469
  }
470
}