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.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 val provider = ValidUndirectioned(UInt(log2Ceil(TageNTables).W)) 35 val altDiffers = Bool() 36 val providerU = UInt(2.W) 37 val providerCtr = UInt(3.W) 38 val allocate = ValidUndirectioned(UInt(log2Ceil(TageNTables).W)) 39} 40 41class BranchPrediction extends XSBundle { 42 val redirect = Bool() 43 val jmpIdx = UInt(log2Up(PredictWidth).W) 44 val hasNotTakenBrs = Bool() 45 val target = UInt(VAddrBits.W) 46 val saveHalfRVI = Bool() 47 val taken = Bool() 48} 49 50class BranchInfo extends XSBundle { 51 val ubtbWriteWay = UInt(log2Up(UBtbWays).W) 52 val ubtbHits = Vec(PredictWidth, Bool()) 53 val btbWriteWay = UInt(log2Up(BtbWays).W) 54 val bimCtrs = Vec(PredictWidth, UInt(2.W)) 55 val histPtr = UInt(log2Up(ExtHistoryLength).W) 56 val tageMeta = new TageMeta 57 val rasSp = UInt(log2Up(RasSize).W) 58 val rasTopCtr = UInt(8.W) 59 60 def apply(histPtr: UInt, tageMeta: TageMeta, rasSp: UInt, rasTopCtr: UInt) = { 61 this.histPtr := histPtr 62 this.tageMeta := tageMeta 63 this.rasSp := rasSp 64 this.rasTopCtr := rasTopCtr 65 this.asUInt 66 } 67 def size = 0.U.asTypeOf(this).getWidth 68 def fromUInt(x: UInt) = x.asTypeOf(this) 69} 70 71class Predecode extends XSBundle { 72 val mask = UInt((FetchWidth*2).W) 73 val pd = Vec(FetchWidth*2, (new PreDecodeInfo)) 74} 75 76class BranchUpdateInfo extends XSBundle { 77 // from backend 78 val pnpc = UInt(VAddrBits.W) 79 val brTarget = UInt(VAddrBits.W) 80 val taken = Bool() 81 val fetchIdx = UInt(log2Up(FetchWidth*2).W) 82 val isMisPred = Bool() 83 84 // frontend -> backend -> frontend 85 val pd = new PreDecodeInfo 86 val brInfo = new BranchInfo 87} 88 89// Dequeue DecodeWidth insts from Ibuffer 90class CtrlFlow extends XSBundle { 91 val instr = UInt(32.W) 92 val pc = UInt(VAddrBits.W) 93 val exceptionVec = Vec(16, Bool()) 94 val intrVec = Vec(12, Bool()) 95 val brUpdate = new BranchUpdateInfo 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 121trait HasRoqIdx { this: HasXSParameter => 122 val roqIdx = UInt(RoqIdxWidth.W) 123 def needFlush(redirect: Valid[Redirect]): Bool = { 124 redirect.valid && Mux( 125 this.roqIdx.head(1) === redirect.bits.roqIdx.head(1), 126 this.roqIdx.tail(1) > redirect.bits.roqIdx.tail(1), 127 this.roqIdx.tail(1) < redirect.bits.roqIdx.tail(1) 128 ) 129 } 130} 131 132// CfCtrl -> MicroOp at Rename Stage 133class MicroOp extends CfCtrl with HasRoqIdx { 134 val psrc1, psrc2, psrc3, pdest, old_pdest = UInt(PhyRegIdxWidth.W) 135 val src1State, src2State, src3State = SrcState() 136} 137 138class Redirect extends XSBundle with HasRoqIdx { 139 val isException = Bool() 140 val isMisPred = Bool() 141 val isReplay = Bool() 142 val pc = UInt(VAddrBits.W) 143 val target = UInt(VAddrBits.W) 144 val brTag = new BrqPtr 145} 146 147class Dp1ToDp2IO extends XSBundle { 148 val intDqToDp2 = Vec(IntDqDeqWidth, DecoupledIO(new MicroOp)) 149 val fpDqToDp2 = Vec(FpDqDeqWidth, DecoupledIO(new MicroOp)) 150 val lsDqToDp2 = Vec(LsDqDeqWidth, DecoupledIO(new MicroOp)) 151} 152 153class DebugBundle extends XSBundle{ 154 val isMMIO = Bool() 155} 156 157class ExuInput extends XSBundle { 158 val uop = new MicroOp 159 val src1, src2, src3 = UInt(XLEN.W) 160} 161 162class ExuOutput extends XSBundle { 163 val uop = new MicroOp 164 val data = UInt(XLEN.W) 165 val redirectValid = Bool() 166 val redirect = new Redirect 167 val brUpdate = new BranchUpdateInfo 168 val debug = new DebugBundle 169} 170 171class ExuIO extends XSBundle { 172 val in = Flipped(DecoupledIO(new ExuInput)) 173 val redirect = Flipped(ValidIO(new Redirect)) 174 val out = DecoupledIO(new ExuOutput) 175 // for csr 176 val exception = Flipped(ValidIO(new MicroOp)) 177 // for Lsu 178 val dmem = new SimpleBusUC 179 val scommit = Input(UInt(3.W)) 180} 181 182class RoqCommit extends XSBundle { 183 val uop = new MicroOp 184 val isWalk = Bool() 185} 186 187class FrontendToBackendIO extends XSBundle { 188 // to backend end 189 val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow)) 190 // from backend 191 val redirect = Flipped(ValidIO(new Redirect)) 192 val outOfOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 193 val inOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 194} 195