# the algorithm is in-place. it does not perform "MV" operations.
# instead, where a masked-out value *should* be read from is tracked
from copy import deepcopy
+import operator
# python "yield" can be iterated. use this to make it clear how
# the indices are generated by using natural-looking nested loops
"end", bin(lend)[2:], bin(rend)[2:])
-def preduce_y(vec, pred=None):
+def preduce_y(vec, pred=None, operation=None):
+ if operation is None:
+ operation = operator.add
+
res = deepcopy(vec)
xdim = len(vec)
# set up an SVSHAPE
r = shapes[1][idx]
(l_idx, lend) = l
(r_idx, rend) = r
- res[l_idx] += res[r_idx]
+ res[l_idx] = operation(res[l_idx], res[r_idx])
return res
# run the demo
for i in range(32):
self.assertEqual(sim.gpr(i), SelectableInt(expected[i], 64))
- def test_sv_remap1(self):
+ def tst_sv_remap1(self):
""">>> lst = ["svshape 7, 0, 0, 7, 0",
"svremap 31, 0, 1, 0, 0, 0, 0",
"sv.add *0, *8, *16"
]
- REMAP fmadds FRT, FRA, FRC, FRB
+ REMAP add RT,RA,RB
"""
lst = SVP64Asm(["svshape 7, 0, 0, 7, 0",
"svremap 31, 0, 1, 0, 0, 0, 0",
self.assertEqual(v, expected[i])
+ def test_sv_remap2(self):
+ """>>> lst = ["svshape 7, 0, 0, 7, 0",
+ "svremap 31, 1, 0, 0, 0, 0, 0", # different order
+ "sv.subf *0, *8, *16"
+ ]
+ REMAP sv.subf RT,RA,RB - inverted application of RA/RB
+ left/right due to subf
+ """
+ lst = SVP64Asm(["svshape 7, 0, 0, 7, 0",
+ "svremap 31, 1, 0, 0, 0, 0, 0",
+ "sv.subf *0, *0, *0"
+ ])
+ lst = list(lst)
+
+ gprs = [0] * 64
+ vec = [1, 2, 3, 4, 9, 5, 6]
+
+ # and create a linear result2, same scheme
+ #result1 = [0] * (ydim1*xdim2)
+
+
+ res = []
+ # store GPRs
+ for i, x in enumerate(vec):
+ gprs[i] = x
+
+ with Program(lst, bigendian=False) as program:
+ sim = self.run_tst_program(program, initial_regs=gprs)
+ print ("spr svshape0", sim.spr['SVSHAPE0'])
+ print (" xdimsz", sim.spr['SVSHAPE0'].xdimsz)
+ print (" ydimsz", sim.spr['SVSHAPE0'].ydimsz)
+ print (" zdimsz", sim.spr['SVSHAPE0'].zdimsz)
+ print ("spr svshape1", sim.spr['SVSHAPE1'])
+ print ("spr svshape2", sim.spr['SVSHAPE2'])
+ print ("spr svshape3", sim.spr['SVSHAPE3'])
+ for i in range(7):
+ val = sim.gpr(i).value
+ res.append(val)
+ print ("i", i, val)
+ # confirm that the results are as expected, mask with 64-bit
+ expected = preduce_y(vec, operation=operator.sub)
+ for i, v in enumerate(res):
+ self.assertEqual(v&0xffffffffffffffff,
+ expected[i]&0xffffffffffffffff)
+
def run_tst_program(self, prog, initial_regs=None,
svstate=None,
initial_mem=None,