xref: /XiangShan/src/main/scala/xiangshan/backend/rename/RenameTable.scala (revision d9469c00c0ff92207955dcdff2c9085ea391c88f)
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(XLEN.W))
10}
11
12class RatWritePort extends XSBundle {
13  val wen = Input(Bool())
14  val addr = Input(UInt(5.W))
15  val wdata = Input(UInt(XLEN.W))
16}
17
18class RenameTable(float: Boolean) extends XSModule {
19  val io = IO(new Bundle() {
20    val redirect = Flipped(ValidIO(new Redirect))
21    val walkWen = 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  // When redirect happens (mis-prediction), don't update the rename table
34  // However, when mis-prediction and walk happens at the same time, rename table needs to be updated
35  for(w <- io.specWritePorts){
36    when(w.wen && (!io.redirect.valid || io.walkWen)) {
37      spec_table(w.addr) := w.wdata
38    }
39  }
40
41  for((r, i) <- io.readPorts.zipWithIndex){
42    r.rdata := spec_table(r.addr)
43    // for(w <- io.specWritePorts.take(i/{if(float) 4 else 3})){ // bypass
44    //   when(w.wen && (w.addr === r.addr)){ r.rdata := w.wdata }
45    // }
46  }
47
48  for(w <- io.archWritePorts){
49    when(w.wen){ arch_table(w.addr) := w.wdata }
50  }
51
52  val flush = io.redirect.valid && io.redirect.bits.isUnconditional()
53  when (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