ReservationStationNew.scala 18.8 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 100 101 102 103 104 105 106 107
  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
   */
108
  val stateQueue    = RegInit(VecInit(Seq.fill(iqSize)(s_idle)))
109 110
  val validQueue    = VecInit(stateQueue.map(_ === s_valid))
  val emptyQueue    = VecInit(stateQueue.map(_ === s_idle))
111
  val srcQueue      = Reg(Vec(iqSize, Vec(srcNum, Bool())))
112
  val cntQueue      = Reg(Vec(iqSize, UInt(log2Up(replayDelay).W)))
Z
ZhangZifei 已提交
113 114

  // rs queue part:
Z
ZhangZifei 已提交
115 116
  // val tailPtr       = RegInit(0.U((iqIdxWidth+1).W))
  val tailPtr       = RegInit(0.U.asTypeOf(new CircularQueuePtr(iqSize)))
117
  val idxQueue      = RegInit(VecInit((0 until iqSize).map(_.U(iqIdxWidth.W))))
118 119 120 121 122 123 124 125 126

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

128
  // redirect
Z
ZhangZifei 已提交
129 130
  val redVec      = io.data.redVec
  val redVecPtr   = widthMap(i => io.data.redVec(idxQueue(i)))
131
  val fbMatchVec = Wire(UInt(iqSize.W))
132
  if (feedback) {
133 134 135
    fbMatchVec := widthMap(i => io.data.feedback(i) && (stateQueue(i) === s_wait || stateQueue(i)===s_valid)).asUInt
  } else {
    fbMatchVec := 0.U
136
  }
137
  val fbHit       = io.data.feedback(IssQueSize)
138

Z
ZhangZifei 已提交
139
  // select ready
Z
ZhangZifei 已提交
140 141
  // for no replay, select just equal to deq (attached)
  // with   replay, select is just two stage with deq.
142
  val issFire = Wire(Bool())
Z
ZhangZifei 已提交
143
  val moveMask = WireInit(0.U(iqSize.W))
144
  val selectMask = WireInit(VecInit((0 until iqSize).map(i => readyIdxQue(i))))
145
  val haveBubble = Wire(Bool())
Z
ZhangZifei 已提交
146 147 148
  // 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)
149
  val selIdxReg = RegNext(selIdx) // NOTE: may dup with other signal, fix it later
Z
ZhangZifei 已提交
150 151
  val redSel = redVec(selIdx)
  val selValid = !redSel && haveReady && !haveBubble
152
  val selReg = RegNext(selValid)
Z
ZhangZifei 已提交
153
  val selPtrReg = RegNext(selPtr - moveMask(selPtr)) // TODO: deal with the long latency
Z
ZhangZifei 已提交
154

Z
ZhangZifei 已提交
155
  // sel bubble
156
  val bubMask = WireInit(VecInit((0 until iqSize).map(i => emptyIdxQue(i))))
157
  // val bubIdx = ParallelMux(bubMask zip idxQueue) // NOTE: the idx in the idxQueue
Z
ZhangZifei 已提交
158 159
  val (bubPtr, findBubble) = PriorityEncoderWithFlag(bubMask) // NOTE: the idx of the idxQueue
  haveBubble := findBubble && (bubPtr < tailPtr.asUInt)
Z
ZhangZifei 已提交
160
  val bubIdx = idxQueue(bubPtr)
161
  val bubIdxReg = RegNext(bubIdx) // NOTE: may dup with other signal, fix it later
Z
ZhangZifei 已提交
162 163
  val bubValid = haveBubble
  val bubReg = RegNext(bubValid)
Z
ZhangZifei 已提交
164
  val bubPtrReg = RegNext(bubPtr - moveMask(bubPtr)) // TODO: deal with the long latency
Z
ZhangZifei 已提交
165 166

  // deq
167
  // TODO: mem's rs will issue but not deq( the bub), so just divide issue and deq
Z
ZhangZifei 已提交
168
  // TODO: when need feadback, only deq when becomes bubble
169
  val dequeue = if (feedback) bubReg else bubReg || issFire
Z
ZhangZifei 已提交
170
  val deqPtr = Mux(bubReg, bubPtrReg, selPtrReg)
Z
ZhangZifei 已提交
171
  moveMask := {
Z
ZhangZifei 已提交
172
    (Fill(iqSize, 1.U(1.W)) << deqPtr)(iqSize-1, 0)
173
  } & Fill(iqSize, dequeue)
Z
ZhangZifei 已提交
174

175
  // move, move happens when deq
176
  for(i <- 0 until iqSize-1){
Z
ZhangZifei 已提交
177
    when(moveMask(i)){
178
      idxQueue(i) := idxQueue(i+1)
Z
ZhangZifei 已提交
179 180
    }
  }
181
  when(dequeue){
Z
ZhangZifei 已提交
182
    idxQueue.last := idxQueue(deqPtr)
Z
ZhangZifei 已提交
183
  }
184 185 186 187 188 189
  when (selValid) {
    stateQueue(selIdx) := s_selected
    // TODO: may have long latency
  }
  when (haveBubble) {
    stateQueue(bubIdx) := s_bubble
190 191
  }

192 193 194 195 196 197 198 199 200 201 202 203
  when (stateQueue(selIdxReg) === s_selected) {
    when (io.data.fuReady) {
      if (feedback) {
        stateQueue(selIdxReg) := s_wait
      } else {
        stateQueue(selIdxReg) := s_idle
      }
    }.otherwise { stateQueue(selIdxReg) := s_valid } // fu is not ready and re-select next cycle
  }
  when (stateQueue(bubIdxReg) === s_bubble) {
    stateQueue(bubIdxReg) := s_idle // move the bubble to the last positon
  }
204

Z
ZhangZifei 已提交
205
  // redirect and feedback && wakeup
206
  for (i <- 0 until iqSize) {
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
    // 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 已提交
224
      }
225
    }
Z
ZhangZifei 已提交
226
    // redirect
227
    when (redVec(i) && stateQueue(i) =/= s_idle) {
Z
ZhangZifei 已提交
228 229
      stateQueue(i) := s_idle
    }
230
  }
231

232
  // output
Z
ZhangZifei 已提交
233
  val issValid = selReg && !redVecPtr(selPtrReg)
234 235 236 237 238 239
  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 已提交
240 241

  // enq
242
  val isFull = tailPtr.flag && !dequeue
Y
Yinan Xu 已提交
243
  // agreement with dispatch: don't fire when io.redirect.valid
244 245 246 247
  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))
248

Y
Yinan Xu 已提交
249
  io.enqCtrl.ready := !isFull
250 251 252
  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)
253
  val srcStateSeq = Seq(enqUop.src1State, enqUop.src2State, enqUop.src3State)
254

Z
ZhangZifei 已提交
255
  val enqPtr = Mux(tailPtr.flag, deqPtr, tailPtr.value)
256
  val enqIdx = idxQueue(enqPtr)
257 258 259 260 261 262
  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)
  }
263

264
  when (enqueue) {
265 266
    stateQueue(enqIdx) := s_valid
    srcQueue(enqIdx).zipWithIndex.map{ case (s, i) =>
267
      s := Mux(enqBpVec(i) || stateCheck(srcSeq(i), srcTypeSeq(i)), true.B,
Z
ZhangZifei 已提交
268
               srcStateSeq(i)===SrcState.rdy)
269
    }
Z
ZhangZifei 已提交
270
    XSDebug(p"EnqCtrl: roqIdx:${enqUop.roqIdx} pc:0x${Hexadecimal(enqUop.cf.pc)} " +
271 272 273
      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 已提交
274 275
  }

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

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

Z
ZhangZifei 已提交
286
  // assert
Z
ZhangZifei 已提交
287
  assert(RegNext(Mux(tailPtr.flag, tailPtr.value===0.U, true.B)))
Z
ZhangZifei 已提交
288

289 290
  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")
291
  XSDebug(print , p"tailPtr:${tailPtr} enq:${enqueue} deq:${dequeue} isFull:${isFull} " +
292
    p"vIdxQue:${Binary(validIdxQue.asUInt)} rIdxQue:${Binary(readyIdxQue.asUInt)}\n")
Z
ZhangZifei 已提交
293
  XSDebug(print && Cat(redVecPtr).orR, p"Redirect: ${Hexadecimal(redVecPtr.asUInt)}\n")
294
  XSDebug(print && Cat(fbMatchVec).orR, p"Feedback: ${Hexadecimal(fbMatchVec.asUInt)} Hit:${fbHit}\n")
295
  XSDebug(print, p"moveMask:${Binary(moveMask)} selMask:${Binary(selectMask.asUInt)} bubMask:${Binary(bubMask.asUInt)}\n")
Z
ZhangZifei 已提交
296
  XSDebug(print, p"selIdxWire:${selPtr} haveReady:${haveReady} redSel:${redSel}" +
297
    p"selV:${selValid} selReg:${selReg} selPtrReg:${selPtrReg} selIdx:${selIdx} selIdxReg:${selIdxReg}\n")
298
  XSDebug(print, p"haveBub:${haveBubble} bubPtr:${bubPtr} findBub:${findBubble} " +
299 300
    p"bubReg:${bubReg} bubPtrReg:${bubPtrReg} bubIdx:${bubIdx} bubIdxReg:${bubIdxReg}\n")
  XSDebug(print, p"issValid:${issValid} issueFire:${issFire} dequeue:${dequeue} deqPtr:${deqPtr}\n")
Z
ZhangZifei 已提交
301
  XSDebug(p" :Idx|v|r|s |cnt|s1:s2:s3\n")
Z
ZhangZifei 已提交
302
  for(i <- srcQueue.indices) {
303 304
    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 已提交
305
  }
306 307 308 309 310 311 312
}

class ReservationStationData
(
  val exuCfg: ExuConfig,
  wakeupCnt: Int,
  extraListenPortsCnt: Int,
313
  fixedDelay: Int,
314
  feedback: Boolean,
315 316
  srcNum: Int = 3
) extends XSModule {
317

318 319
  val iqSize = IssQueSize
  val iqIdxWidth = log2Up(iqSize)
320 321
  val fastWakeup = fixedDelay >= 0 // NOTE: if do not enable fastWakeup(bypass), set fixedDelay to -1
  val nonBlocked = fastWakeup
322 323 324

  val io = IO(new XSBundle {
    // flush
325
    val redirect = Flipped(ValidIO(new Redirect))
326 327 328 329 330

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

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

    // listen to RSCtrl
334 335 336 337 338 339 340 341 342
    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)))
343 344

    // listen to write back data bus(certain latency)
345
    // and extra wrtie back(uncertan latency)
346
    val writeBackedData = Vec(wakeupCnt, Input(UInt(XLEN.W)))
347 348 349 350
    val extraListenPorts = Vec(extraListenPortsCnt, Flipped(ValidIO(new ExuOutput)))

    // tlb feedback
    val feedback = Flipped(ValidIO(new TlbFeedback))
351 352 353
  })

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

356
  // TODO: change srcNum
357

358 359 360 361 362 363 364
  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
365
  val enqPtr = enq(log2Up(IssQueSize)-1,0)
Y
Yinan Xu 已提交
366 367
  val enqPtrReg = RegEnable(enqPtr, enqCtrl.valid)
  val enqEn  = enqCtrl.valid
368 369
  val enqEnReg = RegNext(enqEn)
  when (enqEn) {
370
    uop(enqPtr) := enqUop
Z
ZhangZifei 已提交
371 372 373
    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")
374
  }
375
  when (enqEnReg) { // TODO: turn to srcNum, not the 3
376 377 378
    data(enqPtrReg)(0) := io.enqData.src1
    data(enqPtrReg)(1) := io.enqData.src2
    data(enqPtrReg)(2) := io.enqData.src3
Z
ZhangZifei 已提交
379
    XSDebug(p"enqData: enqPtrReg:${enqPtrReg} src1:${Hexadecimal(io.enqData.src1)}" +
380
            p" src2:${Hexadecimal(io.enqData.src2)} src3:${Hexadecimal(io.enqData.src2)}\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 410 411 412 413 414
    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 }
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 427 428 429 430
    }
  }

  // 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)
431
  io.deq.valid := RegNext(sel.valid)
432
  if (nonBlocked) { assert(RegNext(io.deq.ready), s"${name} if fu wanna fast wakeup, it should not block")}
433 434 435 436 437

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

  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
  }

456 457

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

472

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