/* * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have * questions. */ /* * @test * @modules jdk.incubator.vector * @run testng/othervm -ea -esa LongMaxVectorTests */ import jdk.incubator.vector.VectorShape; import jdk.incubator.vector.VectorSpecies; import jdk.incubator.vector.VectorShuffle; import jdk.incubator.vector.VectorMask; import jdk.incubator.vector.Vector; import jdk.incubator.vector.LongVector; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.lang.Integer; import java.util.List; import java.util.Arrays; import java.util.function.BiFunction; import java.util.function.IntFunction; import java.util.stream.Collectors; import java.util.stream.Stream; @Test public class LongMaxVectorTests extends AbstractVectorTest { static final VectorSpecies SPECIES = LongVector.SPECIES_MAX; static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100); static VectorShape getMaxBit() { return VectorShape.S_Max_BIT; } interface FUnOp { long apply(long a); } static void assertArraysEquals(long[] a, long[] r, FUnOp f) { int i = 0; try { for (; i < a.length; i++) { Assert.assertEquals(r[i], f.apply(a[i])); } } catch (AssertionError e) { Assert.assertEquals(r[i], f.apply(a[i]), "at index #" + i + ", input = " + a[i]); } } static void assertArraysEquals(long[] a, long[] r, boolean[] mask, FUnOp f) { int i = 0; try { for (; i < a.length; i++) { Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i]); } } catch (AssertionError e) { Assert.assertEquals(r[i], mask[i % SPECIES.length()] ? f.apply(a[i]) : a[i], "at index #" + i + ", input = " + a[i] + ", mask = " + mask[i % SPECIES.length()]); } } interface FReductionOp { long apply(long[] a, int idx); } interface FReductionAllOp { long apply(long[] a); } static void assertReductionArraysEquals(long[] a, long[] b, long c, FReductionOp f, FReductionAllOp fa) { int i = 0; try { Assert.assertEquals(c, fa.apply(a)); for (; i < a.length; i += SPECIES.length()) { Assert.assertEquals(b[i], f.apply(a, i)); } } catch (AssertionError e) { Assert.assertEquals(c, fa.apply(a), "Final result is incorrect!"); Assert.assertEquals(b[i], f.apply(a, i), "at index #" + i); } } interface FBoolReductionOp { boolean apply(boolean[] a, int idx); } static void assertReductionBoolArraysEquals(boolean[] a, boolean[] b, FBoolReductionOp f) { int i = 0; try { for (; i < a.length; i += SPECIES.length()) { Assert.assertEquals(f.apply(a, i), b[i]); } } catch (AssertionError e) { Assert.assertEquals(f.apply(a, i), b[i], "at index #" + i); } } static void assertInsertArraysEquals(long[] a, long[] b, long element, int index) { int i = 0; try { for (; i < a.length; i += 1) { if(i%SPECIES.length() == index) { Assert.assertEquals(b[i], element); } else { Assert.assertEquals(b[i], a[i]); } } } catch (AssertionError e) { if (i%SPECIES.length() == index) { Assert.assertEquals(b[i], element, "at index #" + i); } else { Assert.assertEquals(b[i], a[i], "at index #" + i); } } } static void assertRearrangeArraysEquals(long[] a, long[] r, int[] order, int vector_len) { int i = 0, j = 0; try { for (; i < a.length; i += vector_len) { for (j = 0; j < vector_len; j++) { Assert.assertEquals(r[i+j], a[i+order[i+j]]); } } } catch (AssertionError e) { int idx = i + j; Assert.assertEquals(r[i+j], a[i+order[i+j]], "at index #" + idx + ", input = " + a[i+order[i+j]]); } } interface FBinOp { long apply(long a, long b); } interface FBinMaskOp { long apply(long a, long b, boolean m); static FBinMaskOp lift(FBinOp f) { return (a, b, m) -> m ? f.apply(a, b) : a; } } static void assertArraysEquals(long[] a, long[] b, long[] r, FBinOp f) { int i = 0; try { for (; i < a.length; i++) { Assert.assertEquals(r[i], f.apply(a[i], b[i])); } } catch (AssertionError e) { Assert.assertEquals(f.apply(a[i], b[i]), r[i], "(" + a[i] + ", " + b[i] + ") at index #" + i); } } static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { assertArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); } static void assertArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { int i = 0; try { for (; i < a.length; i++) { Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()])); } } catch (AssertionError err) { Assert.assertEquals(r[i], f.apply(a[i], b[i], mask[i % SPECIES.length()]), "at index #" + i + ", input1 = " + a[i] + ", input2 = " + b[i] + ", mask = " + mask[i % SPECIES.length()]); } } static void assertShiftArraysEquals(long[] a, long[] b, long[] r, FBinOp f) { int i = 0; int j = 0; try { for (; j < a.length; j += SPECIES.length()) { for (i = 0; i < SPECIES.length(); i++) { Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j]); } } } catch (AssertionError e) { Assert.assertEquals(f.apply(a[i+j], b[j]), r[i+j], "at index #" + i + ", " + j); } } static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinOp f) { assertShiftArraysEquals(a, b, r, mask, FBinMaskOp.lift(f)); } static void assertShiftArraysEquals(long[] a, long[] b, long[] r, boolean[] mask, FBinMaskOp f) { int i = 0; int j = 0; try { for (; j < a.length; j += SPECIES.length()) { for (i = 0; i < SPECIES.length(); i++) { Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i])); } } } catch (AssertionError err) { Assert.assertEquals(r[i+j], f.apply(a[i+j], b[j], mask[i]), "at index #" + i + ", input1 = " + a[i+j] + ", input2 = " + b[j] + ", mask = " + mask[i]); } } interface FBinArrayOp { long apply(long[] a, int b); } static void assertArraysEquals(long[] a, long[] r, FBinArrayOp f) { int i = 0; try { for (; i < a.length; i++) { Assert.assertEquals(f.apply(a, i), r[i]); } } catch (AssertionError e) { Assert.assertEquals(f.apply(a,i), r[i], "at index #" + i); } } interface FGatherScatterOp { long[] apply(long[] a, int ix, int[] b, int iy); } static void assertArraysEquals(long[] a, int[] b, long[] r, FGatherScatterOp f) { int i = 0; try { for (; i < a.length; i += SPECIES.length()) { Assert.assertEquals(Arrays.copyOfRange(r, i, i+SPECIES.length()), f.apply(a, i, b, i)); } } catch (AssertionError e) { long[] ref = f.apply(a, i, b, i); long[] res = Arrays.copyOfRange(r, i, i+SPECIES.length()); Assert.assertEquals(ref, res, "(ref: " + Arrays.toString(ref) + ", res: " + Arrays.toString(res) + ", a: " + Arrays.toString(Arrays.copyOfRange(a, i, i+SPECIES.length())) + ", b: " + Arrays.toString(Arrays.copyOfRange(b, i, i+SPECIES.length())) + " at index #" + i); } } static final List> LONG_GENERATORS = List.of( withToString("long[-i * 5]", (int s) -> { return fill(s * 1000, i -> (long)(-i * 5)); }), withToString("long[i * 5]", (int s) -> { return fill(s * 1000, i -> (long)(i * 5)); }), withToString("long[i + 1]", (int s) -> { return fill(s * 1000, i -> (((long)(i + 1) == 0) ? 1 : (long)(i + 1))); }), withToString("long[cornerCaseValue(i)]", (int s) -> { return fill(s * 1000, i -> cornerCaseValue(i)); }) ); // Create combinations of pairs // @@@ Might be sensitive to order e.g. div by 0 static final List>> LONG_GENERATOR_PAIRS = Stream.of(LONG_GENERATORS.get(0)). flatMap(fa -> LONG_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))). collect(Collectors.toList()); @DataProvider public Object[][] boolUnaryOpProvider() { return BOOL_ARRAY_GENERATORS.stream(). map(f -> new Object[]{f}). toArray(Object[][]::new); } @DataProvider public Object[][] longBinaryOpProvider() { return LONG_GENERATOR_PAIRS.stream().map(List::toArray). toArray(Object[][]::new); } @DataProvider public Object[][] longIndexedOpProvider() { return LONG_GENERATOR_PAIRS.stream().map(List::toArray). toArray(Object[][]::new); } @DataProvider public Object[][] longBinaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). flatMap(fm -> LONG_GENERATOR_PAIRS.stream().map(lfa -> { return Stream.concat(lfa.stream(), Stream.of(fm)).toArray(); })). toArray(Object[][]::new); } @DataProvider public Object[][] longUnaryOpProvider() { return LONG_GENERATORS.stream(). map(f -> new Object[]{f}). toArray(Object[][]::new); } @DataProvider public Object[][] longUnaryOpMaskProvider() { return BOOLEAN_MASK_GENERATORS.stream(). flatMap(fm -> LONG_GENERATORS.stream().map(fa -> { return new Object[] {fa, fm}; })). toArray(Object[][]::new); } @DataProvider public Object[][] longUnaryOpShuffleProvider() { return INT_SHUFFLE_GENERATORS.stream(). flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { return new Object[] {fa, fs}; })). toArray(Object[][]::new); } @DataProvider public Object[][] longUnaryOpIndexProvider() { return INT_INDEX_GENERATORS.stream(). flatMap(fs -> LONG_GENERATORS.stream().map(fa -> { return new Object[] {fa, fs}; })). toArray(Object[][]::new); } static final List> LONG_COMPARE_GENERATORS = List.of( withToString("long[i]", (int s) -> { return fill(s * 1000, i -> (long)i); }), withToString("long[i + 1]", (int s) -> { return fill(s * 1000, i -> (long)(i + 1)); }), withToString("long[i - 2]", (int s) -> { return fill(s * 1000, i -> (long)(i - 2)); }), withToString("long[zigZag(i)]", (int s) -> { return fill(s * 1000, i -> i%3 == 0 ? (long)i : (i%3 == 1 ? (long)(i + 1) : (long)(i - 2))); }), withToString("long[cornerCaseValue(i)]", (int s) -> { return fill(s * 1000, i -> cornerCaseValue(i)); }) ); static final List>> LONG_COMPARE_GENERATOR_PAIRS = LONG_COMPARE_GENERATORS.stream(). flatMap(fa -> LONG_COMPARE_GENERATORS.stream().map(fb -> List.of(fa, fb))). collect(Collectors.toList()); @DataProvider public Object[][] longCompareOpProvider() { return LONG_COMPARE_GENERATOR_PAIRS.stream().map(List::toArray). toArray(Object[][]::new); } interface ToLongF { long apply(int i); } static long[] fill(int s , ToLongF f) { return fill(new long[s], f); } static long[] fill(long[] a, ToLongF f) { for (int i = 0; i < a.length; i++) { a[i] = f.apply(i); } return a; } static long cornerCaseValue(int i) { switch(i % 5) { case 0: return Long.MAX_VALUE; case 1: return Long.MIN_VALUE; case 2: return Long.MIN_VALUE; case 3: return Long.MAX_VALUE; default: return (long)0; } } static long get(long[] a, int i) { return (long) a[i]; } static final IntFunction fr = (vl) -> { int length = 1000 * vl; return new long[length]; }; static final IntFunction fmr = (vl) -> { int length = 1000 * vl; return new boolean[length]; }; static long add(long a, long b) { return (long)(a + b); } @Test(dataProvider = "longBinaryOpProvider") static void addLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.add(bv).intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::add); } @Test(dataProvider = "longBinaryOpMaskProvider") static void addLongMaxVectorTests(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.add(bv, vmask).intoArray(r, i); } } assertArraysEquals(a, b, r, mask, LongMaxVectorTests::add); } static long sub(long a, long b) { return (long)(a - b); } @Test(dataProvider = "longBinaryOpProvider") static void subLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.sub(bv).intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::sub); } @Test(dataProvider = "longBinaryOpMaskProvider") static void subLongMaxVectorTests(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.sub(bv, vmask).intoArray(r, i); } } assertArraysEquals(a, b, r, mask, LongMaxVectorTests::sub); } static long mul(long a, long b) { return (long)(a * b); } @Test(dataProvider = "longBinaryOpProvider") static void mulLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.mul(bv).intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::mul); } @Test(dataProvider = "longBinaryOpMaskProvider") static void mulLongMaxVectorTests(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.mul(bv, vmask).intoArray(r, i); } } assertArraysEquals(a, b, r, mask, LongMaxVectorTests::mul); } static long and(long a, long b) { return (long)(a & b); } @Test(dataProvider = "longBinaryOpProvider") static void andLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.and(bv).intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::and); } @Test(dataProvider = "longBinaryOpMaskProvider") static void andLongMaxVectorTests(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.and(bv, vmask).intoArray(r, i); } } assertArraysEquals(a, b, r, mask, LongMaxVectorTests::and); } static long or(long a, long b) { return (long)(a | b); } @Test(dataProvider = "longBinaryOpProvider") static void orLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.or(bv).intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::or); } @Test(dataProvider = "longBinaryOpMaskProvider") static void orLongMaxVectorTests(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.or(bv, vmask).intoArray(r, i); } } assertArraysEquals(a, b, r, mask, LongMaxVectorTests::or); } static long xor(long a, long b) { return (long)(a ^ b); } @Test(dataProvider = "longBinaryOpProvider") static void xorLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.xor(bv).intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::xor); } @Test(dataProvider = "longBinaryOpMaskProvider") static void xorLongMaxVectorTests(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.xor(bv, vmask).intoArray(r, i); } } assertArraysEquals(a, b, r, mask, LongMaxVectorTests::xor); } static long shiftLeft(long a, long b) { return (long)((a << b)); } @Test(dataProvider = "longBinaryOpProvider") static void shiftLeftLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.shiftLeft(bv).intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::shiftLeft); } @Test(dataProvider = "longBinaryOpMaskProvider") static void shiftLeftLongMaxVectorTests(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.shiftLeft(bv, vmask).intoArray(r, i); } } assertArraysEquals(a, b, r, mask, LongMaxVectorTests::shiftLeft); } static long shiftRight(long a, long b) { return (long)((a >>> b)); } @Test(dataProvider = "longBinaryOpProvider") static void shiftRightLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.shiftRight(bv).intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::shiftRight); } @Test(dataProvider = "longBinaryOpMaskProvider") static void shiftRightLongMaxVectorTests(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.shiftRight(bv, vmask).intoArray(r, i); } } assertArraysEquals(a, b, r, mask, LongMaxVectorTests::shiftRight); } static long shiftArithmeticRight(long a, long b) { return (long)((a >> b)); } @Test(dataProvider = "longBinaryOpProvider") static void shiftArithmeticRightLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.shiftArithmeticRight(bv).intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::shiftArithmeticRight); } @Test(dataProvider = "longBinaryOpMaskProvider") static void shiftArithmeticRightLongMaxVectorTests(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.shiftArithmeticRight(bv, vmask).intoArray(r, i); } } assertArraysEquals(a, b, r, mask, LongMaxVectorTests::shiftArithmeticRight); } static long shiftLeft_unary(long a, long b) { return (long)((a << b)); } @Test(dataProvider = "longBinaryOpProvider") static void shiftLeftLongMaxVectorTestsShift(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.shiftLeft((int)b[i]).intoArray(r, i); } } assertShiftArraysEquals(a, b, r, LongMaxVectorTests::shiftLeft_unary); } @Test(dataProvider = "longBinaryOpMaskProvider") static void shiftLeftLongMaxVectorTestsShift(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.shiftLeft((int)b[i], vmask).intoArray(r, i); } } assertShiftArraysEquals(a, b, r, mask, LongMaxVectorTests::shiftLeft_unary); } static long shiftRight_unary(long a, long b) { return (long)((a >>> b)); } @Test(dataProvider = "longBinaryOpProvider") static void shiftRightLongMaxVectorTestsShift(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.shiftRight((int)b[i]).intoArray(r, i); } } assertShiftArraysEquals(a, b, r, LongMaxVectorTests::shiftRight_unary); } @Test(dataProvider = "longBinaryOpMaskProvider") static void shiftRightLongMaxVectorTestsShift(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.shiftRight((int)b[i], vmask).intoArray(r, i); } } assertShiftArraysEquals(a, b, r, mask, LongMaxVectorTests::shiftRight_unary); } static long shiftArithmeticRight_unary(long a, long b) { return (long)((a >> b)); } @Test(dataProvider = "longBinaryOpProvider") static void shiftArithmeticRightLongMaxVectorTestsShift(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.shiftArithmeticRight((int)b[i]).intoArray(r, i); } } assertShiftArraysEquals(a, b, r, LongMaxVectorTests::shiftArithmeticRight_unary); } @Test(dataProvider = "longBinaryOpMaskProvider") static void shiftArithmeticRightLongMaxVectorTestsShift(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.shiftArithmeticRight((int)b[i], vmask).intoArray(r, i); } } assertShiftArraysEquals(a, b, r, mask, LongMaxVectorTests::shiftArithmeticRight_unary); } static long max(long a, long b) { return (long)(Math.max(a, b)); } @Test(dataProvider = "longBinaryOpProvider") static void maxLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.max(bv).intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::max); } static long min(long a, long b) { return (long)(Math.min(a, b)); } @Test(dataProvider = "longBinaryOpProvider") static void minLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.min(bv).intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::min); } static long andLanes(long[] a, int idx) { long res = -1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } return res; } static long andLanes(long[] a) { long res = -1; for (int i = 0; i < a.length; i += SPECIES.length()) { long tmp = -1; for (int j = 0; j < SPECIES.length(); j++) { tmp &= a[i + j]; } res &= tmp; } return res; } @Test(dataProvider = "longUnaryOpProvider") static void andLanesLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); long ra = -1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.andLanes(); } } for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = -1; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); ra &= av.andLanes(); } } assertReductionArraysEquals(a, r, ra, LongMaxVectorTests::andLanes, LongMaxVectorTests::andLanes); } static long orLanes(long[] a, int idx) { long res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } return res; } static long orLanes(long[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { long tmp = 0; for (int j = 0; j < SPECIES.length(); j++) { tmp |= a[i + j]; } res |= tmp; } return res; } @Test(dataProvider = "longUnaryOpProvider") static void orLanesLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.orLanes(); } } for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); ra |= av.orLanes(); } } assertReductionArraysEquals(a, r, ra, LongMaxVectorTests::orLanes, LongMaxVectorTests::orLanes); } static long xorLanes(long[] a, int idx) { long res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res ^= a[i]; } return res; } static long xorLanes(long[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { long tmp = 0; for (int j = 0; j < SPECIES.length(); j++) { tmp ^= a[i + j]; } res ^= tmp; } return res; } @Test(dataProvider = "longUnaryOpProvider") static void xorLanesLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.xorLanes(); } } for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); ra ^= av.xorLanes(); } } assertReductionArraysEquals(a, r, ra, LongMaxVectorTests::xorLanes, LongMaxVectorTests::xorLanes); } static long addLanes(long[] a, int idx) { long res = 0; for (int i = idx; i < (idx + SPECIES.length()); i++) { res += a[i]; } return res; } static long addLanes(long[] a) { long res = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { long tmp = 0; for (int j = 0; j < SPECIES.length(); j++) { tmp += a[i + j]; } res += tmp; } return res; } @Test(dataProvider = "longUnaryOpProvider") static void addLanesLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); long ra = 0; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.addLanes(); } } for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = 0; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); ra += av.addLanes(); } } assertReductionArraysEquals(a, r, ra, LongMaxVectorTests::addLanes, LongMaxVectorTests::addLanes); } static long mulLanes(long[] a, int idx) { long res = 1; for (int i = idx; i < (idx + SPECIES.length()); i++) { res *= a[i]; } return res; } static long mulLanes(long[] a) { long res = 1; for (int i = 0; i < a.length; i += SPECIES.length()) { long tmp = 1; for (int j = 0; j < SPECIES.length(); j++) { tmp *= a[i + j]; } res *= tmp; } return res; } @Test(dataProvider = "longUnaryOpProvider") static void mulLanesLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); long ra = 1; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.mulLanes(); } } for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = 1; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); ra *= av.mulLanes(); } } assertReductionArraysEquals(a, r, ra, LongMaxVectorTests::mulLanes, LongMaxVectorTests::mulLanes); } static long minLanes(long[] a, int idx) { long res = Long.MAX_VALUE; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long)Math.min(res, a[i]); } return res; } static long minLanes(long[] a) { long res = Long.MAX_VALUE; for (int i = 0; i < a.length; i++) { res = (long)Math.min(res, a[i]); } return res; } @Test(dataProvider = "longUnaryOpProvider") static void minLanesLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); long ra = Long.MAX_VALUE; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.minLanes(); } } for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = Long.MAX_VALUE; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); ra = (long)Math.min(ra, av.minLanes()); } } assertReductionArraysEquals(a, r, ra, LongMaxVectorTests::minLanes, LongMaxVectorTests::minLanes); } static long maxLanes(long[] a, int idx) { long res = Long.MIN_VALUE; for (int i = idx; i < (idx + SPECIES.length()); i++) { res = (long)Math.max(res, a[i]); } return res; } static long maxLanes(long[] a) { long res = Long.MIN_VALUE; for (int i = 0; i < a.length; i++) { res = (long)Math.max(res, a[i]); } return res; } @Test(dataProvider = "longUnaryOpProvider") static void maxLanesLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); long ra = Long.MIN_VALUE; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); r[i] = av.maxLanes(); } } for (int ic = 0; ic < INVOC_COUNT; ic++) { ra = Long.MIN_VALUE; for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); ra = (long)Math.max(ra, av.maxLanes()); } } assertReductionArraysEquals(a, r, ra, LongMaxVectorTests::maxLanes, LongMaxVectorTests::maxLanes); } static boolean anyTrue(boolean[] a, int idx) { boolean res = false; for (int i = idx; i < (idx + SPECIES.length()); i++) { res |= a[i]; } return res; } @Test(dataProvider = "boolUnaryOpProvider") static void anyTrueLongMaxVectorTests(IntFunction fm) { boolean[] mask = fm.apply(SPECIES.length()); boolean[] r = fmr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < mask.length; i += SPECIES.length()) { VectorMask vmask = VectorMask.fromArray(SPECIES, mask, i); r[i] = vmask.anyTrue(); } } assertReductionBoolArraysEquals(mask, r, LongMaxVectorTests::anyTrue); } static boolean allTrue(boolean[] a, int idx) { boolean res = true; for (int i = idx; i < (idx + SPECIES.length()); i++) { res &= a[i]; } return res; } @Test(dataProvider = "boolUnaryOpProvider") static void allTrueLongMaxVectorTests(IntFunction fm) { boolean[] mask = fm.apply(SPECIES.length()); boolean[] r = fmr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < mask.length; i += SPECIES.length()) { VectorMask vmask = VectorMask.fromArray(SPECIES, mask, i); r[i] = vmask.allTrue(); } } assertReductionBoolArraysEquals(mask, r, LongMaxVectorTests::allTrue); } @Test(dataProvider = "longUnaryOpProvider") static void withLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.with(0, (long)4).intoArray(r, i); } } assertInsertArraysEquals(a, r, (long)4, 0); } @Test(dataProvider = "longCompareOpProvider") static void lessThanLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); VectorMask mv = av.lessThan(bv); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { Assert.assertEquals(mv.lane(j), a[i + j] < b[i + j]); } } } } @Test(dataProvider = "longCompareOpProvider") static void greaterThanLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); VectorMask mv = av.greaterThan(bv); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { Assert.assertEquals(mv.lane(j), a[i + j] > b[i + j]); } } } } @Test(dataProvider = "longCompareOpProvider") static void equalLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); VectorMask mv = av.equal(bv); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { Assert.assertEquals(mv.lane(j), a[i + j] == b[i + j]); } } } } @Test(dataProvider = "longCompareOpProvider") static void notEqualLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); VectorMask mv = av.notEqual(bv); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { Assert.assertEquals(mv.lane(j), a[i + j] != b[i + j]); } } } } @Test(dataProvider = "longCompareOpProvider") static void lessThanEqLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); VectorMask mv = av.lessThanEq(bv); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { Assert.assertEquals(mv.lane(j), a[i + j] <= b[i + j]); } } } } @Test(dataProvider = "longCompareOpProvider") static void greaterThanEqLongMaxVectorTests(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); VectorMask mv = av.greaterThanEq(bv); // Check results as part of computation. for (int j = 0; j < SPECIES.length(); j++) { Assert.assertEquals(mv.lane(j), a[i + j] >= b[i + j]); } } } } static long blend(long a, long b, boolean mask) { return mask ? b : a; } @Test(dataProvider = "longBinaryOpMaskProvider") static void blendLongMaxVectorTests(IntFunction fa, IntFunction fb, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] b = fb.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); LongVector bv = LongVector.fromArray(SPECIES, b, i); av.blend(bv, vmask).intoArray(r, i); } } assertArraysEquals(a, b, r, mask, LongMaxVectorTests::blend); } @Test(dataProvider = "longUnaryOpShuffleProvider") static void RearrangeLongMaxVectorTests(IntFunction fa, BiFunction fs) { long[] a = fa.apply(SPECIES.length()); int[] order = fs.apply(a.length, SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.rearrange(VectorShuffle.fromArray(SPECIES, order, i)).intoArray(r, i); } } assertRearrangeArraysEquals(a, r, order, SPECIES.length()); } @Test(dataProvider = "longUnaryOpProvider") static void getLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); int num_lanes = SPECIES.length(); // Manually unroll because full unroll happens after intrinsification. // Unroll is needed because get intrinsic requires for index to be a known constant. if (num_lanes == 1) { r[i]=av.lane(0); } else if (num_lanes == 2) { r[i]=av.lane(0); r[i+1]=av.lane(1); } else if (num_lanes == 4) { r[i]=av.lane(0); r[i+1]=av.lane(1); r[i+2]=av.lane(2); r[i+3]=av.lane(3); } else if (num_lanes == 8) { r[i]=av.lane(0); r[i+1]=av.lane(1); r[i+2]=av.lane(2); r[i+3]=av.lane(3); r[i+4]=av.lane(4); r[i+5]=av.lane(5); r[i+6]=av.lane(6); r[i+7]=av.lane(7); } else if (num_lanes == 16) { r[i]=av.lane(0); r[i+1]=av.lane(1); r[i+2]=av.lane(2); r[i+3]=av.lane(3); r[i+4]=av.lane(4); r[i+5]=av.lane(5); r[i+6]=av.lane(6); r[i+7]=av.lane(7); r[i+8]=av.lane(8); r[i+9]=av.lane(9); r[i+10]=av.lane(10); r[i+11]=av.lane(11); r[i+12]=av.lane(12); r[i+13]=av.lane(13); r[i+14]=av.lane(14); r[i+15]=av.lane(15); } else if (num_lanes == 32) { r[i]=av.lane(0); r[i+1]=av.lane(1); r[i+2]=av.lane(2); r[i+3]=av.lane(3); r[i+4]=av.lane(4); r[i+5]=av.lane(5); r[i+6]=av.lane(6); r[i+7]=av.lane(7); r[i+8]=av.lane(8); r[i+9]=av.lane(9); r[i+10]=av.lane(10); r[i+11]=av.lane(11); r[i+12]=av.lane(12); r[i+13]=av.lane(13); r[i+14]=av.lane(14); r[i+15]=av.lane(15); r[i+16]=av.lane(16); r[i+17]=av.lane(17); r[i+18]=av.lane(18); r[i+19]=av.lane(19); r[i+20]=av.lane(20); r[i+21]=av.lane(21); r[i+22]=av.lane(22); r[i+23]=av.lane(23); r[i+24]=av.lane(24); r[i+25]=av.lane(25); r[i+26]=av.lane(26); r[i+27]=av.lane(27); r[i+28]=av.lane(28); r[i+29]=av.lane(29); r[i+30]=av.lane(30); r[i+31]=av.lane(31); } else if (num_lanes == 64) { r[i]=av.lane(0); r[i+1]=av.lane(1); r[i+2]=av.lane(2); r[i+3]=av.lane(3); r[i+4]=av.lane(4); r[i+5]=av.lane(5); r[i+6]=av.lane(6); r[i+7]=av.lane(7); r[i+8]=av.lane(8); r[i+9]=av.lane(9); r[i+10]=av.lane(10); r[i+11]=av.lane(11); r[i+12]=av.lane(12); r[i+13]=av.lane(13); r[i+14]=av.lane(14); r[i+15]=av.lane(15); r[i+16]=av.lane(16); r[i+17]=av.lane(17); r[i+18]=av.lane(18); r[i+19]=av.lane(19); r[i+20]=av.lane(20); r[i+21]=av.lane(21); r[i+22]=av.lane(22); r[i+23]=av.lane(23); r[i+24]=av.lane(24); r[i+25]=av.lane(25); r[i+26]=av.lane(26); r[i+27]=av.lane(27); r[i+28]=av.lane(28); r[i+29]=av.lane(29); r[i+30]=av.lane(30); r[i+31]=av.lane(31); r[i+32]=av.lane(32); r[i+33]=av.lane(33); r[i+34]=av.lane(34); r[i+35]=av.lane(35); r[i+36]=av.lane(36); r[i+37]=av.lane(37); r[i+38]=av.lane(38); r[i+39]=av.lane(39); r[i+40]=av.lane(40); r[i+41]=av.lane(41); r[i+42]=av.lane(42); r[i+43]=av.lane(43); r[i+44]=av.lane(44); r[i+45]=av.lane(45); r[i+46]=av.lane(46); r[i+47]=av.lane(47); r[i+48]=av.lane(48); r[i+49]=av.lane(49); r[i+50]=av.lane(50); r[i+51]=av.lane(51); r[i+52]=av.lane(52); r[i+53]=av.lane(53); r[i+54]=av.lane(54); r[i+55]=av.lane(55); r[i+56]=av.lane(56); r[i+57]=av.lane(57); r[i+58]=av.lane(58); r[i+59]=av.lane(59); r[i+60]=av.lane(60); r[i+61]=av.lane(61); r[i+62]=av.lane(62); r[i+63]=av.lane(63); } else { for (int j = 0; j < SPECIES.length(); j++) { r[i+j]=av.lane(j); } } } } assertArraysEquals(a, r, LongMaxVectorTests::get); } static long neg(long a) { return (long)(-((long)a)); } @Test(dataProvider = "longUnaryOpProvider") static void negLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.neg().intoArray(r, i); } } assertArraysEquals(a, r, LongMaxVectorTests::neg); } @Test(dataProvider = "longUnaryOpMaskProvider") static void negMaskedLongMaxVectorTests(IntFunction fa, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.neg(vmask).intoArray(r, i); } } assertArraysEquals(a, r, mask, LongMaxVectorTests::neg); } static long abs(long a) { return (long)(Math.abs((long)a)); } @Test(dataProvider = "longUnaryOpProvider") static void absLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.abs().intoArray(r, i); } } assertArraysEquals(a, r, LongMaxVectorTests::abs); } @Test(dataProvider = "longUnaryOpMaskProvider") static void absMaskedLongMaxVectorTests(IntFunction fa, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.abs(vmask).intoArray(r, i); } } assertArraysEquals(a, r, mask, LongMaxVectorTests::abs); } static long not(long a) { return (long)(~((long)a)); } @Test(dataProvider = "longUnaryOpProvider") static void notLongMaxVectorTests(IntFunction fa) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.not().intoArray(r, i); } } assertArraysEquals(a, r, LongMaxVectorTests::not); } @Test(dataProvider = "longUnaryOpMaskProvider") static void notMaskedLongMaxVectorTests(IntFunction fa, IntFunction fm) { long[] a = fa.apply(SPECIES.length()); long[] r = fr.apply(SPECIES.length()); boolean[] mask = fm.apply(SPECIES.length()); VectorMask vmask = VectorMask.fromValues(SPECIES, mask); for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.not(vmask).intoArray(r, i); } } assertArraysEquals(a, r, mask, LongMaxVectorTests::not); } static long[] gather(long a[], int ix, int[] b, int iy) { long[] res = new long[SPECIES.length()]; for (int i = 0; i < SPECIES.length(); i++) { int bi = iy + i; res[i] = a[b[bi] + ix]; } return res; } @Test(dataProvider = "longUnaryOpIndexProvider") static void gatherLongMaxVectorTests(IntFunction fa, BiFunction fs) { long[] a = fa.apply(SPECIES.length()); int[] b = fs.apply(a.length, SPECIES.length()); long[] r = new long[a.length]; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i, b, i); av.intoArray(r, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::gather); } static long[] scatter(long a[], int ix, int[] b, int iy) { long[] res = new long[SPECIES.length()]; for (int i = 0; i < SPECIES.length(); i++) { int bi = iy + i; res[b[bi]] = a[i + ix]; } return res; } @Test(dataProvider = "longUnaryOpIndexProvider") static void scatterLongMaxVectorTests(IntFunction fa, BiFunction fs) { long[] a = fa.apply(SPECIES.length()); int[] b = fs.apply(a.length, SPECIES.length()); long[] r = new long[a.length]; for (int ic = 0; ic < INVOC_COUNT; ic++) { for (int i = 0; i < a.length; i += SPECIES.length()) { LongVector av = LongVector.fromArray(SPECIES, a, i); av.intoArray(r, i, b, i); } } assertArraysEquals(a, b, r, LongMaxVectorTests::scatter); } }