On Thu, 8 Aug 2024 06:57:28 GMT, Jatin Bhateja <jbhat...@openjdk.org> wrote:
> Hi All, > > As per the discussion on panama-dev mailing list[1], patch adds the support > for following new two vector permutation APIs. > > > Declaration:- > Vector<E>.selectFrom(Vector<E> v1, Vector<E> v2) > > > Semantics:- > Using index values stored in the lanes of "this" vector, assemble the > values stored in first (v1) and second (v2) vector arguments. Thus, first and > second vector serves as a table, whose elements are selected based on index > value vector. API is applicable to all integral and floating-point types. > The result of this operation is semantically equivalent to expression > v1.rearrange(this.toShuffle(), v2). Values held in index vector lanes must > lie within valid two vector index range [0, 2*VLEN) else an > IndexOutOfBoundException is thrown. > > Summary of changes: > - Java side implementation of new selectFrom API. > - C2 compiler IR and inline expander changes. > - In absence of direct two vector permutation instruction in target ISA, a > lowering transformation dismantles new IR into constituent IR supported by > target platforms. > - Optimized x86 backend implementation for AVX512 and legacy target. > - Function tests covering new API. > > JMH micro included with this patch shows around 10-15x gain over existing > rearrange API :- > Test System: Intel(R) Xeon(R) Platinum 8480+ [ Sapphire Rapids Server] > > > Benchmark (size) Mode Cnt Score > Error Units > SelectFromBenchmark.rearrangeFromByteVector 1024 thrpt 2 2041.762 > ops/ms > SelectFromBenchmark.rearrangeFromByteVector 2048 thrpt 2 1028.550 > ops/ms > SelectFromBenchmark.rearrangeFromIntVector 1024 thrpt 2 962.605 > ops/ms > SelectFromBenchmark.rearrangeFromIntVector 2048 thrpt 2 479.004 > ops/ms > SelectFromBenchmark.rearrangeFromLongVector 1024 thrpt 2 359.758 > ops/ms > SelectFromBenchmark.rearrangeFromLongVector 2048 thrpt 2 178.192 > ops/ms > SelectFromBenchmark.rearrangeFromShortVector 1024 thrpt 2 1463.459 > ops/ms > SelectFromBenchmark.rearrangeFromShortVector 2048 thrpt 2 727.556 > ops/ms > SelectFromBenchmark.selectFromByteVector 1024 thrpt 2 33254.830 > ops/ms > SelectFromBenchmark.selectFromByteVector 2048 thrpt 2 17313.174 > ops/ms > SelectFromBenchmark.selectFromIntVector 1024 thrpt 2 10756.804 > ops/ms > SelectFromBenchmark.selectFromIntVector 2048 thrpt 2 5398.2... test/jdk/jdk/incubator/vector/Byte128VectorTests.java line 331: > 329: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 330: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 331: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); test/jdk/jdk/incubator/vector/Double64VectorTests.java line 348: > 346: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 347: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 348: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); test/jdk/jdk/incubator/vector/DoubleMaxVectorTests.java line 353: > 351: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 352: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 353: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); test/jdk/jdk/incubator/vector/Float128VectorTests.java line 348: > 346: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 347: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 348: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); test/jdk/jdk/incubator/vector/Float256VectorTests.java line 348: > 346: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 347: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 348: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); test/jdk/jdk/incubator/vector/Float512VectorTests.java line 348: > 346: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 347: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 348: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); test/jdk/jdk/incubator/vector/FloatMaxVectorTests.java line 353: > 351: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 352: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 353: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); test/jdk/jdk/incubator/vector/Int512VectorTests.java line 331: > 329: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 330: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 331: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); test/jdk/jdk/incubator/vector/IntMaxVectorTests.java line 336: > 334: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 335: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 336: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); test/jdk/jdk/incubator/vector/Long256VectorTests.java line 288: > 286: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 287: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 288: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); test/jdk/jdk/incubator/vector/Long64VectorTests.java line 288: > 286: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 287: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 288: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); test/jdk/jdk/incubator/vector/Short256VectorTests.java line 331: > 329: boolean is_exceptional_idx = (int)order[idx] >= vector_len; > 330: int oidx = is_exceptional_idx ? ((int)order[idx] - > vector_len) : (int)order[idx]; > 331: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + > oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + > ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); Suggestion: Assert.assertEquals(r[idx], (is_exceptional_idx ? b[i + oidx] : a[i + oidx]), "at index #" + idx + ", order = " + (int)order[idx] + ", a = " + a[i + oidx] + ", b = " + b[i + oidx]); ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807165 PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807191 PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807216 PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807254 PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807143 PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807202 PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807129 PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807262 PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807098 PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807239 PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807206 PR Review Comment: https://git.openjdk.org/jdk/pull/20508#discussion_r1720807231