On Tue, 17 Sep 2024 07:02:15 GMT, Jatin Bhateja <jbhat...@openjdk.org> wrote:
>> src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template >> line 561: >> >>> 559: for (int i = 0; i < vlen; i++) { >>> 560: int index = ((int)vecPayload1[i]); >>> 561: res[i] = index >= vlen ? vecPayload3[index & (vlen - 1)] : >>> vecPayload2[index]; >> >> This is incorrect as the index could be negative. You need to wrap in the >> range `[0, 2 * vlen - 1]` before the comparison and selection. >> >> int index = ((int)vecPayload1[i]) & ((vlen << 1) - 1)); >> res[i] = index < vlen ? vecPayload2[index] : vecPayload3[index - vlen]; > > Hi @PaulSandoz , we already pass wrapped indexes to this helper routine > called from fallback implementation. Opps yes, the masking was throwing me off. Can you please add a comment and/or rename the parameters e.g., so `v1` is renamed to `wrappedIndex`? Also i would recommend not doing the masking, it is very misleading and instead do the subtraction. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1763582764