1package xiangshan.backend.fu 2 3import chisel3._ 4import chisel3.util._ 5import xiangshan._ 6import utils._ 7import xiangshan.backend._ 8import xiangshan.backend.fu.FunctionUnit._ 9import xiangshan.backend.decode.isa._ 10 11trait HasRedirectOut { this: RawModule => 12 val redirectOutValid = IO(Output(Bool())) 13 val redirectOut = IO(Output(new Redirect)) 14 val brUpdate = IO(Output(new CfiUpdateInfo)) 15} 16 17class Jump extends FunctionUnit with HasRedirectOut { 18 19 val (src1, offset, func, pc, uop) = ( 20 io.in.bits.src(0), 21 io.in.bits.uop.ctrl.imm, 22 io.in.bits.uop.ctrl.fuOpType, 23 SignExt(io.in.bits.uop.cf.pc, AddrBits), 24 io.in.bits.uop 25 ) 26 27 val redirectHit = uop.roqIdx.needFlush(io.redirectIn) 28 val valid = io.in.valid && !redirectHit 29 30 val isRVC = uop.cf.brUpdate.pd.isRVC 31 val snpc = Mux(isRVC, pc + 2.U, pc + 4.U) 32 val target = src1 + offset // NOTE: src1 is (pc/rf(rs1)), src2 is (offset) 33 34 redirectOutValid := valid 35 redirectOut.pc := uop.cf.pc 36 redirectOut.target := target 37 redirectOut.brTag := uop.brTag 38 redirectOut.isException := false.B 39 redirectOut.isFlushPipe := false.B 40 redirectOut.isMisPred := DontCare // check this in brq 41 redirectOut.isReplay := false.B 42 redirectOut.roqIdx := uop.roqIdx 43 44 brUpdate := uop.cf.brUpdate 45 brUpdate.pc := uop.cf.pc 46 brUpdate.target := target 47 brUpdate.brTarget := target 48 brUpdate.taken := true.B 49 50 // Output 51 val res = snpc 52 53 io.in.ready := io.out.ready 54 io.out.valid := valid 55 io.out.bits.uop <> io.in.bits.uop 56 io.out.bits.data := res 57 58 // 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 io.in.valid, 61 io.in.ready, 62 io.out.valid, 63 io.out.ready, 64 io.redirectIn.valid, 65 io.redirectIn.bits.isException, 66 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) 71} 72