DecodeStage.scala 2.1 KB
Newer Older
1 2 3 4 5
package xiangshan.backend.decode

import chisel3._
import chisel3.util._
import xiangshan._
Y
Yinan Xu 已提交
6
import xiangshan.backend.brq.BrqEnqIO
L
LinJiawei 已提交
7
import utils._
L
LinJiawei 已提交
8
import xiangshan.backend.decode.Instructions.{AUIPC, MRET, SRET}
9

10
class DecodeStage extends XSModule {
11
  val io = IO(new Bundle() {
12
    // enq Brq
Y
Yinan Xu 已提交
13
    val enqBrq = Flipped(new BrqEnqIO)
14 15

    // from Ibuffer
16
    val in = Vec(DecodeWidth, Flipped(DecoupledIO(new CtrlFlow)))
17 18

    // to DecBuffer
19 20
    val out = Vec(DecodeWidth, DecoupledIO(new CfCtrl))
  })
Y
Yinan Xu 已提交
21

22
  val decoders = Seq.fill(DecodeWidth)(Module(new DecodeUnit))
23 24 25

  // Handshake ---------------------
  // 1. if current instruction is valid, then:
26
  //    First, assert toBrq(i).valid if (in.valid and out.ready and isBr) and present toBrq(i).bits
27 28 29 30 31 32
  //    Second, check toBrq(i).ready and connect it to io.out(i).valid
  // 2. To Decode Buffer:
  //    First, assert in(i).ready if out(i).ready
  //    Second, assert out(i).valid iff in(i).valid and instruction is valid (not implemented) and toBrq(i).ready

  for (i <- 0 until DecodeWidth) {
33
    decoders(i).io.enq.ctrl_flow <> io.in(i).bits
Y
Yinan Xu 已提交
34

L
LinJiawei 已提交
35 36 37 38
    val isMret = io.in(i).bits.instr === MRET
    val isSret = io.in(i).bits.instr === SRET
    val isAuiPc = io.in(i).bits.instr === AUIPC
    val thisBrqValid = !io.in(i).bits.brUpdate.pd.notCFI || isMret || isSret || isAuiPc
Y
Yinan Xu 已提交
39 40
    io.enqBrq.needAlloc(i) := thisBrqValid
    io.enqBrq.req(i).valid := io.in(i).valid && thisBrqValid && io.out(i).ready
L
LinJiawei 已提交
41 42
    io.enqBrq.req(i).bits  := io.in(i).bits
    io.enqBrq.req(i).bits.instr := decoders(i).io.deq.cf_ctrl.cf.instr
Y
Yinan Xu 已提交
43 44 45 46 47 48 49 50 51 52 53

    io.out(i).valid      := io.in(i).valid && io.enqBrq.req(i).ready
    io.out(i).bits       := decoders(i).io.deq.cf_ctrl
    io.out(i).bits.brTag := io.enqBrq.resp(i)

    io.in(i).ready := io.out(i).ready && io.enqBrq.req(i).ready

    XSDebug(io.in(i).valid || io.out(i).valid || io.enqBrq.req(i).valid,
      "i:%d In(%d %d) Out(%d %d) ToBrq(%d %d) pc:%x instr:%x\n",
      i.U, io.in(i).valid, io.in(i).ready, io.out(i).valid, io.out(i).ready,
      io.enqBrq.req(i).valid, io.enqBrq.req(i).ready, io.in(i).bits.pc, io.in(i).bits.instr)
54
  }
Y
Yinan Xu 已提交
55
}