3 # Copyright (c) 2020 Peter Hsu. All Rights Reserved. See LICENCE file for details.
9 print("usage: ./make_cache <ways associativity>")
13 filename
= 'lru_fsm_{:d}way.h'.format(N
)
14 print('Making', N
, 'way associative cache in file ', filename
)
16 def cacheHit(state
, hit
):
18 # print("cacheHit(", state, hit, ")")
31 nextState
= cacheHit(state
, i
)
32 nextKey
= makeKey(nextState
)
33 if nextKey
not in table
:
34 table
[nextKey
] = [ None ]*N
36 table
[key
][i
] = nextKey
39 for i
in range(N
-1, -1, -1):
40 initial
.append(str(i
))
42 table
[makeKey(initial
)] = [ None ]*N
47 for key
in sorted(table
):
53 f
= open(filename
, 'w');
54 f
.write('struct lru_fsm_t cache_fsm_{:d}way[] = {{\n'.format(N
))
55 f
.write('/* Header */\t{{ {:d}, {:3d} }}, /* Ways, Number of states */\n'.format(int(sys
.argv
[1]), len(table
)))
58 for key
in sorted(table
):
60 for (i
, ww
) in enumerate(ways
):
62 ns
= number
[table
[key
][i
]]
64 f
.write('/* {:2d} */'.format(k
))
67 f
.write('\t{{ {:d}, {:3d}*{:d} }}, /* {:s} */\n'.format(w
, ns
, N
, table
[key
][i
]))