Jump.scala 2.2 KB
Newer Older
L
LinJiawei 已提交
1
package xiangshan.backend.fu
2 3 4 5

import chisel3._
import chisel3.util._
import xiangshan._
L
LinJiawei 已提交
6
import utils._
L
LinJiawei 已提交
7 8
import xiangshan.backend._
import xiangshan.backend.fu.FunctionUnit._
G
GouLingrui 已提交
9
import xiangshan.backend.decode.isa._
10

11 12 13 14 15 16 17
class RedirectOut extends XSBundle {
  val redirectValid = Bool()
  val redirect = new Redirect
  val brUpdate = new BranchUpdateInfo
}

class Jump extends FunctionUnit(jmpCfg, extOut = new RedirectOut) {
18

19 20 21 22 23 24 25 26
  val (iovalid, src1, offset, func, pc, uop) = (
    io.in.valid,
    io.in.bits.src(0),
    io.in.bits.uop.ctrl.imm,
    io.in.bits.uop.ctrl.fuOpType,
    SignExt(io.in.bits.uop.cf.pc, AddrBits),
    io.in.bits.uop
  )
27

L
LinJiawei 已提交
28
  val redirectHit = uop.roqIdx.needFlush(io.redirectIn)
29 30
  val valid = iovalid && !redirectHit

31
  val isRVC = uop.cf.brUpdate.pd.isRVC
32 33 34
  val pcDelaySlot = Mux(isRVC, pc + 2.U, pc + 4.U)
  val target = src1 + offset // NOTE: src1 is (pc/rf(rs1)), src2 is (offset)

35 36 37 38 39 40 41 42 43 44 45 46
  val redirectOut = io.out.bits.ext.get.redirect
  val brUpdate = io.out.bits.ext.get.brUpdate

  io.out.bits.ext.get.redirectValid := valid
  redirectOut.pc := uop.cf.pc
  redirectOut.target := target
  redirectOut.brTag := uop.brTag
  redirectOut.isException := false.B
  redirectOut.isFlushPipe := false.B
  redirectOut.isMisPred := DontCare // check this in brq
  redirectOut.isReplay := false.B
  redirectOut.roqIdx := uop.roqIdx
47

48 49 50 51 52
  brUpdate := uop.cf.brUpdate
  brUpdate.pc := uop.cf.pc
  brUpdate.target := target
  brUpdate.brTarget := target // DontCare
  brUpdate.taken := true.B
53
  // io.out.bits.brUpdate.fetchIdx := uop.cf.brUpdate.fetchOffset >> 1.U  //TODO: consider RVC
54

55
  // Output
56
  val res = pcDelaySlot
57 58 59 60 61 62 63

  io.in.ready := io.out.ready
  io.out.valid := valid // TODO: CSR/MOU/FMV may need change it
  io.out.bits.uop <> io.in.bits.uop
  io.out.bits.data := res

  // NOTE: the debug info is for one-cycle exec, if FMV needs multi-cycle, may needs change it
64
  XSDebug(io.in.valid, "In(%d %d) Out(%d %d) Redirect:(%d %d %d %d) brTag:%x\n",
65 66 67 68
    io.in.valid,
    io.in.ready,
    io.out.valid,
    io.out.ready,
69 70 71
    io.redirectIn.valid,
    io.redirectIn.bits.isException,
    io.redirectIn.bits.isFlushPipe,
72
    redirectHit,
73
    io.redirectIn.bits.brTag.value
74 75
  )
  XSDebug(io.in.valid, "src1:%x offset:%x func:%b type:JUMP pc:%x res:%x\n", src1, offset, func, pc, res)
L
LinJiawei 已提交
76
}