xref: /XiangShan/src/main/scala/xiangshan/backend/rename/RenameTable.scala (revision 2d7c7105479bec3c329cf213502bd6a01cff7c0a)
1package xiangshan.backend.rename
2
3import chisel3._
4import chisel3.util._
5import xiangshan._
6
7class RatReadPort extends XSBundle {
8  val addr = Input(UInt(5.W))
9  val rdata = Output(UInt(PhyRegIdxWidth.W))
10}
11
12class RatWritePort extends XSBundle {
13  val wen = Input(Bool())
14  val addr = Input(UInt(5.W))
15  val wdata = Input(UInt(PhyRegIdxWidth.W))
16}
17
18class RenameTable(float: Boolean) extends XSModule {
19  val io = IO(new Bundle() {
20    val redirect = Input(Bool())
21    val flush = Input(Bool())
22    val walkWen = Input(Bool())
23    val readPorts = Vec({if(float) 4 else 3} * RenameWidth, new RatReadPort)
24    val specWritePorts = Vec(CommitWidth, new RatWritePort)
25    val archWritePorts = Vec(CommitWidth, new RatWritePort)
26  })
27
28  // speculative rename table
29  val spec_table = RegInit(VecInit(Seq.tabulate(32)(i => i.U(PhyRegIdxWidth.W))))
30
31  // arch state rename table
32  val arch_table = RegInit(VecInit(Seq.tabulate(32)(i => i.U(PhyRegIdxWidth.W))))
33
34  // When redirect happens (mis-prediction), don't update the rename table
35  // However, when mis-prediction and walk happens at the same time, rename table needs to be updated
36  for (w <- io.specWritePorts){
37    when (w.wen && (!(io.redirect || io.flush) || io.walkWen)) {
38      spec_table(w.addr) := w.wdata
39    }
40  }
41
42  for((r, i) <- io.readPorts.zipWithIndex){
43    r.rdata := spec_table(r.addr)
44    // for(w <- io.specWritePorts.take(i/{if(float) 4 else 3})){ // bypass
45    //   when(w.wen && (w.addr === r.addr)){ r.rdata := w.wdata }
46    // }
47  }
48
49  for(w <- io.archWritePorts){
50    when(w.wen){ arch_table(w.addr) := w.wdata }
51  }
52
53  when (io.flush) {
54    spec_table := arch_table
55    // spec table needs to be updated when flushPipe
56    for (w <- io.archWritePorts) {
57      when(w.wen){ spec_table(w.addr) := w.wdata }
58    }
59  }
60
61  if (!env.FPGAPlatform) {
62    ExcitingUtils.addSource(
63      arch_table,
64      if(float) "DEBUG_FP_ARCH_RAT" else "DEBUG_INI_ARCH_RAT",
65      ExcitingUtils.Debug
66    )
67  }
68}
69