From: Luke Kenneth Casson Leighton Date: Wed, 16 Feb 2022 16:18:05 +0000 (+0000) Subject: oof. big update to DCache to accept config parameters X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c9129d8a0f92b04702c3153b644039e764857419;p=soc.git oof. big update to DCache to accept config parameters --- diff --git a/src/soc/experiment/dcache.py b/src/soc/experiment/dcache.py index 936c60d7..1c320ad9 100644 --- a/src/soc/experiment/dcache.py +++ b/src/soc/experiment/dcache.py @@ -79,235 +79,247 @@ from nmutil.sim_tmp_alternative import Simulator from nmutil.util import wrap - -# TODO: make these parameters of DCache at some point -LINE_SIZE = 64 # Line size in bytes -NUM_LINES = 64 # Number of lines in a set -NUM_WAYS = 2 # Number of ways -TLB_SET_SIZE = 64 # L1 DTLB entries per set -TLB_NUM_WAYS = 2 # 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 -# BRAM organisation: We never access more than -# -- WB_DATA_BITS at a time so to save -# -- resources we make the array only that wide, and -# -- use consecutive indices to make a cache "line" -# -- -# -- ROW_SIZE is the width in bytes of the BRAM -# -- (based on WB, so 64-bits) -ROW_SIZE = WB_DATA_BITS // 8; - -# ROW_PER_LINE is the number of row (wishbone -# transactions) in a line -ROW_PER_LINE = LINE_SIZE // ROW_SIZE - -# BRAM_ROWS is the number of rows in BRAM needed -# 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 - -# REAL_ADDR_BITS is the number of real address -# bits that we store -REAL_ADDR_BITS = 56 - -# ROW_BITS is the number of bits to select a row -ROW_BITS = log2_int(BRAM_ROWS) - -# ROW_LINE_BITS is the number of bits to select -# a row within a line -ROW_LINE_BITS = log2_int(ROW_PER_LINE) - -# LINE_OFF_BITS is the number of bits for -# the offset in a cache line -LINE_OFF_BITS = log2_int(LINE_SIZE) - -# ROW_OFF_BITS is the number of bits for -# the offset in a row -ROW_OFF_BITS = log2_int(ROW_SIZE) - -# INDEX_BITS is the number if bits to -# select a cache line -INDEX_BITS = log2_int(NUM_LINES) - -# SET_SIZE_BITS is the log base 2 of the set size -SET_SIZE_BITS = LINE_OFF_BITS + INDEX_BITS - -# TAG_BITS is the number of bits of -# the tag part of the address -TAG_BITS = REAL_ADDR_BITS - SET_SIZE_BITS - -# TAG_WIDTH is the width in bits of each way of the tag RAM -TAG_WIDTH = TAG_BITS + 7 - ((TAG_BITS + 7) % 8) - -# WAY_BITS is the number of bits to select a way -WAY_BITS = log2_int(NUM_WAYS) - -# Example of layout for 32 lines of 64 bytes: -layout = f"""\ - DCache Layout: - |.. -----------------------| REAL_ADDR_BITS ({REAL_ADDR_BITS}) - .. |--------------| SET_SIZE_BITS ({SET_SIZE_BITS}) - .. tag |index| line | - .. | row | | - .. | |---| | ROW_LINE_BITS ({ROW_LINE_BITS}) - .. | |--- - --| LINE_OFF_BITS ({LINE_OFF_BITS}) - .. | |- --| ROW_OFF_BITS ({ROW_OFF_BITS}) - .. |----- ---| | ROW_BITS ({ROW_BITS}) - .. |-----| | INDEX_BITS ({INDEX_BITS}) - .. --------| | TAG_BITS ({TAG_BITS}) -""" -print (layout) -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)) -print ("row @: %d-%d" % (LINE_OFF_BITS, ROW_OFF_BITS)) -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) -print (" TAG_WIDTH", TAG_WIDTH) -print (" NUM_WAYS", NUM_WAYS) -print (" NUM_LINES", NUM_LINES) - - -def CacheTagArray(): - return Array(Signal(TAG_RAM_WIDTH, name="tag%d" % x) \ - for x in range(NUM_LINES)) - -def CacheValidsArray(): - return Array(Signal(NUM_WAYS, name="tag_valids%d" % x) - for x in range(NUM_LINES)) - -def RowPerLineValidArray(): - return Array(Signal(name="rows_valid%d" % x) \ - for x in range(ROW_PER_LINE)) - - -# L1 TLB -TLB_SET_BITS = log2_int(TLB_SET_SIZE) -TLB_WAY_BITS = log2_int(TLB_NUM_WAYS) -TLB_EA_TAG_BITS = 64 - (TLB_LG_PGSZ + TLB_SET_BITS) -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<