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

import chisel3._
import chisel3.util._
import xiangshan._
6
import utils._
7
import xiangshan.backend.exu.{Exu, ExuConfig}
8
import xiangshan.backend.regfile.RfReadPort
9
import scala.math.max
10

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

43
class RSCtrlDataIO(srcNum: Int) extends XSBundle {
44 45 46 47 48 49
  // 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())
50
  val srcUpdate = Input(Vec(IssQueSize+1, Vec(srcNum, Bool()))) // Note: the last one for enq
51 52
  val redVec    = Input(UInt(IssQueSize.W))
  val feedback  = Input(Vec(IssQueSize+1, Bool())) // Note: the last one for hit
53 54

  override def cloneType: RSCtrlDataIO.this.type = new RSCtrlDataIO(srcNum).asInstanceOf[this.type]
55 56
}

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

  val iqSize = IssQueSize
  val iqIdxWidth = log2Up(iqSize)
69
  val fastWakeup = fixedDelay >= 0 // NOTE: if do not enable fastWakeup(bypass), set fixedDelay to -1
70
  val nonBlocked = fastWakeup
71
  val srcNum = max(exuCfg.intSrcCnt, exuCfg.fpSrcCnt)
72 73
  require(srcNum >= 1 && srcNum <= 3)
  println(s"[RsCtrl]  ExuConfig: ${exuCfg.name} (srcNum = $srcNum)")
74 75

  val io = IO(new XSBundle {
76
    // flush
77 78
    val redirect = Flipped(ValidIO(new Redirect))

79
    // enq Ctrl sigs at dispatch-2, only use srcState
80 81
    val enqCtrl = Flipped(DecoupledIO(new MicroOp))

82
    // to DataPart
83
    val data = new RSCtrlDataIO(srcNum)
84 85 86 87 88

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

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  /* 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
   */

104

105 106 107 108 109 110 111 112 113
  val s_idle :: s_valid :: s_selected :: s_bubble :: s_wait :: s_replay :: Nil = Enum(6)
  /* state machine
   * s_idle     : empty slot, init state, set when deq
   * s_valid    : ready to be secleted
   * s_selected : the not bubble that selected
   * s_bubble   : the bubble that selected
   * s_wait     : wait for feedback
   * s_replay   : replay after some particular cycle
   */
114
  val stateQueue    = RegInit(VecInit(Seq.fill(iqSize)(s_idle)))
115 116
  val validQueue    = VecInit(stateQueue.map(_ === s_valid))
  val emptyQueue    = VecInit(stateQueue.map(_ === s_idle))
117
  val srcQueue      = Reg(Vec(iqSize, Vec(srcNum, Bool())))
118
  val cntQueue      = Reg(Vec(iqSize, UInt(log2Up(replayDelay).W)))
Z
ZhangZifei 已提交
119 120

  // rs queue part:
Z
ZhangZifei 已提交
121 122
  // val tailPtr       = RegInit(0.U((iqIdxWidth+1).W))
  val tailPtr       = RegInit(0.U.asTypeOf(new CircularQueuePtr(iqSize)))
123
  val idxQueue      = RegInit(VecInit((0 until iqSize).map(_.U(iqIdxWidth.W))))
124 125 126 127 128 129 130 131 132

  // 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 })
133

134
  // redirect
Z
ZhangZifei 已提交
135 136
  val redVec      = io.data.redVec
  val redVecPtr   = widthMap(i => io.data.redVec(idxQueue(i)))
137
  val fbMatchVec = Wire(UInt(iqSize.W))
138
  if (feedback) {
139 140 141
    fbMatchVec := widthMap(i => io.data.feedback(i) && (stateQueue(i) === s_wait || stateQueue(i)===s_valid)).asUInt
  } else {
    fbMatchVec := 0.U
142
  }
143
  val fbHit       = io.data.feedback(IssQueSize)
144

Z
ZhangZifei 已提交
145
  // select ready
Z
ZhangZifei 已提交
146 147
  // for no replay, select just equal to deq (attached)
  // with   replay, select is just two stage with deq.
148
  val issFire = Wire(Bool())
Z
ZhangZifei 已提交
149
  val moveMask = WireInit(0.U(iqSize.W))
150
  val selectMask = WireInit(VecInit((0 until iqSize).map(i => readyIdxQue(i))))
Z
ZhangZifei 已提交
151 152 153
  // val selIdx = ParallelMux(selectMask zip idxQueue) // NOTE: the idx in the idxQueue
  val (selPtr, haveReady) = PriorityEncoderWithFlag(selectMask) // NOTE: the idx of idxQueue
  val selIdx = idxQueue(selPtr)
154
  val selIdxReg = RegNext(selIdx) // NOTE: may dup with other signal, fix it later
Z
ZhangZifei 已提交
155
  val redSel = redVec(selIdx)
156
  val selValid = !redSel && haveReady
157
  val selReg = RegNext(selValid)
158
  val selPtrReg = RegNext(Mux(moveMask(selPtr), selPtr-1.U, selPtr))
Z
ZhangZifei 已提交
159

Z
ZhangZifei 已提交
160
  // sel bubble
161
  val bubMask = WireInit(VecInit((0 until iqSize).map(i => emptyIdxQue(i))))
162
  // val bubIdx = ParallelMux(bubMask zip idxQueue) // NOTE: the idx in the idxQueue
Z
ZhangZifei 已提交
163
  val (bubPtr, findBubble) = PriorityEncoderWithFlag(bubMask) // NOTE: the idx of the idxQueue
164
  val haveBubble = findBubble && (bubPtr < tailPtr.asUInt)
Z
ZhangZifei 已提交
165
  val bubIdx = idxQueue(bubPtr)
166
  val bubIdxReg = RegNext(bubIdx) // NOTE: may dup with other signal, fix it later
167
  val bubValid = haveBubble && (if (feedback) true.B else !selValid)
Z
ZhangZifei 已提交
168
  val bubReg = RegNext(bubValid)
169
  val bubPtrReg = RegNext(Mux(moveMask(bubPtr), bubPtr-1.U, bubPtr))
Z
ZhangZifei 已提交
170 171

  // deq
172 173 174
  val dequeue = if (feedback) bubReg
                else          bubReg || issFire
  val deqPtr =  if (feedback) bubPtrReg
175
                else Mux(selReg, selPtrReg, bubPtrReg)
Z
ZhangZifei 已提交
176
  moveMask := {
Z
ZhangZifei 已提交
177
    (Fill(iqSize, 1.U(1.W)) << deqPtr)(iqSize-1, 0)
178
  } & Fill(iqSize, dequeue)
Z
ZhangZifei 已提交
179

180
  // move, move happens when deq
181
  for(i <- 0 until iqSize-1){
Z
ZhangZifei 已提交
182
    when(moveMask(i)){
183
      idxQueue(i) := idxQueue(i+1)
Z
ZhangZifei 已提交
184 185
    }
  }
186
  when(dequeue){
Z
ZhangZifei 已提交
187
    idxQueue.last := idxQueue(deqPtr)
188
  }
189 190
  when (selValid) {
    stateQueue(selIdx) := s_selected
Z
ZhangZifei 已提交
191
  }
192
  when (bubValid) {
193
    stateQueue(bubIdx) := s_bubble
194 195
  }

Z
ZhangZifei 已提交
196
  // redirect and feedback && wakeup
197
  for (i <- 0 until iqSize) {
198 199 200
    // replay
    val cnt = cntQueue(i)
    when (stateQueue(i) === s_replay) {
201
      cnt := cnt - 1.U
202 203 204 205 206 207 208 209 210 211 212 213 214
      when (cnt === 0.U) { stateQueue(i) := s_valid }
    }
    // 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 已提交
215
      }
216
    }
217 218 219 220 221 222 223 224 225 226 227 228 229 230
    // mask last selectet slot and deal with the mask
    // TODO: state queu change may have long 'when' chain -> long latency
    when (stateQueue(i) === s_selected) {
      when (io.data.fuReady) {
        if (feedback) {
          stateQueue(i) := s_wait
        }  else {
          stateQueue(i) := s_idle
        }
      }.otherwise { stateQueue(i) := s_valid }
    }
    when (stateQueue(i) === s_bubble) {
      stateQueue(i) := s_idle
    }
Z
ZhangZifei 已提交
231
    // redirect
232
    when (redVec(i) && stateQueue(i) =/= s_idle) {
Z
ZhangZifei 已提交
233
      stateQueue(i) := s_idle
234
    }
235
  }
236

237
  // output
Z
ZhangZifei 已提交
238
  val issValid = selReg && !redVecPtr(selPtrReg)
239 240 241 242 243 244
  if (nonBlocked) {
    issFire := issValid
    assert(RegNext(io.data.fuReady), "if fu wanna fast wakeup, it should not block")
  } else {
    issFire := issValid && io.data.fuReady
  }
Z
ZhangZifei 已提交
245 246

  // enq
Z
ZhangZifei 已提交
247
  val isFull = tailPtr.flag
Y
Yinan Xu 已提交
248
  // agreement with dispatch: don't fire when io.redirect.valid
249 250 251 252
  val enqueue = io.enqCtrl.fire() && !io.redirect.valid
  val tailInc = tailPtr+1.U
  val tailDec = tailPtr-1.U
  tailPtr := Mux(dequeue === enqueue, tailPtr, Mux(dequeue, tailDec, tailInc))
253

Z
ZhangZifei 已提交
254
  io.enqCtrl.ready := !isFull || dequeue
255 256 257
  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)
258
  val srcStateSeq = Seq(enqUop.src1State, enqUop.src2State, enqUop.src3State)
259

Z
ZhangZifei 已提交
260
  val enqPtr = Mux(tailPtr.flag, deqPtr, tailPtr.value)
261
  val enqIdx = idxQueue(enqPtr)
262 263 264 265 266 267
  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)
  }
268

269
  when (enqueue) {
270 271
    stateQueue(enqIdx) := s_valid
    srcQueue(enqIdx).zipWithIndex.map{ case (s, i) =>
272
      s := Mux(enqBpVec(i) || stateCheck(srcSeq(i), srcTypeSeq(i)), true.B,
Z
ZhangZifei 已提交
273
               srcStateSeq(i)===SrcState.rdy)
274
    }
Z
ZhangZifei 已提交
275
    XSDebug(p"EnqCtrl: roqIdx:${enqUop.roqIdx} pc:0x${Hexadecimal(enqUop.cf.pc)} " +
276
      List.tabulate(srcNum)(i => p"<src$i: ${srcSeq(i)} state$i: ${srcStateSeq(i)} type$i: ${srcTypeSeq(i)}>").reduce(_ + " " + _) + "\n")
Z
ZhangZifei 已提交
277 278
  }

279
  // other to Data
280
  io.data.enqPtr := enqIdx
281
  io.data.deqPtr.valid  := selValid
Z
ZhangZifei 已提交
282
  io.data.deqPtr.bits   := selIdx
283
  io.data.enqCtrl.valid := enqueue
284
  io.data.enqCtrl.bits  := io.enqCtrl.bits
285

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

Z
ZhangZifei 已提交
289
  // assert
Z
ZhangZifei 已提交
290
  assert(RegNext(Mux(tailPtr.flag, tailPtr.value===0.U, true.B)))
Z
ZhangZifei 已提交
291

292 293
  val print = !(tailPtr.asUInt===0.U) || io.enqCtrl.valid || enqueue || dequeue
  XSDebug(print || true.B, p"In(${io.enqCtrl.valid} ${io.enqCtrl.ready}) Out(${issValid} ${io.data.fuReady}) nonBlocked:${nonBlocked.B} needfb:${feedback.B}\n")
294
  XSDebug(print , p"tailPtr:${tailPtr} enq:${enqueue} deq:${dequeue} isFull:${isFull} " +
295
    p"vIdxQue:${Binary(validIdxQue.asUInt)} rIdxQue:${Binary(readyIdxQue.asUInt)}\n")
Z
ZhangZifei 已提交
296
  XSDebug(print && Cat(redVecPtr).orR, p"Redirect: ${Hexadecimal(redVecPtr.asUInt)}\n")
297
  XSDebug(print && Cat(fbMatchVec).orR, p"Feedback: ${Hexadecimal(fbMatchVec.asUInt)} Hit:${fbHit}\n")
298
  XSDebug(print, p"moveMask:${Binary(moveMask)} selMask:${Binary(selectMask.asUInt)} bubMask:${Binary(bubMask.asUInt)}\n")
Z
ZhangZifei 已提交
299
  XSDebug(print, p"selIdxWire:${selPtr} haveReady:${haveReady} redSel:${redSel}" +
300
    p"selV:${selValid} selReg:${selReg} selPtrReg:${selPtrReg} selIdx:${selIdx} selIdxReg:${selIdxReg}\n")
301
  XSDebug(print, p"bubValid:${bubValid} haveBub:${haveBubble} bubPtr:${bubPtr} findBub:${findBubble} " +
302 303
    p"bubReg:${bubReg} bubPtrReg:${bubPtrReg} bubIdx:${bubIdx} bubIdxReg:${bubIdxReg}\n")
  XSDebug(print, p"issValid:${issValid} issueFire:${issFire} dequeue:${dequeue} deqPtr:${deqPtr}\n")
Z
ZhangZifei 已提交
304
  XSDebug(p" :Idx|v|r|s |cnt|s1:s2:s3\n")
Z
ZhangZifei 已提交
305
  for(i <- srcQueue.indices) {
306 307
    XSDebug(p"${i.U}: ${idxQueue(i)}|${validIdxQue(i)}|${readyIdxQue(i)}|${stateIdxQue(i)}|${cntIdxQue(i)}|" +
      List.tabulate(srcNum)(j => p"${srcIdxQue(i)(j)}").reduce(_ + ":" + _) + "\n")
Z
ZhangZifei 已提交
308
  }
309 310 311 312 313 314 315
}

class ReservationStationData
(
  val exuCfg: ExuConfig,
  wakeupCnt: Int,
  extraListenPortsCnt: Int,
316
  fixedDelay: Int,
317
  feedback: Boolean,
318 319 320
) extends XSModule {
  val iqSize = IssQueSize
  val iqIdxWidth = log2Up(iqSize)
321 322
  val fastWakeup = fixedDelay >= 0 // NOTE: if do not enable fastWakeup(bypass), set fixedDelay to -1
  val nonBlocked = fastWakeup
323
  val srcNum = max(exuCfg.intSrcCnt, exuCfg.fpSrcCnt)
324 325
  require(srcNum >= 1 && srcNum <= 3)
  println(s"[RsData]  ExuConfig: ${exuCfg.name} (srcNum = $srcNum)")
326 327 328

  val io = IO(new XSBundle {
    // flush
329
    val redirect = Flipped(ValidIO(new Redirect))
330 331

    // send to exu
332
    val deq = DecoupledIO(new ExuInput)
333 334

    // listen to RSCtrl
335
    val ctrl = Flipped(new RSCtrlDataIO(srcNum))
336

337
    // read src op value
338
    val srcRegValue = Vec(srcNum, Input(UInt((XLEN + 1).W)))
339 340 341 342 343
    // 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
344
    // are also in 'broadcastedUops'
345
    val broadcastedUops = Vec(wakeupCnt, Flipped(ValidIO(new MicroOp)))
346 347

    // listen to write back data bus(certain latency)
348
    // and extra write back(uncertain latency)
349
    val writeBackedData = Vec(wakeupCnt, Input(UInt((XLEN+1).W)))
350 351 352 353
    val extraListenPorts = Vec(extraListenPortsCnt, Flipped(ValidIO(new ExuOutput)))

    // tlb feedback
    val feedback = Flipped(ValidIO(new TlbFeedback))
354 355 356
  })

  val uop     = Reg(Vec(iqSize, new MicroOp))
357
  val data    = Reg(Vec(iqSize, Vec(srcNum, UInt((XLEN+1).W))))
358

359 360 361 362 363 364 365
  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
366
  val enqPtr = enq(log2Up(IssQueSize)-1,0)
Y
Yinan Xu 已提交
367 368
  val enqPtrReg = RegEnable(enqPtr, enqCtrl.valid)
  val enqEn  = enqCtrl.valid
369 370
  val enqEnReg = RegNext(enqEn)
  when (enqEn) {
371
    uop(enqPtr) := enqUop
Z
ZhangZifei 已提交
372 373 374
    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")
375
  }
376

377
  when (enqEnReg) {
378
    (0 until srcNum).foreach(i => data(enqPtrReg)(i) := io.srcRegValue(i))
379
    XSDebug(p"${exuCfg.name}: enqPtrReg:${enqPtrReg} pc: ${Hexadecimal(uop(enqPtrReg).cf.pc)}\n")
380
    XSDebug("[srcRegValue] " + List.tabulate(srcNum)(idx => p"src$idx: ${Hexadecimal(io.srcRegValue(idx))}").reduce(_ + " " + _) + "\n")
381 382
  }

383
  def wbHit(uop: MicroOp, src: UInt, srctype: UInt): Bool = {
384
    (src === uop.pdest) &&
385 386 387
    ((srctype === SrcType.reg && uop.ctrl.rfWen && src=/=0.U) ||
     (srctype === SrcType.fp  && uop.ctrl.fpWen))
  }
388

389
  // wakeup and bypass
390 391
  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)
392 393 394 395 396 397
    assert(RegNext(PopCount(hitVec)===0.U || PopCount(hitVec)===1.U))

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

398 399
  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)
400 401 402 403 404 405 406 407 408 409
    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)
410
    for (j <- 0 until srcNum) {
411 412 413 414
      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 }
415
      when (bpHitReg && !(enqPtrReg===i.U && enqEnReg)) { data(i)(j) := bpData }
416 417 418 419
      // 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
420 421 422
      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")
423 424 425 426
    }
  }

  // deq
427 428 429
  val exuInput = io.deq.bits
  exuInput := DontCare
  exuInput.uop := uop(deq)
430 431 432
  exuInput.src1 := Mux(uop(deq).ctrl.src1Type === SrcType.pc, SignExt(uop(deq).cf.pc, XLEN + 1), data(deq)(0))
  if (srcNum > 1) exuInput.src2 := Mux(uop(deq).ctrl.src2Type === SrcType.imm, uop(deq).ctrl.imm, data(deq)(1))
  if (srcNum > 2) exuInput.src3 := data(deq)(2)
433

434
  io.deq.valid := RegNext(sel.valid)
435
  if (nonBlocked) { assert(RegNext(io.deq.ready), s"${name} if fu wanna fast wakeup, it should not block")}
436 437 438 439 440

  // 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 已提交
441
    val (bpHit, bpHitReg, bpData)= bypass(srcSeq(i), srcTypeSeq(i), enqCtrl.valid)
442 443
    when (bpHitReg) { data(enqPtrReg)(i) := bpData }
    h := bpHit
444
    // NOTE: enq bp is done here
445 446 447
    XSDebug(bpHit, p"EnqBPHit: (${i.U})\n")
    XSDebug(bpHitReg, p"EnqBPHitData: (${i.U}) data:${Hexadecimal(bpData)}\n")
  }
448 449
  if (nonBlocked) { io.ctrl.fuReady := true.B }
  else { io.ctrl.fuReady := io.deq.ready }
450
  io.ctrl.redVec   := VecInit(uop.map(_.roqIdx.needFlush(io.redirect))).asUInt
451 452 453 454 455 456 457 458

  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
  }

459 460

  // bypass send
461 462 463 464 465 466 467 468 469 470 471 472
  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" )
473
  }
474

475

Z
ZhangZifei 已提交
476
  // log
Z
ZhangZifei 已提交
477
  XSDebug(io.ctrl.redVec.orR, p"Red: ${Binary(io.ctrl.redVec)}\n")
478
  XSDebug(io.feedback.valid && feedback.B, p"feedback: roqIdx:${io.feedback.bits.roqIdx} hit:${io.feedback.bits.hit}\n")
479
  XSDebug(true.B, p"out(${io.deq.valid} ${io.deq.ready})\n")
Z
ZhangZifei 已提交
480
  XSDebug(io.deq.valid, p"Deq(${io.deq.valid} ${io.deq.ready}): deqPtr:${deq} pc:${Hexadecimal(io.deq.bits.uop.cf.pc)}" +
481 482
    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 已提交
483
  XSDebug(p"Data:  | src1:data | src2:data | src3:data |hit|pdest:rf:fp| roqIdx | pc\n")
484
  for(i <- data.indices) {
Z
ZhangZifei 已提交
485
    XSDebug(p"${i.U}:|${uop(i).psrc1}:${Hexadecimal(data(i)(0))}|${uop(i).psrc2}:" +
486
      (if (srcNum > 1) p"${Hexadecimal(data(i)(1))}" else p"null") + p"|${uop(i).psrc3}:" + (if (srcNum > 2) p"${Hexadecimal(data(i)(2))}" else p"null") + p"|" +
Z
ZhangZifei 已提交
487 488
      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")
489
  }
490
}