ReservationStationNew.scala 17.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 67
  val fastWakeup = fixedDelay > 0 // NOTE: if do not enable fastWakeup(bypass), set fixedDelay to -1
  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))
  })

Z
ZhangZifei 已提交
83
  // control part:
84 85

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

87
  val needFeedback  = if (feedback) true.B else false.B
88
  val notBlock      = if (nonBlocked) true.B else false.B
89 90 91
  val stateQueue    = RegInit(VecInit(Seq.fill(iqSize)(s_idle)))
  val validQueue    = stateQueue.map(_ === s_valid)
  val emptyQueue    = stateQueue.map(_ === s_idle)
92
  val srcQueue      = Reg(Vec(iqSize, Vec(srcNum, Bool())))
93
  val cntQueue      = Reg(Vec(iqSize, UInt(log2Up(replayDelay).W)))
Z
ZhangZifei 已提交
94 95

  // rs queue part:
Z
ZhangZifei 已提交
96 97
  // val tailPtr       = RegInit(0.U((iqIdxWidth+1).W))
  val tailPtr       = RegInit(0.U.asTypeOf(new CircularQueuePtr(iqSize)))
98
  val idxQueue      = RegInit(VecInit((0 until iqSize).map(_.U(iqIdxWidth.W))))
99
  val readyQueue    = VecInit(srcQueue.zip(validQueue).map{ case (a,b) => Cat(a).andR & b })
100

101 102
  // redirect
  val redHitVec   = VecInit((0 until iqSize).map(i => io.data.redVec(idxQueue(i))))
103 104
  val fbMatchVec  = (0 until iqSize).map(i => needFeedback && io.data.feedback(idxQueue(i)) &&
                    (stateQueue(i) === s_wait || stateQueue(i)===s_valid))
105
  val fbHit       = io.data.feedback(IssQueSize)
106

Z
ZhangZifei 已提交
107
  // select ready
Z
ZhangZifei 已提交
108 109
  // for no replay, select just equal to deq (attached)
  // with   replay, select is just two stage with deq.
110
  val issFire = Wire(Bool())
Z
ZhangZifei 已提交
111 112 113 114
  val moveMask = WireInit(0.U(iqSize.W))
  val selectedIdxRegOH = Wire(UInt(iqSize.W))
  val selectMask = WireInit(VecInit(
    (0 until iqSize).map(i =>
115 116
      readyQueue(i) && Mux(notBlock, true.B, !(selectedIdxRegOH(i) && (issFire)))
      // NOTE: if nonBlocked, then change state at sel stage
Z
ZhangZifei 已提交
117 118
    )
  ))
119
  val haveBubble = Wire(Bool())
Z
ZhangZifei 已提交
120
  val (selectedIdxWire, selected) = PriorityEncoderWithFlag(selectMask)
121
  val redSel = redHitVec(selectedIdxWire)
122
  val selValid = !redSel && selected && !haveBubble
123
  val selReg = RegNext(selValid)
Z
ZhangZifei 已提交
124 125
  val selectedIdxReg = RegNext(selectedIdxWire - moveMask(selectedIdxWire))
  selectedIdxRegOH := UIntToOH(selectedIdxReg)
Z
ZhangZifei 已提交
126

Z
ZhangZifei 已提交
127 128 129 130
  // sel bubble
  // TODO:
  val bubIdxRegOH = Wire(UInt(iqSize.W))
  val bubMask = WireInit(VecInit(
131 132 133
    (0 until iqSize).map(i => emptyQueue(i) && !bubIdxRegOH(i) &&
                              Mux(notBlock, !selectedIdxRegOH(i), true.B)
  )))
Z
ZhangZifei 已提交
134
  val (firstBubble, findBubble) = PriorityEncoderWithFlag(bubMask)
Z
ZhangZifei 已提交
135
  haveBubble := findBubble && (firstBubble < tailPtr.asUInt)
Z
ZhangZifei 已提交
136 137 138 139 140 141
  val bubValid = haveBubble
  val bubReg = RegNext(bubValid)
  val bubIdxReg = RegNext(firstBubble - moveMask(firstBubble))
  bubIdxRegOH := UIntToOH(bubIdxReg)

  // deq
142
  // TODO: divide needFeedback and not needFeedback
143
  val deqValid = bubReg/*fire an bubble*/ || (issFire && !needFeedback/*fire an rdy*/)
Z
ZhangZifei 已提交
144
  val deqIdx = Mux(bubReg, bubIdxReg, selectedIdxReg) // TODO: may have one more cycle delay than fire slot
Z
ZhangZifei 已提交
145
  moveMask := {
146
    (Fill(iqSize, 1.U(1.W)) << deqIdx)(iqSize-1, 0)
Z
ZhangZifei 已提交
147
  } & Fill(iqSize, deqValid)
Z
ZhangZifei 已提交
148

149
  // move
150
  for(i <- 0 until iqSize-1){
Z
ZhangZifei 已提交
151
    when(moveMask(i)){
Z
ZhangZifei 已提交
152
      idxQueue(i)   := idxQueue(i+1)
153
      srcQueue(i).zip(srcQueue(i+1)).map{case (a,b) => a := b}
154
      stateQueue(i) := stateQueue(i+1)
Z
ZhangZifei 已提交
155 156
    }
  }
157 158 159 160
  when (notBlock && selValid) { // if notBlock, disable at select stage
    stateQueue(selectedIdxWire - moveMask(selectedIdxWire)) := s_idle
    // TODO: may have long latency
  }
161 162
  when(deqValid){
    idxQueue.last := idxQueue(deqIdx)
163
    stateQueue.last := s_idle
Z
ZhangZifei 已提交
164
  }
165
  when (issFire && needFeedback) {
166 167 168
    stateQueue(selectedIdxReg) := s_wait
  }

169 170

  // redirect and feedback
171
  for (i <- 0 until iqSize) {
172
    val cnt = cntQueue(idxQueue(i))
173
    when (!(deqIdx === i.U && deqValid)) {
174 175 176 177 178 179 180
    if (i != 0) { // TODO: combine the two case
      val nextIdx = i.U - moveMask(i-1)
      when (stateQueue(i)===s_replay) {
        when (cnt===0.U) { stateQueue(nextIdx) := s_valid }
        .otherwise { cnt := cnt - 1.U }
      }
      when (fbMatchVec(i)) {
181 182
        stateQueue(nextIdx) := Mux(fbHit, s_idle, s_replay)
        cnt := Mux(fbHit, cnt, (replayDelay-1).U)
183 184 185 186 187 188 189 190 191
      }
      when (redHitVec(i)) { stateQueue(nextIdx) := s_idle }
    } else { when (!moveMask(i)) {
      val nextIdx = i
      when (stateQueue(i)===s_replay) {
        when (cnt===0.U) { stateQueue(nextIdx) := s_valid }
        .otherwise { cnt := cnt - 1.U }
      }
      when (fbMatchVec(i)) {
192 193
        stateQueue(nextIdx) := Mux(fbHit, s_idle, s_replay)
        cnt := Mux(fbHit, cnt, (replayDelay-1).U)
194 195 196
      }
      when (redHitVec(i)) { stateQueue(nextIdx) := s_idle }
    }}
197
    }
198
  }
199

200
  // output
201
  val issValid = selReg && !redHitVec(selectedIdxReg)
202
  issFire := issValid && Mux(notBlock, true.B, io.data.fuReady)
203
  if (nonBlocked) { assert(RegNext(io.data.fuReady), "if fu wanna fast wakeup, it should not block")}
Z
ZhangZifei 已提交
204 205

  // enq
206
  val tailAfterRealDeq = tailPtr - (issFire && !needFeedback|| bubReg)
Z
ZhangZifei 已提交
207
  val isFull = tailAfterRealDeq.flag // tailPtr===qsize.U
Y
Yinan Xu 已提交
208 209 210
  // agreement with dispatch: don't fire when io.redirect.valid
  val enqFire = io.enqCtrl.fire() && !io.redirect.valid
  tailPtr := tailAfterRealDeq + enqFire
211

Y
Yinan Xu 已提交
212
  io.enqCtrl.ready := !isFull
213 214 215
  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)
216
  val srcStateSeq = Seq(enqUop.src1State, enqUop.src2State, enqUop.src3State)
217

Z
ZhangZifei 已提交
218
  val enqIdx_ctrl = tailAfterRealDeq.value
219 220 221 222 223 224
  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)
  }
225

Y
Yinan Xu 已提交
226
  when (enqFire) {
227
    stateQueue(enqIdx_ctrl) := s_valid
228
    srcQueue(enqIdx_ctrl).zipWithIndex.map{ case (s, i) =>
229
      s := Mux(enqBpVec(i) || stateCheck(srcSeq(i), srcTypeSeq(i)), true.B,
Z
ZhangZifei 已提交
230
               srcStateSeq(i)===SrcState.rdy)
231
    }
Z
ZhangZifei 已提交
232
    XSDebug(p"EnqCtrl: roqIdx:${enqUop.roqIdx} pc:0x${Hexadecimal(enqUop.cf.pc)} " +
233 234 235
      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 已提交
236 237
  }

238
  // wakeup
239
  for(i <- 0 until IssQueSize) {
240
    val hitVec = io.data.srcUpdate(idxQueue(i))
241 242 243 244 245
    for(j <- 0 until srcNum) {
      when (hitVec(j) && validQueue(i)) {
        srcQueue(i.U - moveMask(i))(j) := true.B
        XSDebug(p"srcHit: i:${i.U} j:${j.U}\n")
      }
246 247 248
    }
  }

249
  // other to Data
Z
ZhangZifei 已提交
250
  io.data.enqPtr := idxQueue(Mux(tailPtr.flag, deqIdx, tailPtr.value))
251 252
  io.data.deqPtr.valid  := selValid
  io.data.deqPtr.bits   := idxQueue(selectedIdxWire)
Y
Yinan Xu 已提交
253
  io.data.enqCtrl.valid := enqFire
254
  io.data.enqCtrl.bits  := io.enqCtrl.bits
255

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

Z
ZhangZifei 已提交
259
  // assert
Z
ZhangZifei 已提交
260
  assert(RegNext(Mux(tailPtr.flag, tailPtr.value===0.U, true.B)))
Z
ZhangZifei 已提交
261

Z
ZhangZifei 已提交
262
  val print = !(tailPtr.asUInt===0.U) || io.enqCtrl.valid
263
  XSDebug(print || true.B, p"In(${io.enqCtrl.valid} ${io.enqCtrl.ready}) Out(${issValid} ${io.data.fuReady})\n")
Z
ZhangZifei 已提交
264 265 266 267 268 269 270 271 272
  XSDebug(print , p"tailPtr:${tailPtr} tailPtrAdq:${tailAfterRealDeq} isFull:${isFull} " +
    p"needFeed:${needFeedback} vQue:${Binary(VecInit(validQueue).asUInt)} rQue:${Binary(readyQueue.asUInt)}\n")
  XSDebug(print && Cat(redHitVec).orR, p"Redirect: ${Hexadecimal(redHitVec.asUInt)}\n")
  XSDebug(print && Cat(fbMatchVec).orR, p"Feedback: ${Hexadecimal(VecInit(fbMatchVec).asUInt)} Hit:${fbHit}\n")
  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")
Z
ZhangZifei 已提交
273
  XSDebug(p" :Idx|v|r|s |cnt|s1:s2:s3\n")
Z
ZhangZifei 已提交
274 275
  for(i <- srcQueue.indices) {
    XSDebug(p"${i.U}: ${idxQueue(i)}|${validQueue(i)}|${readyQueue(i)}|${stateQueue(i)}|" +
Z
ZhangZifei 已提交
276
      p"${cntQueue(i)}|${srcQueue(i)(0)}:${srcQueue(i)(1)}:${srcQueue(i)(2)}\n")
Z
ZhangZifei 已提交
277
  }
278 279 280 281 282 283 284
}

class ReservationStationData
(
  val exuCfg: ExuConfig,
  wakeupCnt: Int,
  extraListenPortsCnt: Int,
285
  fixedDelay: Int,
286
  feedback: Boolean,
287 288
  srcNum: Int = 3
) extends XSModule {
289

290 291
  val iqSize = IssQueSize
  val iqIdxWidth = log2Up(iqSize)
292 293 294
  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
295 296 297

  val io = IO(new XSBundle {
    // flush
298
    val redirect = Flipped(ValidIO(new Redirect))
299 300 301 302 303

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

    // send to exu
304
    val deq = DecoupledIO(new ExuInput)
305 306

    // listen to RSCtrl
307 308 309 310 311 312 313 314 315
    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)))
316 317

    // listen to write back data bus(certain latency)
318
    // and extra wrtie back(uncertan latency)
319
    val writeBackedData = Vec(wakeupCnt, Input(UInt(XLEN.W)))
320 321 322 323
    val extraListenPorts = Vec(extraListenPortsCnt, Flipped(ValidIO(new ExuOutput)))

    // tlb feedback
    val feedback = Flipped(ValidIO(new TlbFeedback))
324 325 326
  })

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

329
  // TODO: change srcNum
330

331 332 333 334 335 336 337
  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
338
  val enqPtr = enq(log2Up(IssQueSize)-1,0)
Y
Yinan Xu 已提交
339 340
  val enqPtrReg = RegEnable(enqPtr, enqCtrl.valid)
  val enqEn  = enqCtrl.valid
341 342
  val enqEnReg = RegNext(enqEn)
  when (enqEn) {
343
    uop(enqPtr) := enqUop
Z
ZhangZifei 已提交
344 345 346
    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")
347
  }
348
  when (enqEnReg) { // TODO: turn to srcNum, not the 3
349 350 351
    data(enqPtrReg)(0) := io.enqData.src1
    data(enqPtrReg)(1) := io.enqData.src2
    data(enqPtrReg)(2) := io.enqData.src3
Z
ZhangZifei 已提交
352
    XSDebug(p"enqData: enqPtrReg:${enqPtrReg} src1:${Hexadecimal(io.enqData.src1)}" +
353
            p" src2:${Hexadecimal(io.enqData.src2)} src3:${Hexadecimal(io.enqData.src2)}\n")
354 355
  }

356
  def wbHit(uop: MicroOp, src: UInt, srctype: UInt): Bool = {
357
    (src === uop.pdest) &&
358 359 360
    ((srctype === SrcType.reg && uop.ctrl.rfWen && src=/=0.U) ||
     (srctype === SrcType.fp  && uop.ctrl.fpWen))
  }
361

362
  // wakeup and bypass
363 364
  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)
365 366 367 368 369 370
    assert(RegNext(PopCount(hitVec)===0.U || PopCount(hitVec)===1.U))

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

371 372
  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)
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
    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 }
388
      when (bpHitReg && !(enqPtrReg===i.U && enqEnReg)) { data(i)(j) := bpData }
389 390 391 392
      // 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
393 394 395
      XSDebug(wuHit, p"WUHit: (${i.U})(${j.U}) Data:0x${Hexadecimal(wuData)} i:${i.U} j:${j.U}\n")
      XSDebug(bpHit, p"BPHit: (${i.U})(${j.U}) i:${i.U} j:${j.U}\n")
      XSDebug(bpHitReg, p"BPHitData: (${i.U})(${j.U}) Data:0x${Hexadecimal(bpData)} i:${i.U} j:${j.U}\n")
396 397 398 399 400 401 402 403
    }
  }

  // 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)
404
  io.deq.valid := RegNext(sel.valid)
405
  if (nonBlocked) { assert(RegNext(io.deq.ready), s"${name} if fu wanna fast wakeup, it should not block")}
406 407 408 409 410

  // 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 已提交
411
    val (bpHit, bpHitReg, bpData)= bypass(srcSeq(i), srcTypeSeq(i), enqCtrl.valid)
412 413
    when (bpHitReg) { data(enqPtrReg)(i) := bpData }
    h := bpHit
414
    // NOTE: enq bp is done here
415 416 417
    XSDebug(bpHit, p"EnqBPHit: (${i.U})\n")
    XSDebug(bpHitReg, p"EnqBPHitData: (${i.U}) data:${Hexadecimal(bpData)}\n")
  }
418
  io.ctrl.fuReady  := Mux(notBlock, true.B, io.deq.ready)
419
  io.ctrl.redVec   := VecInit(uop.map(_.roqIdx.needFlush(io.redirect))).asUInt
420 421 422 423 424 425 426 427

  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
  }

428 429

  // bypass send
430 431 432 433 434 435 436 437 438 439 440 441
  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" )
442
  }
443

444

Z
ZhangZifei 已提交
445 446
  // log
  XSDebug(io.feedback.valid, p"feedback: roqIdx:${io.feedback.bits.roqIdx} hit:${io.feedback.bits.hit}\n")
447
  XSDebug(true.B, p"out(${io.deq.valid} ${io.deq.ready})\n")
Z
ZhangZifei 已提交
448
  XSDebug(io.deq.valid, p"Deq(${io.deq.valid} ${io.deq.ready}): deqPtr:${deq} pc:${Hexadecimal(io.deq.bits.uop.cf.pc)}" +
449 450
    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 已提交
451
  XSDebug(p"Data:  | src1:data | src2:data | src3:data |hit|pdest:rf:fp| roqIdx | pc\n")
452
  for(i <- data.indices) {
Z
ZhangZifei 已提交
453 454 455 456
    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")
457
  }
458
}