/* * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2019, Arm Limited. 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 Long512VectorExceptionTests * */ import jdk.incubator.vector.Vector.Shape; 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.util.List; import java.util.function.IntFunction; @Test public class Long512VectorExceptionTests extends AbstractVectorTest { static final LongVector.LongSpecies SPECIES = LongVector.species(Shape.S_512_BIT); static final int LOAD_STORE_ARRAY_LENGTH = SPECIES.length() / 2; static final int GATHER_SCATTER_ARRAY_LENGTH = SPECIES.length(); static final Vector.Mask LOAD_STORE_MASK = LongVector.maskFromValues( SPECIES, fill_boolean(SPECIES.length(), i -> (i < LOAD_STORE_ARRAY_LENGTH))); static final Vector.Mask GATHER_SCATTER_MASK = LongVector.maskFromValues( SPECIES, fill_boolean(SPECIES.length(), i -> ((i * 2 + 1) < GATHER_SCATTER_ARRAY_LENGTH))); static final Vector.Mask ALL_TRUE_MASK = LongVector.maskFromValues( SPECIES, fill_boolean(SPECIES.length(), i -> true)); 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 final List> LONG_GENERATORS = List.of( withToString("long[i + 1]", (int s) -> { return fill(s, i -> (((long)(i + 1) == 0) ? 1 : (long)(i + 1))); }) ); static final List> INDEX_GENERATORS = List.of( withToString("index[i * 2 + 1]", (int s) -> { return fillInts(s, i -> (i * 2 + 1)); }) ); @DataProvider public Object[][] longProvider() { return LONG_GENERATORS.stream(). map(f -> new Object[]{f}). toArray(Object[][]::new); } @DataProvider public Object[][] longIndexMapProvider() { return INDEX_GENERATORS.stream(). flatMap(fim -> LONG_GENERATORS.stream().map(fa -> { return new Object[] {fa, fim}; })). toArray(Object[][]::new); } @Test(dataProvider = "longProvider") static void loadStoreArrayWithMask(IntFunction fa) { long[] a = fa.apply(SPECIES.length() / 2); long[] r = new long[a.length]; // case 1: No IndexOutOfBoundsException for unset mask lanes. LongVector av = LongVector.fromArray(SPECIES, a, 0, LOAD_STORE_MASK); av.intoArray(r, 0, LOAD_STORE_MASK); Assert.assertEquals(a, r); // case 2: long[] new_a = new long[a.length]; av = LongVector.fromArray(SPECIES, new_a, 0, LOAD_STORE_MASK); try { // Result in IndexOutOfBoundsException for intoArray(). av.intoArray(r, 0, ALL_TRUE_MASK); Assert.fail("Expected IndexOutOfBoundsException not thrown"); } catch(IndexOutOfBoundsException e) { } // case 3: try { // Result in IndexOutOfBoundsException for fromArray(). av = LongVector.fromArray(SPECIES, a, 0, ALL_TRUE_MASK); Assert.fail("Expected IndexOutOfBoundsException not thrown"); } catch(IndexOutOfBoundsException e) { } } @Test(dataProvider = "longIndexMapProvider") static void gatherScatterArrayWithMask(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); int[] indexMap = fb.apply(SPECIES.length()); long[] r = new long[a.length]; // case 1: No IndexOutOfBoundsException for unset mask lanes. LongVector av = LongVector.fromArray(SPECIES, a, 0); av.intoArray(r, 0, GATHER_SCATTER_MASK, indexMap, 0); av = LongVector.fromArray(SPECIES, a, 0, GATHER_SCATTER_MASK, indexMap, 0); // case 2: long[] r1 = new long[a.length]; long[] r2 = new long[a.length]; av = LongVector.fromArray(SPECIES, a, 0); try { // Result in IndexOutOfBoundsException for scatter. av.intoArray(r2, 0, ALL_TRUE_MASK, indexMap, 0); Assert.fail("Expected IndexOutOfBoundsException not thrown"); } catch(IndexOutOfBoundsException e) { } // case 3: try { // Result in IndexOutOfBoundsException for gather. av = LongVector.fromArray(SPECIES, a, 0, ALL_TRUE_MASK, indexMap, 0); Assert.fail("Expected IndexOutOfBoundsException not thrown"); } catch(IndexOutOfBoundsException e) { } } @Test(dataProvider = "longProvider") static void loadStoreArray(IntFunction fa) { long[] a = fa.apply(SPECIES.length() / 2); long[] r = new long[a.length]; // case 1: try { // Result in IndexOutOfBoundsException for fromArray(). LongVector av = LongVector.fromArray(SPECIES, a, 0); Assert.fail("Expected IndexOutOfBoundsException not thrown"); } catch(IndexOutOfBoundsException e) { } // case 2: LongVector av = LongVector.fromArray(SPECIES, a, 0, LOAD_STORE_MASK); try { // Result in IndexOutOfBoundsException for intoArray(). av.intoArray(r, 0); Assert.fail("Expected IndexOutOfBoundsException not thrown"); } catch(IndexOutOfBoundsException e) { } } @Test(dataProvider = "longIndexMapProvider") static void gatherScatterArray(IntFunction fa, IntFunction fb) { long[] a = fa.apply(SPECIES.length()); int[] indexMap = fb.apply(SPECIES.length()); long[] r = new long[a.length]; // case 1: try { // Result in IndexOutOfBoundsException for gather. LongVector av = LongVector.fromArray(SPECIES, a, 0, indexMap, 0); Assert.fail("Expected IndexOutOfBoundsException not thrown"); } catch(IndexOutOfBoundsException e) { } // case 2: LongVector av = LongVector.fromArray(SPECIES, a, 0, GATHER_SCATTER_MASK, indexMap, 0); try { // Result in IndexOutOfBoundsException for scatter. av.intoArray(r, 0, indexMap, 0); Assert.fail("Expected IndexOutOfBoundsException not thrown"); } catch(IndexOutOfBoundsException e) { } } }