From 1e10f8a2496dd88252c72c7d77e14373727fe85e Mon Sep 17 00:00:00 2001 From: tracer-ysyx Date: Sat, 9 Mar 2024 09:29:14 +0800 Subject: [PATCH] =?UTF-8?q?>=20configure(npc)=20=20ysyx=5F22040000=20?= =?UTF-8?q?=E6=9D=8E=E5=BF=83=E6=9D=A8=20=20Linux=20calcite=206.6.19=20#1-?= =?UTF-8?q?NixOS=20SMP=20PREEMPT=5FDYNAMIC=20Fri=20Mar=20=201=2012:35:11?= =?UTF-8?q?=20UTC=202024=20x86=5F64=20GNU/Linux=20=20=2009:29:14=20=20up?= =?UTF-8?q?=20=20=200:19,=20=202=20users,=20=20load=20average:=201.32,=201?= =?UTF-8?q?.09,=200.72?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- npc/core/src/main/scala/Main.scala | 33 ++++++++++++++++---- npc/core/src/main/scala/RegisterFile.scala | 35 ++++++++++++---------- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/npc/core/src/main/scala/Main.scala b/npc/core/src/main/scala/Main.scala index 41b4ba4..9f601e7 100644 --- a/npc/core/src/main/scala/Main.scala +++ b/npc/core/src/main/scala/Main.scala @@ -3,9 +3,12 @@ package npc import chisel3._ import chisel3.util.{MuxLookup, Fill, Decoupled, Counter, Queue, Reverse} import chisel3.util.{SRAM} +import chisel3.util.experimental.decode.{decoder, TruthTable, QMCMinimizer} import chisel3.stage.ChiselOption -import npc.util.{ KeyboardSegController, RegisterFile } -import flowpc.components.{ProgramCounter, ProgramCounterSel} +import npc.util.{ KeyboardSegController } +import flowpc.components.RegisterFile +import chisel3.util.log2Ceil +import chisel3.util.BitPat class Switch extends Module { val io = IO(new Bundle { @@ -33,12 +36,32 @@ class Keyboard extends Module { io.segs := seg_handler.io.segs } -object Opcode extends ChiselEnum { +object RV32Inst extends ChiselEnum { val addi = Value("b0010011".U) + val inv = Value("b0000000".U) } -class Control extends Bundle { - +object InstType extends ChiselEnum { + val R, I, S, B, U, J = Value +} + +class RegControl(width: Int) extends Bundle { + object RegWriteDataSel extends ChiselEnum { + val ALUOut = Value + } + val T = RegWriteDataSel + val writeEnable = Output(Bool()) + val writeSelect = Output(this.T()) +} + +class Control(width: Int) extends Bundle { + val inst = IO(Input(UInt(width.W))) + val out = decoder(QMCMinimizer, inst, TruthTable( + Map( + BitPat(Opcode.addi.asUInt) -> BitPat("b00001") + ), BitPat("b?????"))) + val regControl = new RegControl(width) + } class Flowpc extends Module { diff --git a/npc/core/src/main/scala/RegisterFile.scala b/npc/core/src/main/scala/RegisterFile.scala index fbf8a94..8bb3cc0 100644 --- a/npc/core/src/main/scala/RegisterFile.scala +++ b/npc/core/src/main/scala/RegisterFile.scala @@ -1,25 +1,28 @@ -package npc.util +package flowpc.components import chisel3._ +import chisel3.util.log2Ceil +import chisel3.util.UIntToOH -class RegisterFile(readPorts: Int) extends Module { - require(readPorts >= 0) - val io = IO(new Bundle { - val writeEnable = Input(Bool()) - val writeAddr = Input(UInt(5.W)) - val writeData = Input(UInt(32.W)) - val readAddr = Input(Vec(readPorts, UInt(5.W))) - val readData = Output(Vec(readPorts, UInt(32.W))) +class RegisterFile(width: Int, numRegisters: Int, numReadPorts: Int) extends Module { + require(numReadPorts >= 0) + val writePort = IO(new Bundle { + val enable = Input(Bool()) + val addr = Input(UInt(log2Ceil(width).W)) + val data = Input(UInt(width.W)) }) + val readPorts = IO(Vec(numReadPorts, new Bundle { + val addr = Input(UInt(log2Ceil(width).W)) + val data = Output(UInt(width.W)) + })) - val regFile = RegInit(VecInit(Seq.fill(32)(0.U(32.W)))) - for (i <- 1 until 32) { - regFile(i) := regFile(i) + val regFile = RegInit(VecInit(Seq.fill(numRegisters)(0.U(32.W)))) + val writeAddrOH = UIntToOH(writePort.addr) + for ((reg, i) <- regFile.zipWithIndex) { + reg := Mux(writeAddrOH(i) && writePort.enable, writePort.data, reg) } - regFile(io.writeAddr) := Mux(io.writeEnable, io.writeData, regFile(io.writeAddr)) - regFile(0) := 0.U - for (i <- 0 until readPorts) { - io.readData(i) := regFile(io.readAddr(i)) + for (readPort <- readPorts) { + readPort.data := regFile(readPort.addr) } }