bug 1155: experimenting with bigmul / triangle / modulo
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 26 Dec 2023 19:58:54 +0000 (19:58 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 26 Dec 2023 19:58:54 +0000 (19:58 +0000)
https://bugs.libre-soc.org/show_bug.cgi?id=1155#c30

src/openpower/decoder/isa/remapyield.py

index 389cfb6b394063e9afa9abfacd1b1331286c5430..856b2b8998c9b2cfa5d0aa61e93063a0e593989d 100644 (file)
@@ -3,9 +3,12 @@
 
 # python "yield" can be iterated. use this to make it clear how
 # the indices are generated by using natural-looking nested loops
-def iterate_indices(SVSHAPE):
+def iterate_indices(SVSHAPE, VL=None):
     # establish if this is triangular mode
-    triangle = SVSHAPE.mode == 0b11 and SVSHAPE.submode == 0b00
+    triangle = SVSHAPE.mode == 0b11 and SVSHAPE.submode & 0b10 == 0b10
+    bigmul = SVSHAPE.mode == 0b11 and SVSHAPE.submode & 0b01 == 0b01
+    in_offs = VL is not None and SVSHAPE.mode == 0b11
+
     # get indices to iterate over, in the required order
     xd = SVSHAPE.lims[0]
     yd = SVSHAPE.lims[1]
@@ -50,18 +53,31 @@ def iterate_indices(SVSHAPE):
                     # "order" to say which ones get stacked on
                     result = 0
                     mult = 1
+                    if in_offs:
+                        if SVSHAPE.submode2 & 0b001 == 0b001: # cols
+                            ix, ddbg = yi, "x"
+                        else:
+                            ix, ddbg = xi, "y"
+
                     for i in range(3):
                         lim, idx, dbg = vals[i]
                         # some of the dimensions can be "skipped".  the order
                         # was actually selected above on all 3 dimensions,
                         # e.g. [z][x][y] or [y][z][x].  "skip" allows one of
                         # those to be knocked out
-                        #print ("select %d %s" % (i, dbg))
-                        if SVSHAPE.mode == 0b00: # Matrix Mode
+                        #print ("select %d %s idx %d" % (i, dbg, idx), VL,
+                        #                                xi, yi, zi)
+                        # modulo+offset?
+                        if in_offs and dbg == ddbg:
+                            ni = (idx + ix*SVSHAPE.offset) % lim
+                            #print ("mod", idx, ni, yi, SVSHAPE.offset, lim)
+                            idx = ni
+
+                        if not bigmul: # Matrix Mode
                             if SVSHAPE.skip == i+1: continue
                             idx *= mult   # shifts up by previous dimension(s)
                         result += idx # adds on this dimension
-                        if SVSHAPE.mode == 0b00: # Matrix Mode
+                        if not bigmul: # Matrix Mode
                             mult *= lim   # for the next dimension
 
                     loopends = (x_end |
@@ -70,22 +86,25 @@ def iterate_indices(SVSHAPE):
 
                     if hasattr(SVSHAPE, "postprocess"): # for Indexed mode
                         result = SVSHAPE.postprocess(result, step)
-                    yield result + SVSHAPE.offset, loopends
+                    if not in_offs:
+                        result += SVSHAPE.offset
+                    yield result, loopends
                     step += 1
 
-def dump_shape(SVSHAPE0):
+
+def dump_shape(SVSHAPE, VL=None):
     # enumerate over the iterator function, getting new indices
-    for idx, (new_idx, end) in enumerate(iterate_indices(SVSHAPE0)):
+    for idx, (new_idx, end) in enumerate(iterate_indices(SVSHAPE, VL=VL)):
         estring = bin(end)[2:] if end else ''
         print ("%2d->%-2d" % (idx, new_idx), "%2s" % estring, end=' ')
         if end == 0b111:
             print()
             break
-        triangle = SVSHAPE0.mode == 0b11 and SVSHAPE0.submode == 0b00
+        triangle = SVSHAPE.mode == 0b11 and SVSHAPE.submode & 0b10 == 0b10
         if triangle:
-            if SVSHAPE0.lims[0] == 1: end &= ~0b001
+            if SVSHAPE.lims[0] == 1: end &= ~0b001
         if triangle:
-            if SVSHAPE0.lims[1] == 1: end &= ~0b010
+            if SVSHAPE.lims[1] == 1: end &= ~0b010
         if end != 0:
             print()
 
@@ -103,6 +122,7 @@ def demo():
     SVSHAPE0.order = [1,0,2]  # experiment with different permutations, here
     SVSHAPE0.mode = 0b00
     SVSHAPE0.skip = 0b00
+    SVSHAPE0.submode2 = 0b000    #
     SVSHAPE0.offset = 0       # experiment with different offset, here
     SVSHAPE0.invxyz = [0,0,0] # inversion if desired
 
@@ -116,6 +136,8 @@ def demo():
     SVSHAPE0.order = [0,1,2]  # experiment with different permutations, here
     SVSHAPE0.mode = 0b11
     SVSHAPE0.submode = 0b01      # rhombus mode
+    SVSHAPE0.submode2 = 0b000    #
+    SVSHAPE0.skip = 0b00
     SVSHAPE0.offset = 0       # experiment with different offset, here
     SVSHAPE0.invxyz = [0,0,0] # inversion if desired
 
@@ -123,17 +145,50 @@ def demo():
 
     # triangle
     print("\ntriangle", xdim, ydim, zdim)
-    xdim, ydim, zdim = 1, 5, 5 # set the dimension sizes here
+    xdim, ydim, zdim = 1, 3, 5 # set the dimension sizes here
     SVSHAPE0 = SVSHAPE()
     SVSHAPE0.lims = [xdim, ydim, zdim]
     SVSHAPE0.order = [0,1,2]  # experiment with different permutations, here
     SVSHAPE0.mode = 0b11
-    SVSHAPE0.submode = 0b00      # triangle mode
+    SVSHAPE0.submode = 0b10      # triangle mode
+    SVSHAPE0.submode2 = 0b000    #
+    SVSHAPE0.skip = 0b00
+    SVSHAPE0.offset = 0       # experiment with different offset, here
+    SVSHAPE0.invxyz = [0,0,0] # inversion if desired
+
+    # triangle
+    print("\ntriangle-bigmul", xdim, ydim, zdim)
+    xdim, ydim, zdim = 1, 3, 5 # set the dimension sizes here
+    SVSHAPE0 = SVSHAPE()
+    SVSHAPE0.lims = [xdim, ydim, zdim]
+    SVSHAPE0.order = [0,1,2]  # experiment with different permutations, here
+    SVSHAPE0.mode = 0b11
+    SVSHAPE0.submode = 0b11      # triangle mode, with sum
+    SVSHAPE0.submode2 = 0b000    #
+    SVSHAPE0.skip = 0b00
     SVSHAPE0.offset = 0       # experiment with different offset, here
     SVSHAPE0.invxyz = [0,0,0] # inversion if desired
 
     dump_shape(SVSHAPE0)
 
+    VL = 12 # modulo
+
+    # matrix modulo
+    xdim, ydim, zdim = 4, 4, 1 # set the dimension sizes here
+    print("\nmatrix modulo(%d)" % VL, xdim, ydim, zdim)
+    SVSHAPE0 = SVSHAPE()
+    SVSHAPE0.lims = [xdim, ydim, zdim]
+    SVSHAPE0.order = [0,1,2]  # experiment with different permutations, here
+    SVSHAPE0.mode = 0b11
+    SVSHAPE0.submode = 0b00      #
+    SVSHAPE0.skip = 0b00
+    SVSHAPE0.submode2 = 0b000    # cols or rows modulo
+    SVSHAPE0.offset = 1 # experiment with different offset, here
+    SVSHAPE0.invxyz = [0,0,0] # inversion if desired
+
+    dump_shape(SVSHAPE0, VL=VL)
+
+
 # run the demo
 if __name__ == '__main__':
     demo()