1package xiangshan 2 3import chisel3._ 4import chisel3.util._ 5import bus.simplebus._ 6import xiangshan.backend.brq.BrqPtr 7import xiangshan.backend.rename.FreeListPtr 8import xiangshan.frontend.PDecodeInfo 9 10// Fetch FetchWidth x 32-bit insts from Icache 11class FetchPacket extends XSBundle { 12 val instrs = Vec(FetchWidth, UInt(32.W)) 13 val mask = UInt((FetchWidth*2).W) 14 val pc = UInt(VAddrBits.W) // the pc of first inst in the fetch group 15 val pnpc = Vec(FetchWidth*2, UInt(VAddrBits.W)) 16 val hist = Vec(FetchWidth*2, UInt(HistoryLength.W)) 17 // val btbVictimWay = UInt(log2Up(BtbWays).W) 18 val predCtr = Vec(FetchWidth*2, UInt(2.W)) 19 val btbHit = Vec(FetchWidth*2, Bool()) 20 val tageMeta = Vec(FetchWidth*2, (new TageMeta)) 21 val rasSp = UInt(log2Up(RasSize).W) 22 val rasTopCtr = UInt(8.W) 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 val pd = Vec(FetchWidth*2, (new PDecodeInfo)) 77} 78 79// Dequeue DecodeWidth insts from Ibuffer 80class CtrlFlow extends XSBundle { 81 val instr = UInt(32.W) 82 val pc = UInt(VAddrBits.W) 83 val fetchOffset = UInt((log2Up(FetchWidth * 4)).W) 84 val pnpc = UInt(VAddrBits.W) 85 val hist = UInt(HistoryLength.W) 86 // val btbVictimWay = UInt(log2Up(BtbWays).W) 87 val btbPredCtr = UInt(2.W) 88 val btbHit = Bool() 89 val tageMeta = new TageMeta 90 val rasSp = UInt(log2Up(RasSize).W) 91 val rasTopCtr = UInt(8.W) 92 val exceptionVec = Vec(16, Bool()) 93 val intrVec = Vec(12, Bool()) 94 val isRVC = Bool() 95 val isBr = Bool() 96 val crossPageIPFFix = Bool() 97} 98 99// Decode DecodeWidth insts at Decode Stage 100class CtrlSignals extends XSBundle { 101 val src1Type, src2Type, src3Type = SrcType() 102 val lsrc1, lsrc2, lsrc3 = UInt(5.W) 103 val ldest = UInt(5.W) 104 val fuType = FuType() 105 val fuOpType = FuOpType() 106 val rfWen = Bool() 107 val fpWen = Bool() 108 val isXSTrap = Bool() 109 val noSpecExec = Bool() // This inst can not be speculated 110 val isBlocked = Bool() // This inst requires pipeline to be blocked 111 val isRVF = Bool() 112 val imm = UInt(XLEN.W) 113} 114 115class CfCtrl extends XSBundle { 116 val cf = new CtrlFlow 117 val ctrl = new CtrlSignals 118 val brTag = new BrqPtr 119} 120 121// CfCtrl -> MicroOp at Rename Stage 122class MicroOp extends CfCtrl { 123 124 val psrc1, psrc2, psrc3, pdest, old_pdest = UInt(PhyRegIdxWidth.W) 125 val src1State, src2State, src3State = SrcState() 126 val roqIdx = UInt(RoqIdxWidth.W) 127} 128 129class Redirect extends XSBundle { 130 val pc = UInt(VAddrBits.W) // wrongly predicted pc 131 val target = UInt(VAddrBits.W) 132 val brTarget = UInt(VAddrBits.W) 133 val brTag = new BrqPtr 134 val btbType = UInt(2.W) 135 val isRVC = Bool() 136 //val isCall = Bool() 137 val taken = Bool() 138 val hist = UInt(HistoryLength.W) 139 val tageMeta = new TageMeta 140 val fetchIdx = UInt(log2Up(FetchWidth*2).W) 141 // val btbVictimWay = UInt(log2Up(BtbWays).W) 142 val btbPredCtr = UInt(2.W) 143 val btbHit = Bool() 144 val rasSp = UInt(log2Up(RasSize).W) 145 val rasTopCtr = UInt(8.W) 146 val isException = Bool() 147 val roqIdx = UInt(RoqIdxWidth.W) 148} 149 150class RedirectInfo extends XSBundle { 151 152 val valid = Bool() // a valid commit form brq/roq 153 val misPred = Bool() // a branch miss prediction ? 154 val redirect = new Redirect 155 156 def flush():Bool = valid && (redirect.isException || misPred) 157} 158 159class Dp1ToDp2IO extends XSBundle { 160 val intDqToDp2 = Vec(IntDqDeqWidth, DecoupledIO(new MicroOp)) 161 val fpDqToDp2 = Vec(FpDqDeqWidth, DecoupledIO(new MicroOp)) 162 val lsDqToDp2 = Vec(LsDqDeqWidth, DecoupledIO(new MicroOp)) 163} 164 165class DebugBundle extends XSBundle{ 166 val isMMIO = Bool() 167} 168 169class ExuInput extends XSBundle { 170 val uop = new MicroOp 171 val src1, src2, src3 = UInt(XLEN.W) 172} 173 174class ExuOutput extends XSBundle { 175 val uop = new MicroOp 176 val data = UInt(XLEN.W) 177 val redirectValid = Bool() 178 val redirect = new Redirect 179 val debug = new DebugBundle 180} 181 182class ExuIO extends XSBundle { 183 val in = Flipped(DecoupledIO(new ExuInput)) 184 val redirect = Flipped(ValidIO(new Redirect)) 185 val out = DecoupledIO(new ExuOutput) 186 // for csr 187 val exception = Flipped(ValidIO(new MicroOp)) 188 // for Lsu 189 val dmem = new SimpleBusUC 190 val scommit = Input(UInt(3.W)) 191} 192 193class RoqCommit extends XSBundle { 194 val uop = new MicroOp 195 val isWalk = Bool() 196} 197 198class FrontendToBackendIO extends XSBundle { 199 // to backend end 200 val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow)) 201 // from backend 202 val redirectInfo = Input(new RedirectInfo) 203 val inOrderBrInfo = Input(new RedirectInfo) 204} 205