1package xiangshan 2 3import chisel3._ 4import chisel3.util._ 5import bus.simplebus._ 6import xiangshan.backend.brq.BrqPtr 7import xiangshan.backend.rename.FreeListPtr 8 9// Fetch FetchWidth x 32-bit insts from Icache 10class FetchPacket extends XSBundle { 11 val instrs = Vec(FetchWidth, UInt(32.W)) 12 val mask = UInt((FetchWidth*2).W) 13 val pc = UInt(VAddrBits.W) // the pc of first inst in the fetch group 14 val pnpc = Vec(FetchWidth, UInt(VAddrBits.W)) 15} 16 17// Branch prediction result from BPU Stage1 & 3 18class BranchPrediction extends XSBundle { 19 val redirect = Bool() 20 21 // mask off all the instrs after the first redirect instr 22 val instrValid = Vec(FetchWidth, Bool()) 23 // target and BTBtype of the first redirect instr in a fetch package 24 val target = UInt(VAddrBits.W) 25 val _type = UInt(2.W) 26 27 // save these info in brq! 28 // global history of each valid(or uncancelled) instruction, excluding branch's own prediction result 29 val hist = Vec(FetchWidth, UInt(HistoryLength.W)) 30 // ras checkpoint, only used in Stage3 31 val rasSp = Vec(FetchWidth, UInt(log2Up(RasSize).W)) 32 val rasTopCtr = Vec(FetchWidth, UInt(8.W)) 33} 34 35// Save predecode info in icache 36class Predecode extends XSBundle { 37 val mask = UInt(FetchWidth.W) 38 val fuTypes = Vec(FetchWidth, FuType()) 39 val fuOpTypes = Vec(FetchWidth, FuOpType()) 40} 41 42// Dequeue DecodeWidth insts from Ibuffer 43class CtrlFlow extends XSBundle { 44 val instr = UInt(32.W) 45 val pc = UInt(VAddrBits.W) 46 val pnpc = UInt(VAddrBits.W) 47 val exceptionVec = Vec(16, Bool()) 48 val intrVec = Vec(12, Bool()) 49 val isRVC = Bool() 50 val isBr = Bool() 51} 52 53// Decode DecodeWidth insts at Decode Stage 54class CtrlSignals extends XSBundle { 55 val src1Type, src2Type, src3Type = SrcType() 56 val lsrc1, lsrc2, lsrc3 = UInt(5.W) 57 val ldest = UInt(5.W) 58 val fuType = FuType() 59 val fuOpType = FuOpType() 60 val rfWen = Bool() 61 val fpWen = Bool() 62 val isXSTrap = Bool() 63 val noSpecExec = Bool() // This inst can not be speculated 64 val isBlocked = Bool() // This inst requires pipeline to be blocked 65 val isRVF = Bool() 66 val imm = UInt(XLEN.W) 67} 68 69class CfCtrl extends XSBundle { 70 val cf = new CtrlFlow 71 val ctrl = new CtrlSignals 72 val brTag = new BrqPtr 73} 74 75// CfCtrl -> MicroOp at Rename Stage 76class MicroOp extends CfCtrl { 77 78 val psrc1, psrc2, psrc3, pdest, old_pdest = UInt(PhyRegIdxWidth.W) 79 val src1State, src2State, src3State = SrcState() 80 val freelistAllocPtr = new FreeListPtr 81 val roqIdx = UInt(RoqIdxWidth.W) 82} 83 84class Redirect extends XSBundle { 85 val pc = UInt(VAddrBits.W) // wrongly predicted pc 86 val target = UInt(VAddrBits.W) 87 val brTarget = UInt(VAddrBits.W) 88 val brTag = new BrqPtr 89 val _type = UInt(2.W) 90 val isCall = Bool() 91 val taken = Bool() 92 val hist = UInt(HistoryLength.W) 93 val isException = Bool() 94 val roqIdx = UInt(RoqIdxWidth.W) 95 val freelistAllocPtr = new FreeListPtr 96} 97 98class RedirectInfo extends XSBundle { 99 100 val valid = Bool() // a valid commit form brq/roq 101 val misPred = Bool() // a branch miss prediction ? 102 val redirect = new Redirect 103 104 def flush():Bool = valid && (redirect.isException || misPred) 105} 106 107class Dp1ToDp2IO extends XSBundle { 108 val intDqToDp2 = Vec(IntDqDeqWidth, DecoupledIO(new MicroOp)) 109 val fpDqToDp2 = Vec(FpDqDeqWidth, DecoupledIO(new MicroOp)) 110 val lsDqToDp2 = Vec(LsDqDeqWidth, DecoupledIO(new MicroOp)) 111} 112 113class DebugBundle extends XSBundle{ 114 val isMMIO = Bool() 115} 116 117class ExuInput extends XSBundle { 118 val uop = new MicroOp 119 val src1, src2, src3 = UInt(XLEN.W) 120} 121 122class ExuOutput extends XSBundle { 123 val uop = new MicroOp 124 val data = UInt(XLEN.W) 125 val redirectValid = Bool() 126 val redirect = new Redirect 127 val debug = new DebugBundle 128} 129 130class ExuIO extends XSBundle { 131 val in = Flipped(DecoupledIO(new ExuInput)) 132 val redirect = Flipped(ValidIO(new Redirect)) 133 val out = DecoupledIO(new ExuOutput) 134 135 // for Lsu 136 val dmem = new SimpleBusUC 137 val scommit = Input(UInt(3.W)) 138} 139 140class RoqCommit extends XSBundle { 141 val uop = new MicroOp 142 val isWalk = Bool() 143} 144 145class FrontendToBackendIO extends XSBundle { 146 // to backend end 147 val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow)) 148 // from backend 149 val redirectInfo = Input(new RedirectInfo) 150 val commits = Vec(CommitWidth, Flipped(ValidIO(new RoqCommit))) // update branch pred 151} 152