BusyTable.scala 1.3 KB
Newer Older
1 2 3 4 5
package xiangshan.backend.rename

import chisel3._
import chisel3.util._
import xiangshan._
L
LinJiawei 已提交
6
import utils.{ParallelOR, XSDebug}
7 8 9 10 11 12

class BusyTable extends XSModule {
  val io = IO(new Bundle() {
    val flush = Input(Bool())
    // set preg state to busy
    val allocPregs = Vec(RenameWidth, Flipped(ValidIO(UInt(PhyRegIdxWidth.W))))
L
linjiawei 已提交
13 14
    // set preg state to ready (write back regfile + roq walk)
    val wbPregs = Vec(NRWritePorts + CommitWidth, Flipped(ValidIO(UInt(PhyRegIdxWidth.W))))
15 16 17 18 19 20 21 22
    // read preg state
    val rfReadAddr = Vec(NRReadPorts, Input(UInt(PhyRegIdxWidth.W)))
    val pregRdy = Vec(NRReadPorts, Output(Bool()))
  })

  val table = RegInit(VecInit(Seq.fill(NRPhyRegs)(false.B)))

  for((raddr, rdy) <- io.rfReadAddr.zip(io.pregRdy)){
L
LinJiawei 已提交
23
    rdy := !table(raddr) || ParallelOR(io.wbPregs.map(wb => wb.valid && (wb.bits===raddr))).asBool()
24 25 26 27 28 29
  }

  for((alloc, i) <- io.allocPregs.zipWithIndex){
    when(alloc.valid){
      table(alloc.bits) := true.B
    }
Y
Yinan Xu 已提交
30
    XSDebug(alloc.valid, "Allocate %d\n", alloc.bits)
31 32 33 34 35 36
  }

  for((wb, i) <- io.wbPregs.zipWithIndex){
    when(wb.valid){
      table(wb.bits) := false.B
    }
Y
Yinan Xu 已提交
37
    XSDebug(wb.valid, "writeback %d\n", wb.bits)
38 39 40 41 42
  }

  when(io.flush){
    table.foreach(_ := false.B)
  }
Y
Yinan Xu 已提交
43 44 45 46

  for (i <- 0 until NRPhyRegs) {
    XSDebug(table(i), "%d is busy\n", i.U)
  }
47
}