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.pc := uop.cf.pc 42 redirectOut.target := target 43 redirectOut.brTag := uop.brTag 44 redirectOut.level := RedirectLevel.flushAfter 45 redirectOut.interrupt := DontCare 46 redirectOut.roqIdx := uop.roqIdx 47 48 brUpdate := uop.cf.brUpdate 49 brUpdate.pc := uop.cf.pc 50 brUpdate.target := target 51 brUpdate.brTarget := target 52 brUpdate.taken := true.B 53 54 // Output 55 val res = snpc 56 57 io.in.ready := io.out.ready 58 io.out.valid := valid 59 io.out.bits.uop <> io.in.bits.uop 60 io.out.bits.data := res 61 62 // NOTE: the debug info is for one-cycle exec, if FMV needs multi-cycle, may needs change it 63 XSDebug(io.in.valid, "In(%d %d) Out(%d %d) Redirect:(%d %d %d) brTag:%x\n", 64 io.in.valid, 65 io.in.ready, 66 io.out.valid, 67 io.out.ready, 68 io.redirectIn.valid, 69 io.redirectIn.bits.level, 70 redirectHit, 71 io.redirectIn.bits.brTag.value 72 ) 73 XSDebug(io.in.valid, "src1:%x offset:%x func:%b type:JUMP pc:%x res:%x\n", src1, offset, func, pc, res) 74} 75