VectorMask.firstTrue()/lastTrue()
Remi Forax
forax at univ-mlv.fr
Wed Apr 14 12:35:50 UTC 2021
There is a way to implement firstTrue and lastTrue using only vector operations.
The idea is to use to mask iota with the mask and then do a reduceLanes with MIN or MAX.
By example to for firstTrue() that returns -1 if the mask is empty,
first create iotaPlusOne, blend with zero, then reduceLanes with MIN, then substract 1
VectorMask mask = ...
var iotaPlusOne = ByteVector.broadcast(SPECIES, 1).addIndex(1);
ByteVector.zero(SPECIES).blend(iotaPlusOne, mask).reduceLanes(VectorOperators.MIN) - 1;
BTW, i wonder why firstTrue return the mask length instead of -1.
regards,
Rémi
More information about the panama-dev
mailing list