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