LSQWrapper.scala 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package xiangshan.mem

import chisel3._
import chisel3.util._
import utils._
import xiangshan._
import xiangshan.cache._
import xiangshan.cache.{DCacheWordIO, DCacheLineIO, TlbRequestIO, MemoryOpConstants}
import xiangshan.backend.LSUOpType
import xiangshan.mem._

// Load / Store Queue Wrapper for XiangShan Out of Order LSU
//
// By using this Wrapper, interface of unified lsroq and ldq / stq are the same 
class LsqWrappper extends XSModule with HasDCacheParameters with NeedImpl {
  val io = IO(new Bundle() {
    val dp1Req = Vec(RenameWidth, Flipped(DecoupledIO(new MicroOp)))
18
    val lsIdxs = Output(Vec(RenameWidth, new LSIdx))
19 20 21 22 23 24 25 26 27 28 29 30 31 32
    val brqRedirect = Input(Valid(new Redirect))
    val loadIn = Vec(LoadPipelineWidth, Flipped(Valid(new LsPipelineBundle)))
    val storeIn = Vec(StorePipelineWidth, Flipped(Valid(new LsPipelineBundle)))
    val sbuffer = Vec(StorePipelineWidth, Decoupled(new DCacheWordReq))
    val ldout = Vec(2, DecoupledIO(new ExuOutput)) // writeback store
    val stout = Vec(2, DecoupledIO(new ExuOutput)) // writeback store
    val forward = Vec(LoadPipelineWidth, Flipped(new LoadForwardQueryIO))
    val commits = Flipped(Vec(CommitWidth, Valid(new RoqCommit)))
    val rollback = Output(Valid(new Redirect))
    val dcache = new DCacheLineIO
    val uncache = new DCacheWordIO
    val roqDeqPtr = Input(UInt(RoqIdxWidth.W))
  })
  
33 34
  if(EnableUnifiedLSQ){
    val lsroq = Module(new Lsroq)
35 36 37 38 39 40 41 42 43 44 45 46 47 48

    lsroq.io.dp1Req <> io.dp1Req
    lsroq.io.brqRedirect <> io.brqRedirect
    lsroq.io.loadIn <> io.loadIn
    lsroq.io.storeIn <> io.storeIn
    lsroq.io.sbuffer <> io.sbuffer
    lsroq.io.ldout <> io.ldout
    lsroq.io.stout <> io.stout
    lsroq.io.forward <> io.forward
    lsroq.io.commits <> io.commits
    lsroq.io.rollback <> io.rollback
    lsroq.io.dcache <> io.dcache
    lsroq.io.uncache <> io.uncache
    lsroq.io.roqDeqPtr <> io.roqDeqPtr
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    (0 until RenameWidth).map(i => {
      io.lsIdxs(i).lsroqIdx := lsroq.io.lsroqIdxs(i)
    })
  } else {
    val loadQueue = Module(new LoadQueue)
    val storeQueue = Module(new StoreQueue)
    
    // load queue wiring
    loadQueue.io.dp1Req <> io.dp1Req
    loadQueue.io.brqRedirect <> io.brqRedirect
    loadQueue.io.loadIn <> io.loadIn
    loadQueue.io.storeIn <> io.storeIn
    loadQueue.io.ldout <> io.ldout
    loadQueue.io.forward <> io.forward
    loadQueue.io.commits <> io.commits
    loadQueue.io.rollback <> io.rollback
    loadQueue.io.dcache <> io.dcache
    loadQueue.io.roqDeqPtr <> io.roqDeqPtr
    
    // store queue wiring
    // storeQueue.io <> DontCare
    storeQueue.io.dp1Req <> io.dp1Req
    storeQueue.io.brqRedirect <> io.brqRedirect
    storeQueue.io.storeIn <> io.storeIn
    storeQueue.io.sbuffer <> io.sbuffer
    storeQueue.io.stout <> io.stout
    storeQueue.io.forward <> io.forward
    storeQueue.io.commits <> io.commits
    storeQueue.io.rollback <> io.rollback
    storeQueue.io.roqDeqPtr <> io.roqDeqPtr
    
    // uncache arbiter
    val uncacheArb = Module(new Arbiter(new DCacheWordIO, 2))
    uncacheArb.io.in(0) <> loadQueue.io.uncache
    uncacheArb.io.in(1) <> storeQueue.io.uncache
    uncacheArb.io.out <> io.uncache
    
    // fix valid, allocate lq / sq index
    (0 until RenameWidth).map(i => {
      val isStore = LSUOpType.isStore(io.dp1Req(i).bits.ctrl.fuOpType)
      loadQueue.io.dp1Req(i).valid := !isStore
      storeQueue.io.dp1Req(i).valid := isStore
      io.lsIdxs(i) := DontCare
      loadQueue.io.lqIdxs(i) <> io.lsIdxs(i).lqIdx
      storeQueue.io.sqIdxs(i) <> io.lsIdxs(i).sqIdx
      io.lsIdxs(i).instIsLoad := !isStore
    })
  }
97
}