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*2, UInt(VAddrBits.W)) 15 val hist = Vec(FetchWidth*2, UInt(HistoryLength.W)) // TODO: LoopBuffer can't handle RVC 16 // val btbVictimWay = UInt(log2Up(BtbWays).W) 17 val predCtr = Vec(FetchWidth*2, UInt(2.W)) 18 val btbHit = Vec(FetchWidth*2, Bool()) 19 val tageMeta = Vec(FetchWidth*2, (new TageMeta)) 20 val rasSp = UInt(log2Up(RasSize).W) 21 val rasTopCtr = UInt(8.W) 22 val branchInfo = Vec(FetchWidth,Bool()) 23} 24 25 26class ValidUndirectioned[T <: Data](gen: T) extends Bundle { 27 val valid = Bool() 28 val bits = gen.asInstanceOf[T] 29 override def cloneType = new ValidUndirectioned(gen).asInstanceOf[this.type] 30} 31 32object ValidUndirectioned { 33 def apply[T <: Data](gen: T) = { 34 new ValidUndirectioned[T](gen) 35 } 36} 37 38class TageMeta extends XSBundle { 39 val provider = ValidUndirectioned(UInt(log2Ceil(TageNTables).W)) 40 val altDiffers = Bool() 41 val providerU = UInt(2.W) 42 val providerCtr = UInt(3.W) 43 val allocate = ValidUndirectioned(UInt(log2Ceil(TageNTables).W)) 44} 45 46// Branch prediction result from BPU Stage1 & 3 47class BranchPrediction extends XSBundle { 48 val redirect = Bool() 49 50 // mask off all the instrs after the first redirect instr 51 val instrValid = Vec(FetchWidth*2, Bool()) 52 // target of the first redirect instr in a fetch package 53 val target = UInt(VAddrBits.W) 54 val lateJump = Bool() 55 // save these info in brq! 56 // global history of each valid(or uncancelled) instruction, excluding branch's own prediction result 57 val hist = Vec(FetchWidth*2, UInt(HistoryLength.W)) 58 // victim way when updating btb 59 // val btbVictimWay = UInt(log2Up(BtbWays).W) 60 // 2-bit saturated counter 61 val predCtr = Vec(FetchWidth*2, UInt(2.W)) 62 val btbHit = Vec(FetchWidth*2, Bool()) 63 // tage meta info 64 val tageMeta = Vec(FetchWidth*2, (new TageMeta)) 65 // ras checkpoint, only used in Stage3 66 val rasSp = UInt(log2Up(RasSize).W) 67 val rasTopCtr = UInt(8.W) 68} 69 70// Save predecode info in icache 71class Predecode extends XSBundle { 72 val mask = UInt((FetchWidth*2).W) 73 val isRVC = Vec(FetchWidth*2, Bool()) 74 val fuTypes = Vec(FetchWidth*2, FuType()) 75 val fuOpTypes = Vec(FetchWidth*2, FuOpType()) 76} 77 78// Dequeue DecodeWidth insts from Ibuffer 79class CtrlFlow extends XSBundle { 80 val instr = UInt(32.W) 81 val pc = UInt(VAddrBits.W) 82 val fetchOffset = UInt((log2Up(FetchWidth * 4)).W) 83 val pnpc = UInt(VAddrBits.W) 84 val hist = UInt(HistoryLength.W) 85 // val btbVictimWay = UInt(log2Up(BtbWays).W) 86 val btbPredCtr = UInt(2.W) 87 val btbHit = Bool() 88 val tageMeta = new TageMeta 89 val rasSp = UInt(log2Up(RasSize).W) 90 val rasTopCtr = UInt(8.W) 91 val exceptionVec = Vec(16, Bool()) 92 val intrVec = Vec(12, Bool()) 93 val isRVC = Bool() 94 val isBr = Bool() 95 val crossPageIPFFix = Bool() 96} 97 98// Decode DecodeWidth insts at Decode Stage 99class CtrlSignals extends XSBundle { 100 val src1Type, src2Type, src3Type = SrcType() 101 val lsrc1, lsrc2, lsrc3 = UInt(5.W) 102 val ldest = UInt(5.W) 103 val fuType = FuType() 104 val fuOpType = FuOpType() 105 val rfWen = Bool() 106 val fpWen = Bool() 107 val isXSTrap = Bool() 108 val noSpecExec = Bool() // This inst can not be speculated 109 val isBlocked = Bool() // This inst requires pipeline to be blocked 110 val isRVF = Bool() 111 val imm = UInt(XLEN.W) 112} 113 114class CfCtrl extends XSBundle { 115 val cf = new CtrlFlow 116 val ctrl = new CtrlSignals 117 val brTag = new BrqPtr 118} 119 120// CfCtrl -> MicroOp at Rename Stage 121class MicroOp extends CfCtrl { 122 123 val psrc1, psrc2, psrc3, pdest, old_pdest = UInt(PhyRegIdxWidth.W) 124 val src1State, src2State, src3State = SrcState() 125 val roqIdx = UInt(RoqIdxWidth.W) 126} 127 128class Redirect extends XSBundle { 129 val pc = UInt(VAddrBits.W) // wrongly predicted pc 130 val target = UInt(VAddrBits.W) 131 val brTarget = UInt(VAddrBits.W) 132 val brTag = new BrqPtr 133 val btbType = UInt(2.W) 134 val isRVC = Bool() 135 //val isCall = Bool() 136 val taken = Bool() 137 val hist = UInt(HistoryLength.W) 138 val tageMeta = new TageMeta 139 val fetchIdx = UInt(log2Up(FetchWidth*2).W) 140 // val btbVictimWay = UInt(log2Up(BtbWays).W) 141 val btbPredCtr = UInt(2.W) 142 val btbHit = Bool() 143 val rasSp = UInt(log2Up(RasSize).W) 144 val rasTopCtr = UInt(8.W) 145 val isException = Bool() 146 val roqIdx = UInt(RoqIdxWidth.W) 147} 148 149class RedirectInfo extends XSBundle { 150 151 val valid = Bool() // a valid commit form brq/roq 152 val misPred = Bool() // a branch miss prediction ? 153 val redirect = new Redirect 154 155 def flush():Bool = valid && (redirect.isException || misPred) 156} 157 158class Dp1ToDp2IO extends XSBundle { 159 val intDqToDp2 = Vec(IntDqDeqWidth, DecoupledIO(new MicroOp)) 160 val fpDqToDp2 = Vec(FpDqDeqWidth, DecoupledIO(new MicroOp)) 161 val lsDqToDp2 = Vec(LsDqDeqWidth, DecoupledIO(new MicroOp)) 162} 163 164class DebugBundle extends XSBundle{ 165 val isMMIO = Bool() 166} 167 168class ExuInput extends XSBundle { 169 val uop = new MicroOp 170 val src1, src2, src3 = UInt(XLEN.W) 171} 172 173class ExuOutput extends XSBundle { 174 val uop = new MicroOp 175 val data = UInt(XLEN.W) 176 val redirectValid = Bool() 177 val redirect = new Redirect 178 val debug = new DebugBundle 179} 180 181class ExuIO extends XSBundle { 182 val in = Flipped(DecoupledIO(new ExuInput)) 183 val redirect = Flipped(ValidIO(new Redirect)) 184 val out = DecoupledIO(new ExuOutput) 185 // for csr 186 val exception = Flipped(ValidIO(new MicroOp)) 187 // for Lsu 188 val dmem = new SimpleBusUC 189 val scommit = Input(UInt(3.W)) 190} 191 192class RoqCommit extends XSBundle { 193 val uop = new MicroOp 194 val isWalk = Bool() 195} 196 197class FrontendToBackendIO extends XSBundle { 198 // to backend end 199 val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow)) 200 // from backend 201 val redirectInfo = Input(new RedirectInfo) 202 val inOrderBrInfo = Input(new RedirectInfo) 203} 204