(no commit message)
[libreriscv.git] / openpower / sv / remapmatrixprint.py
1 # a "yield" version of the REMAP algorithm. a little easier to read
2 # than the Finite State Machine version
3
4 from remapyield import iterate_indices
5
6
7 def matrixscheduledemo():
8 ydim2, xdim2, ydim1 = (3, 4, 3)
9
10 print ("ydim2 xdim2 ydim1", ydim2, xdim2, ydim1)
11
12 # got this from running an earlier version
13 expected = [
14 ( 0 , (0, 0, 0) ),
15 ( 1 , (1, 0, 1) ),
16 ( 2 , (2, 0, 2) ),
17 ( 3 , (3, 0, 3) ),
18 ( 4 , (4, 3, 0) ),
19 ( 5 , (5, 3, 1) ),
20 ( 6 , (6, 3, 2) ),
21 ( 7 , (7, 3, 3) ),
22 ( 8 , (8, 6, 0) ),
23 ( 9 , (9, 6, 1) ),
24 ( 10 , (10, 6, 2) ),
25 ( 11 , (11, 6, 3) ),
26 ( 12 , (0, 1, 4) ),
27 ( 13 , (1, 1, 5) ),
28 ( 14 , (2, 1, 6) ),
29 ( 15 , (3, 1, 7) ),
30 ( 16 , (4, 4, 4) ),
31 ( 17 , (5, 4, 5) ),
32 ( 18 , (6, 4, 6) ),
33 ( 19 , (7, 4, 7) ),
34 ( 20 , (8, 7, 4) ),
35 ( 21 , (9, 7, 5) ),
36 ( 22 , (10, 7, 6) ),
37 ( 23 , (11, 7, 7) ),
38 ( 24 , (0, 2, 8) ),
39 ( 25 , (1, 2, 9) ),
40 ( 26 , (2, 2, 10) ),
41 ( 27 , (3, 2, 11) ),
42 ( 28 , (4, 5, 8) ),
43 ( 29 , (5, 5, 9) ),
44 ( 30 , (6, 5, 10) ),
45 ( 31 , (7, 5, 11) ),
46 ( 32 , (8, 8, 8) ),
47 ( 33 , (9, 8, 9) ),
48 ( 34 , (10, 8, 10) ),
49 ( 35 , (11, 8, 11) ),
50 ]
51
52 class SVSHAPE:
53 pass
54 # result uses SVSHAPE0
55 SVSHAPE0 = SVSHAPE()
56 SVSHAPE0.lims = [xdim2, ydim2, 1]
57 SVSHAPE0.order = [0,1,2] # result iterates through i and j (modulo)
58 SVSHAPE0.mode = 0b00
59 SVSHAPE0.skip = 0b00
60 SVSHAPE0.offset = 0 # no offset
61 SVSHAPE0.invxyz = [0,0,0] # no inversion
62 # X uses SVSHAPE1
63 SVSHAPE1 = SVSHAPE()
64 SVSHAPE1.lims = [xdim2, ydim2, ydim1]
65 SVSHAPE1.order = [0,2,1] # X iterates through i and k
66 SVSHAPE1.mode = 0b00
67 SVSHAPE1.skip = 0b01
68 SVSHAPE1.offset = 0 # no offset
69 SVSHAPE1.invxyz = [0,0,0] # no inversion
70 # y-selector uses SHAPE2
71 SVSHAPE2 = SVSHAPE()
72 SVSHAPE2.lims = [xdim2, ydim2, ydim1]
73 SVSHAPE2.order = [0,2,1] # X iterates through i and k
74 SVSHAPE2.mode = 0b00
75 SVSHAPE2.skip = 0b11
76 SVSHAPE2.offset = 0 # no offset
77 SVSHAPE2.invxyz = [0,0,0] # no inversion
78
79 # perform the iteration over the *linear* arrays using the
80 # schedules
81 VL = ydim2 * xdim2 * ydim1
82 i = 0
83 for i, idxs in enumerate(zip(iterate_indices(SVSHAPE0),
84 iterate_indices(SVSHAPE1),
85 iterate_indices(SVSHAPE2))):
86
87 if i == VL:
88 break
89 print ("(", i, ",", idxs, "),", "expected", expected[i])
90 if expected[i] != (i, idxs):
91 print ("row incorrect")
92
93
94 # run the demo
95 if __name__ == '__main__':
96 matrixscheduledemo()