From d1c5b05513012d9515ebabec9308647d1d971ddf Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sat, 25 Jun 2022 19:46:46 +0100 Subject: [PATCH] add some more preduce examples, remove predicate ORing --- openpower/sv/preduce.py | 45 +++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/openpower/sv/preduce.py b/openpower/sv/preduce.py index 5fb4f26f6..b369778ee 100644 --- a/openpower/sv/preduce.py +++ b/openpower/sv/preduce.py @@ -2,7 +2,6 @@ from copy import copy def preduce(vl, vec, pred): vec = copy(vec) - pred = copy(pred) # must not damage predicate step = 1 print(" start", step, pred, vec) while step < vl: @@ -14,14 +13,12 @@ def preduce(vl, vec, pred): vec[i] += vec[other] elif other_pred: vec[i] = vec[other] - pred[i] |= other_pred print(" row", step, pred, vec) return vec def preducei(vl, vec, pred): vec = copy(vec) - pred = copy(pred) # must not damage predicate step = 1 ix = list(range(vl)) # indices move rather than copy data print(" start", step, pred, vec) @@ -36,13 +33,11 @@ def preducei(vl, vec, pred): vec[ci] += vec[oi] elif other_pred: ix[i] = oi # leave data in-place, copy index instead - pred[ci] |= other_pred print(" row", step, pred, vec, ix) return vec def preduce_yield(vl, vec, pred): - pred = copy(pred) # must not damage predicate step = 1 ix = list(range(vl)) while step < vl: @@ -56,7 +51,6 @@ def preduce_yield(vl, vec, pred): yield ci, oi elif other_pred: ix[i] = oi - pred[ci] |= other_pred def preduce_y(vl, vec, pred): @@ -91,3 +85,42 @@ if __name__ == '__main__': print () assert vec == res2 + vec = [1, 2, 3, 4, 9, 5, 6, 8] + prd = [0, 0, 0, 0, 1, 1, 1, 1] + print (vec) + res = preduce(len(vec), vec, prd) + print (res) + res2 = preducei(len(vec), vec, prd) + print (res2) + print () + preduce_y(len(vec), vec, prd) + print (vec) + print () + assert vec == res2 + + vec = [1, 2, 3, 4, 9, 5, 6, 8] + prd = [0, 1, 0, 0, 0, 1, 0, 1] + print (vec) + res = preduce(len(vec), vec, prd) + print (res) + res2 = preducei(len(vec), vec, prd) + print (res2) + print () + preduce_y(len(vec), vec, prd) + print (vec) + print () + assert vec == res2 + + vec = [1, 2, 3, 4, 9, 5, 6] + prd = [1, 0, 1, 1, 0, 0, 1] + print (vec) + res = preduce(len(vec), vec, prd) + print (res) + res2 = preducei(len(vec), vec, prd) + print (res2) + print () + preduce_y(len(vec), vec, prd) + print (vec) + print () + assert vec == res2 + -- 2.30.2