of SVSTATE, making things slightly tricky.
Executable demo pseudocode, full version
-[here](https://git.libre-soc.org/?p=libreriscv.git;a=blob;f=openpower/sv/preduce.py;hb=HEAD)
+[here](https://git.libre-soc.org/?p=libreriscv.git;a=blob;f=openpower/sv/test_preduce.py;hb=HEAD)
```
-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)
- 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 # leave data in-place, copy index instead
- pred[ci] |= other_pred
- print(" row", step, pred, vec, ix)
- return vec
+[[!inline raw="yes" pages="openpower/sv/preduce.py" ]]
```
This algorithm works by noting when data remains in-place rather than