Vector (and integer) API: unsigned min/max
David Lloyd
david.lloyd at redhat.com
Wed Apr 17 14:13:29 UTC 2024
I've been trying the the incubating Vector API and one thing I've missed on
integer-typed vectors is having unsigned min/max operations. There is a
signed min/max operation, and unsigned comparison, but no unsigned min/max.
I guess this is for symmetry with `Math`, which only has signed
`min`/`max`. However, I would point out that while it's not very hard to
implement one's own unsigned min/max for integer types using
`compareUnsigned`, it is a bit harder to do so with vectors. The best I've
come up with is to take one of two approaches:
1. Zero-extend the vector to the next-larger size, perform the min/max, and
reduce it back down again, or
2. Add <IntType>.MIN_VALUE, min/max with a value or vector also offset by
<IntType>.MIN_VALUE, and then subtract the offset again
I guess a third approach could be to do a comparison using unsigned
compares, and then use the resultant vector mask to select items from the
original two vectors, but I didn't bother to work out this solution given I
already had the other two options.
Would it be feasible to add unsigned min/max operations for vectors? It
looks like at least AArch64 has support for this as a single instruction,
so it doesn't seem too outlandish.
And as a separate (but related) question, what about
`Math.minUnsigned`/`Math.maxUnsigned` of `int` and `long` for symmetry?
--
- DML • he/him
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20240417/32894e44/attachment-0001.htm>
More information about the core-libs-dev
mailing list