1package xiangshan.backend.fu 2 3import chisel3._ 4import chisel3.util._ 5import xiangshan._ 6import utils._ 7import xiangshan.backend._ 8import xiangshan.backend.decode.ImmUnion 9import xiangshan.backend.fu.FunctionUnit._ 10import xiangshan.backend.decode.isa._ 11 12trait HasRedirectOut { this: RawModule => 13 val redirectOutValid = IO(Output(Bool())) 14 val redirectOut = IO(Output(new Redirect)) 15 val brUpdate = IO(Output(new CfiUpdateInfo)) 16} 17 18class Jump extends FunctionUnit with HasRedirectOut { 19 20 val (src1, immMin, func, pc, uop) = ( 21 io.in.bits.src(0), 22 io.in.bits.uop.ctrl.imm, 23 io.in.bits.uop.ctrl.fuOpType, 24 SignExt(io.in.bits.uop.cf.pc, AddrBits), 25 io.in.bits.uop 26 ) 27 28 val offset = SignExt(Mux(JumpOpType.jumpOpIsJal(func), 29 ImmUnion.J.toImm32(immMin), 30 ImmUnion.I.toImm32(immMin) 31 ), XLEN) 32 33 val redirectHit = uop.roqIdx.needFlush(io.redirectIn) 34 val valid = io.in.valid 35 36 val isRVC = uop.cf.brUpdate.pd.isRVC 37 val snpc = Mux(isRVC, pc + 2.U, pc + 4.U) 38 val target = src1 + offset // NOTE: src1 is (pc/rf(rs1)), src2 is (offset) 39 40 redirectOutValid := valid 41 redirectOut := DontCare 42// redirectOut.pc := uop.cf.pc 43 redirectOut.target := target 44 redirectOut.brTag := uop.brTag 45 redirectOut.level := RedirectLevel.flushAfter 46// redirectOut.interrupt := DontCare 47 redirectOut.roqIdx := uop.roqIdx 48 49 brUpdate := DontCare //uop.cf.brUpdate 50// brUpdate.pc := uop.cf.pc 51 brUpdate.target := target 52 brUpdate.brTarget := target 53 brUpdate.taken := true.B 54 55 // Output 56 val res = snpc 57 58 io.in.ready := io.out.ready 59 io.out.valid := valid 60 io.out.bits.uop <> io.in.bits.uop 61 io.out.bits.data := res 62 63 // 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) brTag:%x\n", 65 io.in.valid, 66 io.in.ready, 67 io.out.valid, 68 io.out.ready, 69 io.redirectIn.valid, 70 io.redirectIn.bits.level, 71 redirectHit, 72 io.redirectIn.bits.brTag.value 73 ) 74 XSDebug(io.in.valid, "src1:%x offset:%x func:%b type:JUMP pc:%x res:%x\n", src1, offset, func, pc, res) 75} 76