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