From: Luke Kenneth Casson Leighton Date: Tue, 21 Jun 2022 10:34:38 +0000 (+0100) Subject: reduce without MVs X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e554b4e06814101b6a68ca39b93b324c9fd55491;p=libreriscv.git reduce without MVs --- diff --git a/openpower/sv/preduce.py b/openpower/sv/preduce.py index 242b3ab6b..815def6b7 100644 --- a/openpower/sv/preduce.py +++ b/openpower/sv/preduce.py @@ -1,8 +1,10 @@ from copy import copy def preduce(vl, vec, pred): + vec = copy(vec) # must not damage predicate pred = copy(pred) # must not damage predicate step = 1 + print(" start", step, pred, vec) while step < vl: step *= 2 for i in range(0, vl, step): @@ -14,12 +16,35 @@ def preduce(vl, vec, pred): vec[i] = vec[other] pred[i] |= other_pred print(" row", step, pred, vec) + return vec + +def preducei(vl, vec, pred): + pred = copy(pred) # must not damage predicate + step = 1 + ix = list(range(vl)) + print(" start", step, pred, vec) + while step < vl: + step *= 2 + for i in range(0, vl, step): + other = i + step // 2 + ci = ix[i] + oi = ix[other] if other < vl else None + other_pred = other < vl and pred[oi] + if pred[ci] and other_pred: + vec[ci] += vec[oi] + elif other_pred: + ix[i] = oi + pred[ci] |= other_pred + print(" row", step, pred, vec, ix) if __name__ == '__main__': vec = [1, 2, 3, 4, 9, 5, 6] - prd = [1, 1, 1, 1, 0, 1, 1] + prd = [0, 1, 1, 1, 0, 0, 1] print (vec) - preduce(len(vec), vec, prd) + res = preduce(len(vec), vec, prd) + print (res) + preducei(len(vec), vec, prd) print (vec) print () + assert vec == res