ICache改为双取指

This commit is contained in:
Liphen 2023-11-20 13:58:08 +08:00
parent 7ecb175c6d
commit b657c0c7f0
5 changed files with 25 additions and 23 deletions

View File

@ -12,10 +12,10 @@ case class CpuConfig(
val hasUMode: Boolean = false, // 是否有U模式 val hasUMode: Boolean = false, // 是否有U模式
// 模块配置 // 模块配置
val hasCommitBuffer: Boolean = false, // 是否有提交缓存 val hasCommitBuffer: Boolean = false, // 是否有提交缓存
val decoderNum: Int = 1, // 同时访问寄存器的指令数 val decoderNum: Int = 2, // 同时访问寄存器的指令数
val commitNum: Int = 1, // 同时提交的指令数 val commitNum: Int = 2, // 同时提交的指令数
val fuNum: Int = 1, // 功能单元数 val fuNum: Int = 2, // 功能单元数
val instFetchNum: Int = 1, // iCache取到的指令数量 val instFetchNum: Int = 2, // iCache取到的指令数量
val instFifoDepth: Int = 8, // 指令缓存深度 val instFifoDepth: Int = 8, // 指令缓存深度
val mulClockNum: Int = 2, // 乘法器的时钟周期数 val mulClockNum: Int = 2, // 乘法器的时钟周期数
val divClockNum: Int = 8, // 除法器的时钟周期数 val divClockNum: Int = 8, // 除法器的时钟周期数

View File

@ -17,8 +17,8 @@ class ICache(implicit config: CpuConfig) extends Module {
val s_idle :: s_read :: s_finishwait :: Nil = Enum(3) val s_idle :: s_read :: s_finishwait :: Nil = Enum(3)
val status = RegInit(s_idle) val status = RegInit(s_idle)
io.cpu.valid := status === s_finishwait io.cpu.valid.map(_ := status === s_finishwait)
val addr_err = io.cpu.addr.orR val addr_err = io.cpu.addr(0).orR
// default // default
io.axi.ar.id := 0.U io.axi.ar.id := 0.U
@ -32,7 +32,7 @@ class ICache(implicit config: CpuConfig) extends Module {
io.axi.ar.prot := 0.U io.axi.ar.prot := 0.U
io.axi.ar.cache := 0.U io.axi.ar.cache := 0.U
io.axi.r.ready := true.B io.axi.r.ready := true.B
io.cpu.rdata := 0.U io.cpu.rdata.map(_ := 0.U)
io.cpu.acc_err := false.B io.cpu.acc_err := false.B
io.cpu.stall := false.B io.cpu.stall := false.B
@ -43,7 +43,7 @@ class ICache(implicit config: CpuConfig) extends Module {
io.cpu.acc_err := true.B io.cpu.acc_err := true.B
status := s_finishwait status := s_finishwait
}.otherwise { }.otherwise {
io.axi.ar.addr := Cat(io.cpu.addr(31, 2), 0.U(2.W)) io.axi.ar.addr := Cat(io.cpu.addr(0)(31, 2), 0.U(2.W))
arvalid := true.B arvalid := true.B
status := s_read status := s_read
} }
@ -54,7 +54,8 @@ class ICache(implicit config: CpuConfig) extends Module {
arvalid := false.B arvalid := false.B
} }
when(io.axi.r.valid) { when(io.axi.r.valid) {
io.cpu.rdata := Mux(io.axi.ar.addr(2), io.axi.r.data(63, 32), io.axi.r.data(31, 0)) io.cpu.rdata(0) := Mux(io.axi.ar.addr(2), io.axi.r.data(63, 32), io.axi.r.data(31, 0))
io.cpu.rdata(1) := Mux(io.axi.ar.addr(2), 0.U, io.axi.r.data(63, 32))
io.cpu.acc_err := io.axi.r.resp =/= RESP_OKEY.U io.cpu.acc_err := io.axi.r.resp =/= RESP_OKEY.U
status := s_finishwait status := s_finishwait
} }
@ -67,7 +68,7 @@ class ICache(implicit config: CpuConfig) extends Module {
io.cpu.acc_err := true.B io.cpu.acc_err := true.B
status := s_finishwait status := s_finishwait
}.otherwise { }.otherwise {
io.axi.ar.addr := Cat(io.cpu.addr(31, 2), 0.U(2.W)) io.axi.ar.addr := Cat(io.cpu.addr(0)(31, 2), 0.U(2.W))
arvalid := true.B arvalid := true.B
status := s_read status := s_read
} }

View File

@ -107,12 +107,12 @@ class Cache_ICache(implicit val config: CpuConfig) extends Bundle {
// read inst request from cpu // read inst request from cpu
val en = Output(Bool()) val en = Output(Bool())
val ready = Output(Bool()) val ready = Output(Bool())
val addr = Output(UInt(INST_ADDR_WID.W)) // virtual address and next virtual address val addr = Output(Vec(config.instFetchNum,UInt(INST_ADDR_WID.W))) // virtual address and next virtual address
val fence_i = Output(Bool()) val fence_i = Output(Bool())
// read inst result // read inst result
val rdata = Input(UInt(INST_WID.W)) val rdata = Input(Vec(config.instFetchNum,UInt(INST_WID.W)))
val valid = Input(Bool()) val valid = Input(Vec(config.instFetchNum,Bool()))
val acc_err = Input(Bool()) val acc_err = Input(Bool())
val stall = Input(Bool()) val stall = Input(Bool())
} }

View File

@ -58,7 +58,7 @@ object Util {
object LookupTreeDefault { object LookupTreeDefault {
def apply[T <: Data](key: UInt, default: T, mapping: Iterable[(UInt, T)]): T = def apply[T <: Data](key: UInt, default: T, mapping: Iterable[(UInt, T)]): T =
MuxLookup(key, default, mapping.toSeq) MuxLookup(key, default)(mapping.toSeq)
} }
} }

View File

@ -3,10 +3,11 @@ import circt.stage._
import cache.Cache import cache.Cache
import cpu.pipeline.decoder.Decoder import cpu.pipeline.decoder.Decoder
import cpu.pipeline.decoder.DecoderUnit import cpu.pipeline.decoder.DecoderUnit
import cache.ICache
object TestMain extends App { object TestMain extends App {
implicit val config = new CpuConfig() implicit val config = new CpuConfig()
def top = new DecoderUnit() def top = new Cache()
val useMFC = false // use MLIR-based firrtl compiler val useMFC = false // use MLIR-based firrtl compiler
val generator = Seq(chisel3.stage.ChiselGeneratorAnnotation(() => top)) val generator = Seq(chisel3.stage.ChiselGeneratorAnnotation(() => top))
if (useMFC) { if (useMFC) {