X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fsoc%2Fexperiment%2Fdcache.py;h=e1f82b77dc337467c1f9eeff306adc2ade4a7120;hb=41d2c31f6f0d184a57f468d5b157d6e8c0a44af1;hp=abf6c27659ab1b17decd5a43381ff68357233545;hpb=e9c438d11c12720ae16713145026ee2f2bcf8a4f;p=soc.git diff --git a/src/soc/experiment/dcache.py b/src/soc/experiment/dcache.py index abf6c276..e1f82b77 100644 --- a/src/soc/experiment/dcache.py +++ b/src/soc/experiment/dcache.py @@ -7,17 +7,12 @@ based on Anton Blanchard microwatt dcache.vhdl from enum import Enum, unique from nmigen import Module, Signal, Elaboratable, Cat, Repl, Array, Const -try: - from nmigen.hdl.ast import Display -except ImportError: - def Display(*args): - return [] +from nmutil.util import Display from random import randint from nmigen.cli import main from nmutil.iocontrol import RecordObject -from nmutil.util import wrap from nmigen.utils import log2_int from soc.experiment.mem_types import (LoadStore1ToDCacheType, DCacheToLoadStore1Type, @@ -31,16 +26,19 @@ from soc.experiment.wb_types import (WB_ADDR_BITS, WB_DATA_BITS, WB_SEL_BITS, WBIOMasterOut, WBIOSlaveOut) from soc.experiment.cache_ram import CacheRam -from soc.experiment.plru import PLRU +#from soc.experiment.plru import PLRU +from nmutil.plru import PLRU # for test from nmigen_soc.wishbone.sram import SRAM from nmigen import Memory from nmigen.cli import rtlil -if True: - from nmigen.back.pysim import Simulator, Delay, Settle -else: - from nmigen.sim.cxxsim import Simulator, Delay, Settle + +# NOTE: to use cxxsim, export NMIGEN_SIM_MODE=cxxsim from the shell +# Also, check out the cxxsim nmigen branch, and latest yosys from git +from nmutil.sim_tmp_alternative import Simulator + +from nmutil.util import wrap # TODO: make these parameters of DCache at some point @@ -48,7 +46,7 @@ LINE_SIZE = 64 # Line size in bytes NUM_LINES = 16 # Number of lines in a set NUM_WAYS = 4 # Number of ways TLB_SET_SIZE = 64 # L1 DTLB entries per set -TLB_NUM_WAYS = 2 # L1 DTLB number of sets +TLB_NUM_WAYS = 4 # L1 DTLB number of sets TLB_LG_PGSZ = 12 # L1 DTLB log_2(page_size) LOG_LENGTH = 0 # Non-zero to enable log data collection @@ -69,6 +67,10 @@ ROW_PER_LINE = LINE_SIZE // ROW_SIZE # to represent the full dcache BRAM_ROWS = NUM_LINES * ROW_PER_LINE +print ("ROW_SIZE", ROW_SIZE) +print ("ROW_PER_LINE", ROW_PER_LINE) +print ("BRAM_ROWS", BRAM_ROWS) +print ("NUM_WAYS", NUM_WAYS) # Bit fields counts in the address @@ -120,7 +122,7 @@ layout = """\ .. --------| | TAG_BITS (45) """ print (layout) -print ("Dcache TAG %d IDX %d ROW %d ROFF %d LOFF %d RLB %d" % \ +print ("Dcache TAG %d IDX %d ROW_BITS %d ROFF %d LOFF %d RLB %d" % \ (TAG_BITS, INDEX_BITS, ROW_BITS, ROW_OFF_BITS, LINE_OFF_BITS, ROW_LINE_BITS)) print ("index @: %d-%d" % (LINE_OFF_BITS, SET_SIZE_BITS)) @@ -129,12 +131,14 @@ print ("tag @: %d-%d width %d" % (SET_SIZE_BITS, REAL_ADDR_BITS, TAG_WIDTH)) TAG_RAM_WIDTH = TAG_WIDTH * NUM_WAYS +print ("TAG_RAM_WIDTH", TAG_RAM_WIDTH) + def CacheTagArray(): return Array(Signal(TAG_RAM_WIDTH, name="cachetag_%d" % x) \ for x in range(NUM_LINES)) def CacheValidBitsArray(): - return Array(Signal(INDEX_BITS, name="cachevalid_%d" % x) \ + return Array(Signal(NUM_WAYS, name="cachevalid_%d" % x) \ for x in range(NUM_LINES)) def RowPerLineValidArray(): @@ -149,10 +153,13 @@ TLB_TAG_WAY_BITS = TLB_NUM_WAYS * TLB_EA_TAG_BITS TLB_PTE_BITS = 64 TLB_PTE_WAY_BITS = TLB_NUM_WAYS * TLB_PTE_BITS; +def ispow2(x): + return (1<