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 def apply(histPtr: UInt, tageMeta: TageMeta, rasSp: UInt, rasTopCtr: UInt) = { 63 this.histPtr := histPtr 64 this.tageMeta := tageMeta 65 this.rasSp := rasSp 66 this.rasTopCtr := rasTopCtr 67 this.asUInt 68 } 69 def size = 0.U.asTypeOf(this).getWidth 70 def fromUInt(x: UInt) = x.asTypeOf(this) 71} 72 73class Predecode extends XSBundle { 74 val mask = UInt((FetchWidth*2).W) 75 val pd = Vec(FetchWidth*2, (new PreDecodeInfo)) 76} 77 78class BranchUpdateInfo extends XSBundle { 79 // from backend 80 val pc = UInt(VAddrBits.W) 81 val pnpc = UInt(VAddrBits.W) 82 val target = UInt(VAddrBits.W) 83 val brTarget = UInt(VAddrBits.W) 84 val taken = Bool() 85 val fetchIdx = UInt(log2Up(FetchWidth*2).W) 86 val isMisPred = Bool() 87 88 // frontend -> backend -> frontend 89 val pd = new PreDecodeInfo 90 val brInfo = new BranchInfo 91} 92 93// Dequeue DecodeWidth insts from Ibuffer 94class CtrlFlow extends XSBundle { 95 val instr = UInt(32.W) 96 val pc = UInt(VAddrBits.W) 97 val exceptionVec = Vec(16, Bool()) 98 val intrVec = Vec(12, Bool()) 99 val brUpdate = new BranchUpdateInfo 100 val crossPageIPFFix = Bool() 101} 102 103// Decode DecodeWidth insts at Decode Stage 104class CtrlSignals extends XSBundle { 105 val src1Type, src2Type, src3Type = SrcType() 106 val lsrc1, lsrc2, lsrc3 = UInt(5.W) 107 val ldest = UInt(5.W) 108 val fuType = FuType() 109 val fuOpType = FuOpType() 110 val rfWen = Bool() 111 val fpWen = Bool() 112 val isXSTrap = Bool() 113 val noSpecExec = Bool() // This inst can not be speculated 114 val isBlocked = Bool() // This inst requires pipeline to be blocked 115 val isRVF = Bool() 116 val imm = UInt(XLEN.W) 117} 118 119class CfCtrl extends XSBundle { 120 val cf = new CtrlFlow 121 val ctrl = new CtrlSignals 122 val brTag = new BrqPtr 123} 124 125trait HasRoqIdx { this: HasXSParameter => 126 val roqIdx = UInt(RoqIdxWidth.W) 127 def needFlush(redirect: Valid[Redirect]): Bool = { 128 redirect.valid && Mux( 129 this.roqIdx.head(1) === redirect.bits.roqIdx.head(1), 130 this.roqIdx.tail(1) > redirect.bits.roqIdx.tail(1), 131 this.roqIdx.tail(1) < redirect.bits.roqIdx.tail(1) 132 ) 133 } 134} 135 136// CfCtrl -> MicroOp at Rename Stage 137class MicroOp extends CfCtrl with HasRoqIdx { 138 val psrc1, psrc2, psrc3, pdest, old_pdest = UInt(PhyRegIdxWidth.W) 139 val src1State, src2State, src3State = SrcState() 140} 141 142class Redirect extends XSBundle with HasRoqIdx { 143 val isException = Bool() 144 val isMisPred = Bool() 145 val isReplay = Bool() 146 val pc = UInt(VAddrBits.W) 147 val target = UInt(VAddrBits.W) 148 val brTag = new BrqPtr 149} 150 151class Dp1ToDp2IO extends XSBundle { 152 val intDqToDp2 = Vec(IntDqDeqWidth, DecoupledIO(new MicroOp)) 153 val fpDqToDp2 = Vec(FpDqDeqWidth, DecoupledIO(new MicroOp)) 154 val lsDqToDp2 = Vec(LsDqDeqWidth, DecoupledIO(new MicroOp)) 155} 156 157class DebugBundle extends XSBundle{ 158 val isMMIO = Bool() 159} 160 161class ExuInput extends XSBundle { 162 val uop = new MicroOp 163 val src1, src2, src3 = UInt(XLEN.W) 164} 165 166class ExuOutput extends XSBundle { 167 val uop = new MicroOp 168 val data = UInt(XLEN.W) 169 val redirectValid = Bool() 170 val redirect = new Redirect 171 val brUpdate = new BranchUpdateInfo 172 val debug = new DebugBundle 173} 174 175class ExuIO extends XSBundle { 176 val in = Flipped(DecoupledIO(new ExuInput)) 177 val redirect = Flipped(ValidIO(new Redirect)) 178 val out = DecoupledIO(new ExuOutput) 179 // for csr 180 val exception = Flipped(ValidIO(new MicroOp)) 181 // for Lsu 182 val dmem = new SimpleBusUC 183 val scommit = Input(UInt(3.W)) 184} 185 186class RoqCommit extends XSBundle { 187 val uop = new MicroOp 188 val isWalk = Bool() 189} 190 191class FrontendToBackendIO extends XSBundle { 192 // to backend end 193 val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow)) 194 // from backend 195 val redirect = Flipped(ValidIO(new Redirect)) 196 val outOfOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 197 val inOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 198} 199