From: Luke Kenneth Casson Leighton Date: Tue, 21 Jun 2022 10:03:45 +0000 (+0100) Subject: first version of parallel reduce demo, must remove MV X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f58b4e442ccc71e1928fb54c275f058783c1d7df;p=libreriscv.git first version of parallel reduce demo, must remove MV --- diff --git a/openpower/sv/preduce.py b/openpower/sv/preduce.py new file mode 100644 index 000000000..242b3ab6b --- /dev/null +++ b/openpower/sv/preduce.py @@ -0,0 +1,25 @@ +from copy import copy + +def preduce(vl, vec, pred): + pred = copy(pred) # must not damage predicate + step = 1 + while step < vl: + step *= 2 + for i in range(0, vl, step): + other = i + step // 2 + other_pred = other < vl and pred[other] + if pred[i] and other_pred: + vec[i] += vec[other] + elif other_pred: + vec[i] = vec[other] + pred[i] |= other_pred + print(" row", step, pred, vec) + +if __name__ == '__main__': + vec = [1, 2, 3, 4, 9, 5, 6] + prd = [1, 1, 1, 1, 0, 1, 1] + print (vec) + preduce(len(vec), vec, prd) + print (vec) + print () +