1/*************************************************************************************** 2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3* Copyright (c) 2020-2021 Peng Cheng Laboratory 4* 5* XiangShan is licensed under Mulan PSL v2. 6* You can use this software according to the terms and conditions of the Mulan PSL v2. 7* You may obtain a copy of Mulan PSL v2 at: 8* http://license.coscl.org.cn/MulanPSL2 9* 10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13* 14* See the Mulan PSL v2 for more details. 15***************************************************************************************/ 16 17package xiangshan.mem.mdp 18 19import org.chipsalliance.cde.config.Parameters 20import chisel3._ 21import chisel3.util._ 22import xiangshan._ 23import utils._ 24import utility._ 25 26// 21264-like wait table, uses 2-bit counter 27class WaitTable(implicit p: Parameters) extends XSModule { 28 val io = IO(new Bundle { 29 // to decode 30 val raddr = Vec(DecodeWidth, Input(UInt(MemPredPCWidth.W))) // decode pc(VaddrBits-1, 1) 31 val rdata = Vec(DecodeWidth, Output(Bool())) // loadWaitBit 32 val update = Input(new MemPredUpdateReq) // RegNext should be added outside 33 val csrCtrl = Input(new CustomCSRCtrlIO) 34 }) 35 36 require(DecodeWidth == RenameWidth) 37 38 val data = RegInit(VecInit(Seq.fill(WaitTableSize)(0.U(2.W)))) 39 val resetCounter = RegInit(0.U(ResetTimeMax2Pow.W)) 40 resetCounter := resetCounter + 1.U 41 42 // read ports 43 for (i <- 0 until DecodeWidth) { 44 io.rdata(i) := (data(io.raddr(i))(LWTUse2BitCounter.B.asUInt) || io.csrCtrl.no_spec_load) && !io.csrCtrl.lvpred_disable 45 } 46 47 // write port 48 when(io.update.valid){ 49 data(io.update.waddr) := Cat(data(io.update.waddr)(0), true.B) 50 } 51 52 // reset period: ResetTimeMax2Pow 53 when(resetCounter(ResetTimeMax2Pow-1, ResetTimeMin2Pow)(RegNext(io.csrCtrl.lvpred_timeout))) { 54 for (j <- 0 until WaitTableSize) { 55 data(j) := 0.U 56 } 57 resetCounter:= 0.U 58 } 59 60 // debug 61 when (io.update.valid) { 62 XSDebug("%d: waittable update: pc %x data: %x\n", GTimer(), io.update.waddr, io.update.wdata) 63 } 64 65 XSPerfAccumulate("wait_table_bit_set", PopCount(data.map(d => d(1)))) 66} 67