Jump.scala 2.0 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

L
LinJiawei 已提交
11 12 13 14
trait HasRedirectOut { this: RawModule =>
  val redirectOutValid = IO(Output(Bool()))
  val redirectOut = IO(Output(new Redirect))
  val brUpdate = IO(Output(new BranchUpdateInfo))
15 16
}

17
class Jump extends FunctionUnit with HasRedirectOut {
18

L
LinJiawei 已提交
19
  val (src1, offset, func, pc, uop) = (
20 21 22 23 24 25
    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
  )
26

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

30
  val isRVC = uop.cf.brUpdate.pd.isRVC
L
LinJiawei 已提交
31
  val snpc = Mux(isRVC, pc + 2.U, pc + 4.U)
32 33
  val target = src1 + offset // NOTE: src1 is (pc/rf(rs1)), src2 is (offset)

L
LinJiawei 已提交
34
  redirectOutValid := valid
35 36 37 38 39 40 41 42
  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
43

44 45 46 47 48
  brUpdate := uop.cf.brUpdate
  brUpdate.pc := uop.cf.pc
  brUpdate.target := target
  brUpdate.brTarget := target // DontCare
  brUpdate.taken := true.B
49

50
  // Output
L
LinJiawei 已提交
51
  val res = snpc
52 53

  io.in.ready := io.out.ready
L
LinJiawei 已提交
54
  io.out.valid := valid
55 56 57 58
  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
59
  XSDebug(io.in.valid, "In(%d %d) Out(%d %d) Redirect:(%d %d %d %d) brTag:%x\n",
60 61 62 63
    io.in.valid,
    io.in.ready,
    io.out.valid,
    io.out.ready,
64 65 66
    io.redirectIn.valid,
    io.redirectIn.bits.isException,
    io.redirectIn.bits.isFlushPipe,
67
    redirectHit,
68
    io.redirectIn.bits.brTag.value
69 70
  )
  XSDebug(io.in.valid, "src1:%x offset:%x func:%b type:JUMP pc:%x res:%x\n", src1, offset, func, pc, res)
L
LinJiawei 已提交
71
}