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(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 46class BranchPrediction extends XSBundle { 47 val redirect = Bool() 48 val jmpIdx = UInt(log2Up(PredictWidth).W) 49 val target = UInt(VAddrBits.W) 50 val saveHalfRVI = Bool() 51} 52 53class BranchInfo extends XSBundle { 54 val histPtr = UInt(log2Up(ExtHistoryLength).W) 55 val tageMeta = new TageMeta 56 val rasSp = UInt(log2Up(RasSize).W) 57 val rasTopCtr = UInt(8.W) 58 59 def apply(histPtr: UInt, tageMeta: TageMeta, rasSp: UInt, rasTopCtr: UInt) = { 60 this.histPtr := histPtr 61 this.tageMeta := tageMeta 62 this.rasSp := rasSp 63 this.rasTopCtr 64 this.asUInt 65 } 66 def size = 0.U.asTypeOf(this).getWidth 67 def fromUInt(x: UInt) = x.asTypeOf(this) 68} 69 70class Predecode extends XSBundle { 71 val mask = UInt((FetchWidth*2).W) 72 val pd = Vec(FetchWidth*2, (new PreDecodeInfo)) 73} 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 val histPtr = UInt(log2Up(ExtHistoryLength).W) 146} 147 148class Dp1ToDp2IO extends XSBundle { 149 val intDqToDp2 = Vec(IntDqDeqWidth, DecoupledIO(new MicroOp)) 150 val fpDqToDp2 = Vec(FpDqDeqWidth, DecoupledIO(new MicroOp)) 151 val lsDqToDp2 = Vec(LsDqDeqWidth, DecoupledIO(new MicroOp)) 152} 153 154class DebugBundle extends XSBundle{ 155 val isMMIO = Bool() 156} 157 158class ExuInput extends XSBundle { 159 val uop = new MicroOp 160 val src1, src2, src3 = UInt(XLEN.W) 161} 162 163class ExuOutput extends XSBundle { 164 val uop = new MicroOp 165 val data = UInt(XLEN.W) 166 val redirectValid = Bool() 167 val redirect = new Redirect 168 val brUpdate = new BranchUpdateInfo 169 val debug = new DebugBundle 170} 171 172class ExuIO extends XSBundle { 173 val in = Flipped(DecoupledIO(new ExuInput)) 174 val redirect = Flipped(ValidIO(new Redirect)) 175 val out = DecoupledIO(new ExuOutput) 176 // for csr 177 val exception = Flipped(ValidIO(new MicroOp)) 178 // for Lsu 179 val dmem = new SimpleBusUC 180 val scommit = Input(UInt(3.W)) 181} 182 183class RoqCommit extends XSBundle { 184 val uop = new MicroOp 185 val isWalk = Bool() 186} 187 188class FrontendToBackendIO extends XSBundle { 189 // to backend end 190 val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow)) 191 // from backend 192 val redirect = Flipped(ValidIO(new Redirect)) 193 val outOfOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 194 val inOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 195} 196