xref: /XiangShan/src/main/scala/xiangshan/backend/rename/RenameTable.scala (revision 66314a3840e5ebe6cc81ca4725bde95942f67489)
1package xiangshan.backend.rename
2
3import chisel3._
4import chisel3.util._
5import chisel3.util.experimental.BoringUtils
6import xiangshan._
7
8class RatReadPort extends XSBundle {
9  val addr = Input(UInt(5.W))
10  val rdata = Output(UInt(XLEN.W))
11}
12
13class RatWritePort extends XSBundle {
14  val wen = Input(Bool())
15  val addr = Input(UInt(5.W))
16  val wdata = Input(UInt(XLEN.W))
17}
18
19class RenameTable(float: Boolean) extends XSModule {
20  val io = IO(new Bundle() {
21    val flush = Input(Bool())
22    val readPorts = Vec({if(float) 4 else 3} * RenameWidth, new RatReadPort)
23    val specWritePorts = Vec(RenameWidth, new RatWritePort)
24    val archWritePorts = Vec(CommitWidth, new RatWritePort)
25  })
26
27  // speculative rename table
28  val spec_table = RegInit(VecInit(Seq.tabulate(32)(i => i.U(PhyRegIdxWidth.W))))
29
30  // arch state rename table
31  val arch_table = RegInit(VecInit(Seq.tabulate(32)(i => i.U(PhyRegIdxWidth.W))))
32
33  for(w <- io.specWritePorts){
34    when(w.wen){ spec_table(w.addr) := w.wdata }
35  }
36
37  for((r, i) <- io.readPorts.zipWithIndex){
38    r.rdata := spec_table(r.addr)
39    for(w <- io.specWritePorts.take(i/{if(float) 4 else 3})){ // bypass
40      when(w.wen && (w.addr === r.addr)){ r.rdata := w.wdata }
41    }
42  }
43
44  for(w <- io.archWritePorts){
45    when(w.wen){ arch_table(w.addr) := w.wdata }
46  }
47
48  when(io.flush){
49    spec_table := arch_table
50  }
51
52  BoringUtils.addSource(arch_table, if(float) "DEBUG_FP_ARCH_RAT" else "DEBUG_INI_ARCH_RAT")
53}