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

import chisel3._
import chisel3.util._
import xiangshan._

7
class DecodeStage extends XSModule {
8
  val io = IO(new Bundle() {
9
    // enq Brq
10
    val toBrq = Vec(DecodeWidth, DecoupledIO(new CfCtrl))
11 12 13 14 15
    // get brMask/brTag
    val brTags = Input(Vec(DecodeWidth, UInt(BrTagWidth.W)))
    val brMasks = Input(Vec(DecodeWidth, UInt(BrqSize.W)))

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

    // to DecBuffer
19 20
    val out = Vec(DecodeWidth, DecoupledIO(new CfCtrl))
  })
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  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:
  //    First, assert toBrq(i).valid and present toBrq(i).bits
  //    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
37
    io.toBrq(i).valid := io.in(i).valid & io.out(i).ready & decoders(i).io.out.cf.isBr
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    decoderToBrq(i).brMask := DontCare
    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)
    decoderToDecBuffer(i).brMask := io.brMasks(i)
    io.out(i).bits := decoderToDecBuffer(i)

    // 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
  }
53
}