1package xiangshan 2 3import chisel3._ 4import chisel3.util._ 5import bus.simplebus._ 6import xiangshan.backend.brq.BrqPtr 7import xiangshan.backend.rename.FreeListPtr 8import xiangshan.frontend.PreDecodeInfo 9import xiangshan.frontend.HasBPUParameter 10 11// Fetch FetchWidth x 32-bit insts from Icache 12class FetchPacket extends XSBundle { 13 val instrs = Vec(PredictWidth, UInt(32.W)) 14 val mask = UInt(PredictWidth.W) 15 // val pc = UInt(VAddrBits.W) 16 val pc = Vec(PredictWidth, UInt(VAddrBits.W)) 17 val pnpc = Vec(PredictWidth, UInt(VAddrBits.W)) 18 val brInfo = Vec(PredictWidth, new BranchInfo) 19 val pd = Vec(PredictWidth, new PreDecodeInfo) 20} 21 22class ValidUndirectioned[T <: Data](gen: T) extends Bundle { 23 val valid = Bool() 24 val bits = gen.cloneType.asInstanceOf[T] 25 override def cloneType = new ValidUndirectioned(gen).asInstanceOf[this.type] 26} 27 28object ValidUndirectioned { 29 def apply[T <: Data](gen: T) = { 30 new ValidUndirectioned[T](gen) 31 } 32} 33 34class TageMeta extends XSBundle { 35 def TageNTables = 6 36 val provider = ValidUndirectioned(UInt(log2Ceil(TageNTables).W)) 37 val altDiffers = Bool() 38 val providerU = UInt(2.W) 39 val providerCtr = UInt(3.W) 40 val allocate = ValidUndirectioned(UInt(log2Ceil(TageNTables).W)) 41} 42 43class BranchPrediction extends XSBundle { 44 val redirect = Bool() 45 val taken = Bool() 46 val jmpIdx = UInt(log2Up(PredictWidth).W) 47 val hasNotTakenBrs = Bool() 48 val target = UInt(VAddrBits.W) 49 val saveHalfRVI = Bool() 50 val takenOnBr = Bool() 51} 52 53class BranchInfo extends XSBundle with HasBPUParameter { 54 val ubtbWriteWay = UInt(log2Up(UBtbWays).W) 55 val ubtbHits = Bool() 56 val btbWriteWay = UInt(log2Up(BtbWays).W) 57 val btbHitJal = Bool() 58 val bimCtr = UInt(2.W) 59 val histPtr = UInt(log2Up(ExtHistoryLength).W) 60 val tageMeta = new TageMeta 61 val rasSp = UInt(log2Up(RasSize).W) 62 val rasTopCtr = UInt(8.W) 63 val rasToqAddr = UInt(VAddrBits.W) 64 val fetchIdx = UInt(log2Up(PredictWidth).W) 65 val specCnt = UInt(10.W) 66 val sawNotTakenBranch = Bool() 67 68 val debug_ubtb_cycle = if (BPUDebug) UInt(64.W) else UInt(0.W) 69 val debug_btb_cycle = if (BPUDebug) UInt(64.W) else UInt(0.W) 70 val debug_tage_cycle = if (BPUDebug) UInt(64.W) else UInt(0.W) 71 72 def apply(histPtr: UInt, tageMeta: TageMeta, rasSp: UInt, rasTopCtr: UInt) = { 73 this.histPtr := histPtr 74 this.tageMeta := tageMeta 75 this.rasSp := rasSp 76 this.rasTopCtr := rasTopCtr 77 this.asUInt 78 } 79 def size = 0.U.asTypeOf(this).getWidth 80 def fromUInt(x: UInt) = x.asTypeOf(this) 81} 82 83class Predecode extends XSBundle { 84 val isFetchpcEqualFirstpc = Bool() 85 val mask = UInt((FetchWidth*2).W) 86 val pd = Vec(FetchWidth*2, (new PreDecodeInfo)) 87} 88 89class BranchUpdateInfo extends XSBundle { 90 // from backend 91 val pc = UInt(VAddrBits.W) 92 val pnpc = UInt(VAddrBits.W) 93 val target = UInt(VAddrBits.W) 94 val brTarget = UInt(VAddrBits.W) 95 val taken = Bool() 96 val fetchIdx = UInt(log2Up(FetchWidth*2).W) 97 val isMisPred = Bool() 98 val brTag = new BrqPtr 99 100 // frontend -> backend -> frontend 101 val pd = new PreDecodeInfo 102 val brInfo = new BranchInfo 103} 104 105// Dequeue DecodeWidth insts from Ibuffer 106class CtrlFlow extends XSBundle { 107 val instr = UInt(32.W) 108 val pc = UInt(VAddrBits.W) 109 val exceptionVec = Vec(16, Bool()) 110 val intrVec = Vec(12, Bool()) 111 val brUpdate = new BranchUpdateInfo 112 val crossPageIPFFix = Bool() 113} 114 115// Decode DecodeWidth insts at Decode Stage 116class CtrlSignals extends XSBundle { 117 val src1Type, src2Type, src3Type = SrcType() 118 val lsrc1, lsrc2, lsrc3 = UInt(5.W) 119 val ldest = UInt(5.W) 120 val fuType = FuType() 121 val fuOpType = FuOpType() 122 val rfWen = Bool() 123 val fpWen = Bool() 124 val isXSTrap = Bool() 125 val noSpecExec = Bool() // This inst can not be speculated 126 val isBlocked = Bool() // This inst requires pipeline to be blocked 127 val isRVF = Bool() 128 val imm = UInt(XLEN.W) 129} 130 131class CfCtrl extends XSBundle { 132 val cf = new CtrlFlow 133 val ctrl = new CtrlSignals 134 val brTag = new BrqPtr 135} 136 137trait HasRoqIdx { this: HasXSParameter => 138 val roqIdx = UInt(RoqIdxWidth.W) 139 def needFlush(redirect: Valid[Redirect]): Bool = { 140 redirect.valid && Mux( 141 this.roqIdx.head(1) === redirect.bits.roqIdx.head(1), 142 this.roqIdx.tail(1) > redirect.bits.roqIdx.tail(1), 143 this.roqIdx.tail(1) < redirect.bits.roqIdx.tail(1) 144 ) 145 } 146} 147 148// CfCtrl -> MicroOp at Rename Stage 149class MicroOp extends CfCtrl with HasRoqIdx { 150 val psrc1, psrc2, psrc3, pdest, old_pdest = UInt(PhyRegIdxWidth.W) 151 val src1State, src2State, src3State = SrcState() 152} 153 154class Redirect extends XSBundle with HasRoqIdx { 155 val isException = Bool() 156 val isMisPred = Bool() 157 val isReplay = Bool() 158 val pc = UInt(VAddrBits.W) 159 val target = UInt(VAddrBits.W) 160 val brTag = new BrqPtr 161} 162 163class Dp1ToDp2IO extends XSBundle { 164 val intDqToDp2 = Vec(IntDqDeqWidth, DecoupledIO(new MicroOp)) 165 val fpDqToDp2 = Vec(FpDqDeqWidth, DecoupledIO(new MicroOp)) 166 val lsDqToDp2 = Vec(LsDqDeqWidth, DecoupledIO(new MicroOp)) 167} 168 169class DebugBundle extends XSBundle{ 170 val isMMIO = Bool() 171} 172 173class ExuInput extends XSBundle { 174 val uop = new MicroOp 175 val src1, src2, src3 = UInt(XLEN.W) 176} 177 178class ExuOutput extends XSBundle { 179 val uop = new MicroOp 180 val data = UInt(XLEN.W) 181 val redirectValid = Bool() 182 val redirect = new Redirect 183 val brUpdate = new BranchUpdateInfo 184 val debug = new DebugBundle 185} 186 187class ExuIO extends XSBundle { 188 val in = Flipped(DecoupledIO(new ExuInput)) 189 val redirect = Flipped(ValidIO(new Redirect)) 190 val out = DecoupledIO(new ExuOutput) 191 // for csr 192 val exception = Flipped(ValidIO(new MicroOp)) 193 // for Lsu 194 val dmem = new SimpleBusUC 195 val scommit = Input(UInt(3.W)) 196} 197 198class RoqCommit extends XSBundle { 199 val uop = new MicroOp 200 val isWalk = Bool() 201} 202 203class FrontendToBackendIO extends XSBundle { 204 // to backend end 205 val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow)) 206 // from backend 207 val redirect = Flipped(ValidIO(new Redirect)) 208 val outOfOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 209 val inOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 210} 211