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

import chisel3._
import chisel3.util._
import xiangshan._
L
LinJiawei 已提交
6
import xiangshan.backend.brq.BrqPtr
7
import xiangshan.utils._
8

9
class DecodeStage extends XSModule {
10
  val io = IO(new Bundle() {
11
    // enq Brq
12
    val toBrq = Vec(DecodeWidth, DecoupledIO(new CfCtrl))
13
    // get brMask/brTag
L
LinJiawei 已提交
14
    val brTags = Input(Vec(DecodeWidth, new BrqPtr))
15 16

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

    // to DecBuffer
20 21
    val out = Vec(DecodeWidth, DecoupledIO(new CfCtrl))
  })
22 23 24 25 26 27
  val decoders = Seq.fill(DecodeWidth)(Module(new Decoder))
  val decoderToBrq = Wire(Vec(DecodeWidth, new CfCtrl)) // without brTag and brMask
  val decoderToDecBuffer = Wire(Vec(DecodeWidth, new CfCtrl)) // with brTag and brMask

  // Handshake ---------------------
  // 1. if current instruction is valid, then:
28
  //    First, assert toBrq(i).valid if (in.valid and out.ready and isBr) and present toBrq(i).bits
29 30 31 32 33 34 35 36 37
  //    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) {
    decoders(i).io.in <> io.in(i).bits
    decoderToBrq(i) := decoders(i).io.out // CfCtrl without bfTag and brMask
    // send CfCtrl without brTags and brMasks to brq
38
    io.toBrq(i).valid := io.in(i).valid && io.out(i).ready && decoders(i).io.out.cf.isBr
39 40 41 42 43 44 45
    decoderToBrq(i).brTag := DontCare
    io.toBrq(i).bits := decoderToBrq(i)
    // if brq returns ready, then assert valid and send CfCtrl with bfTag and brMask to DecBuffer
    io.out(i).valid := io.toBrq(i).ready && io.in(i).valid
    decoderToDecBuffer(i) := decoders(i).io.out
    decoderToDecBuffer(i).brTag := io.brTags(i)
    io.out(i).bits := decoderToDecBuffer(i)
46 47 48 49
    XSDebug(
      io.out(i).valid && io.out(i).bits.ctrl.noSpecExec,
      p"noSpecExec inst: pc=${Hexadecimal(io.out(i).bits.cf.pc)}\n"
    )
50 51 52 53 54 55

    // If an instruction i is received by DecBuffer,
    // then assert in(i).ready, waiting for new instructions
    // Only when all out(i).ready signals are true can we decode next instruction group (?)
    io.in(i).ready := io.out(i).ready
  }
56
}