(no commit message)
[libreriscv.git] / openpower / sv / remap.py
1 # Finite State Machine version of the REMAP system. much more likely
2 # to end up being actually used in actual hardware
3
4 # up to three dimensions permitted
5 xdim = 3
6 ydim = 2
7 zdim = 1
8
9 VL = xdim * ydim * zdim # set total (can repeat, e.g. VL=x*y*z*4)
10
11 lims = [xdim, ydim, zdim]
12 idxs = [0,0,0] # starting indices
13 applydim = [1, 1] # apply lower dims
14 order = [1,0,2] # experiment with different permutations, here
15 offset = 0 # experiment with different offsetet, here
16 invxyz = [0,1,0] # inversion allowed
17
18 # pre-prepare the index state: run for "offset" times before
19 # actually starting. this algorithm can also be used for re-entrancy
20 # if exceptions occur and a REMAP has to be started from where the
21 # interrupt left off.
22 for idx in range(offset):
23 for i in range(3):
24 idxs[order[i]] = idxs[order[i]] + 1
25 if (idxs[order[i]] != lims[order[i]]):
26 break
27 idxs[order[i]] = 0
28
29 break_count = 0 # for pretty-printing
30
31 for idx in range(VL):
32 ix = [0] * 3
33 for i in range(3):
34 ix[i] = idxs[i]
35 if invxyz[i]:
36 ix[i] = lims[i] - 1 - ix[i]
37 new_idx = ix[2]
38 if applydim[1]:
39 new_idx = new_idx * ydim + ix[1]
40 if applydim[0]:
41 new_idx = new_idx * xdim + ix[0]
42 print ("%d->%d" % (idx, new_idx)),
43 break_count += 1
44 if break_count == lims[order[0]]:
45 print ("")
46 break_count = 0
47 # this is the exact same thing as the pre-preparation stage
48 # above. step 1: count up to the limit of the current dimension
49 # step 2: if limit reached, zero it, and allow the *next* dimension
50 # to increment. repeat for 3 dimensions.
51 for i in range(3):
52 idxs[order[i]] = idxs[order[i]] + 1
53 if (idxs[order[i]] != lims[order[i]]):
54 break
55 idxs[order[i]] = 0