From: Luke Kenneth Casson Leighton Date: Sat, 25 Jun 2022 18:46:46 +0000 (+0100) Subject: add some more preduce examples, remove predicate ORing X-Git-Tag: opf_rfc_ls005_v1~1524 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d1c5b05513012d9515ebabec9308647d1d971ddf;p=libreriscv.git add some more preduce examples, remove predicate ORing --- 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 +