from nmigen import Cat, Const, Array, Signal, Elaboratable, Module
from nmutil.iocontrol import RecordObject
from nmutil.util import treereduce
+from nmigen import Memory
from math import log
import operator
class RegFileArray(Elaboratable):
+ unary = True
""" an array-based register file (register having write-through capability)
that has no "address" decoder, instead it has individual write-en
and read-en signals (per port).
return list(self)
+class RegFileMem(Elaboratable):
+ unary = False
+ def __init__(self, width, depth):
+ self.memory = Memory(width=width, depth=depth)
+ self._rdports = {}
+ self._wrports = {}
+
+ def read_port(self, name=None):
+ port = self._rdports[name] = self.memory.read_port()
+ return port
+
+ def write_port(self, name=None):
+ port = self._wrports[name] = self.memory.write_port()
+ return port
+
+ def elaborate(self, platform):
+ m = Module()
+ for name, rp in self._rdports.items():
+ setattr(m.submodules, "rp_"+name, rp)
+ for name, wp in self._wrports.items():
+ setattr(m.submodules, "wp_"+name, wp)
+ return m
+
+
class RegFile(Elaboratable):
+ unary = False
def __init__(self, width, depth):
self.width = width
self.depth = depth
# TODO
-from soc.regfile.regfile import RegFile, RegFileArray
+from soc.regfile.regfile import RegFile, RegFileArray, RegFileMem
from soc.regfile.virtual_port import VirtualRegPort
from soc.decoder.power_enums import SPR
-from nmigen import Memory, Elaboratable
# "State" Regfile
# SPR Regfile
-class SPRRegs(Memory, Elaboratable):
+class SPRRegs(RegFileMem):
"""SPRRegs
* QTY len(SPRs) 64-bit registers
def __init__(self):
n_sprs = len(SPR)
super().__init__(width=64, depth=n_sprs)
- self.w_ports = {'spr1': self.write_port()}
- self.r_ports = {'spr1': self.read_port()}
+ self.w_ports = {'spr1': self.write_port("spr1")}
+ self.r_ports = {'spr1': self.read_port("spr1")}
# make read/write ports look like RegFileArray
self.w_ports['spr1'].wen = self.w_ports['spr1'].en