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