< prev index next >

test/jdk/jdk/incubator/vector/Int128VectorTests.java

Print this page

   1 /*
   2  * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */

  46 import org.testng.annotations.DataProvider;
  47 import org.testng.annotations.Test;
  48 
  49 import java.lang.Integer;
  50 import java.util.List;
  51 import java.util.Arrays;
  52 import java.util.function.BiFunction;
  53 import java.util.function.IntFunction;
  54 import java.util.Objects;
  55 import java.util.stream.Collectors;
  56 import java.util.stream.Stream;
  57 
  58 @Test
  59 public class Int128VectorTests extends AbstractVectorTest {
  60 
  61     static final VectorSpecies<Integer> SPECIES =
  62                 IntVector.SPECIES_128;
  63 
  64     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  65 


  66 
  67     private static final int CONST_SHIFT = Integer.SIZE / 2;
  68 
  69     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128);
  70 
  71     static void assertArraysStrictlyEquals(int[] r, int[] a) {
  72         for (int i = 0; i < a.length; i++) {
  73             if (r[i] != a[i]) {
  74                 Assert.fail("at index #" + i + ", expected = " + a[i] + ", actual = " + r[i]);
  75             }
  76         }
  77     }
  78 
  79     interface FUnOp {
  80         int apply(int a);
  81     }
  82 
  83     static void assertArraysEquals(int[] r, int[] a, FUnOp f) {
  84         int i = 0;
  85         try {

3059 
3060     @Test(dataProvider = "intUnaryOpMaskProvider")
3061     static void ROLInt128VectorTestsScalarShiftMaskedConst(IntFunction<int[]> fa,
3062                                           IntFunction<boolean[]> fm) {
3063         int[] a = fa.apply(SPECIES.length());
3064         int[] r = fr.apply(SPECIES.length());
3065         boolean[] mask = fm.apply(SPECIES.length());
3066         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3067 
3068         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3069             for (int i = 0; i < a.length; i += SPECIES.length()) {
3070                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3071                 av.lanewise(VectorOperators.ROL, CONST_SHIFT, vmask).intoArray(r, i);
3072             }
3073         }
3074 
3075         assertShiftConstEquals(r, a, mask, Int128VectorTests::ROL_binary_const);
3076     }
3077 
3078 
3079     static IntVector bv_MIN = IntVector.broadcast(SPECIES, (int)10);
3080 
3081     @Test(dataProvider = "intUnaryOpProvider")
3082     static void MINInt128VectorTestsWithMemOp(IntFunction<int[]> fa) {
3083         int[] a = fa.apply(SPECIES.length());
3084         int[] r = fr.apply(SPECIES.length());
3085 
3086         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3087             for (int i = 0; i < a.length; i += SPECIES.length()) {
3088                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3089                 av.lanewise(VectorOperators.MIN, bv_MIN).intoArray(r, i);
3090             }
3091         }
3092 
3093         assertArraysEquals(r, a, (int)10, Int128VectorTests::MIN);
3094     }
3095 
3096     static IntVector bv_min = IntVector.broadcast(SPECIES, (int)10);
3097 
3098     @Test(dataProvider = "intUnaryOpProvider")
3099     static void minInt128VectorTestsWithMemOp(IntFunction<int[]> fa) {
3100         int[] a = fa.apply(SPECIES.length());
3101         int[] r = fr.apply(SPECIES.length());
3102 
3103         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3104             for (int i = 0; i < a.length; i += SPECIES.length()) {
3105                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3106                 av.min(bv_min).intoArray(r, i);
3107             }
3108         }
3109 
3110         assertArraysEquals(r, a, (int)10, Int128VectorTests::min);
3111     }
3112 
3113     static IntVector bv_MIN_M = IntVector.broadcast(SPECIES, (int)10);
3114 
3115     @Test(dataProvider = "intUnaryOpMaskProvider")
3116     static void MINInt128VectorTestsMaskedWithMemOp(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3117         int[] a = fa.apply(SPECIES.length());
3118         int[] r = fr.apply(SPECIES.length());
3119         boolean[] mask = fm.apply(SPECIES.length());
3120         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3121 
3122         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3123             for (int i = 0; i < a.length; i += SPECIES.length()) {
3124                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3125                 av.lanewise(VectorOperators.MIN, bv_MIN_M, vmask).intoArray(r, i);
3126             }
3127         }
3128 
3129         assertArraysEquals(r, a, (int)10, mask, Int128VectorTests::MIN);
3130     }
3131 
3132     static IntVector bv_MAX = IntVector.broadcast(SPECIES, (int)10);
3133 
3134     @Test(dataProvider = "intUnaryOpProvider")
3135     static void MAXInt128VectorTestsWithMemOp(IntFunction<int[]> fa) {
3136         int[] a = fa.apply(SPECIES.length());
3137         int[] r = fr.apply(SPECIES.length());
3138 
3139         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3140             for (int i = 0; i < a.length; i += SPECIES.length()) {
3141                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3142                 av.lanewise(VectorOperators.MAX, bv_MAX).intoArray(r, i);
3143             }
3144         }
3145 
3146         assertArraysEquals(r, a, (int)10, Int128VectorTests::MAX);
3147     }
3148 
3149     static IntVector bv_max = IntVector.broadcast(SPECIES, (int)10);
3150 
3151     @Test(dataProvider = "intUnaryOpProvider")
3152     static void maxInt128VectorTestsWithMemOp(IntFunction<int[]> fa) {
3153         int[] a = fa.apply(SPECIES.length());
3154         int[] r = fr.apply(SPECIES.length());
3155 
3156         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3157             for (int i = 0; i < a.length; i += SPECIES.length()) {
3158                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3159                 av.max(bv_max).intoArray(r, i);
3160             }
3161         }
3162 
3163         assertArraysEquals(r, a, (int)10, Int128VectorTests::max);
3164     }
3165 
3166     static IntVector bv_MAX_M = IntVector.broadcast(SPECIES, (int)10);
3167 
3168     @Test(dataProvider = "intUnaryOpMaskProvider")
3169     static void MAXInt128VectorTestsMaskedWithMemOp(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3170         int[] a = fa.apply(SPECIES.length());
3171         int[] r = fr.apply(SPECIES.length());
3172         boolean[] mask = fm.apply(SPECIES.length());
3173         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3174 
3175         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3176             for (int i = 0; i < a.length; i += SPECIES.length()) {
3177                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3178                 av.lanewise(VectorOperators.MAX, bv_MAX_M, vmask).intoArray(r, i);
3179             }
3180         }
3181 
3182         assertArraysEquals(r, a, (int)10, mask, Int128VectorTests::MAX);
3183     }
3184 
3185     static int MIN(int a, int b) {
3186         return (int)(Math.min(a, b));
3187     }
3188 
3189     @Test(dataProvider = "intBinaryOpProvider")
3190     static void MINInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
3191         int[] a = fa.apply(SPECIES.length());
3192         int[] b = fb.apply(SPECIES.length());
3193         int[] r = fr.apply(SPECIES.length());
3194 
3195         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3196             for (int i = 0; i < a.length; i += SPECIES.length()) {
3197                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3198                 IntVector bv = IntVector.fromArray(SPECIES, b, i);

   1 /*
   2  * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */

  46 import org.testng.annotations.DataProvider;
  47 import org.testng.annotations.Test;
  48 
  49 import java.lang.Integer;
  50 import java.util.List;
  51 import java.util.Arrays;
  52 import java.util.function.BiFunction;
  53 import java.util.function.IntFunction;
  54 import java.util.Objects;
  55 import java.util.stream.Collectors;
  56 import java.util.stream.Stream;
  57 
  58 @Test
  59 public class Int128VectorTests extends AbstractVectorTest {
  60 
  61     static final VectorSpecies<Integer> SPECIES =
  62                 IntVector.SPECIES_128;
  63 
  64     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  65 
  66     static IntVector bcast_vec = IntVector.broadcast(SPECIES, (int)10);
  67 
  68 
  69     private static final int CONST_SHIFT = Integer.SIZE / 2;
  70 
  71     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 128);
  72 
  73     static void assertArraysStrictlyEquals(int[] r, int[] a) {
  74         for (int i = 0; i < a.length; i++) {
  75             if (r[i] != a[i]) {
  76                 Assert.fail("at index #" + i + ", expected = " + a[i] + ", actual = " + r[i]);
  77             }
  78         }
  79     }
  80 
  81     interface FUnOp {
  82         int apply(int a);
  83     }
  84 
  85     static void assertArraysEquals(int[] r, int[] a, FUnOp f) {
  86         int i = 0;
  87         try {

3061 
3062     @Test(dataProvider = "intUnaryOpMaskProvider")
3063     static void ROLInt128VectorTestsScalarShiftMaskedConst(IntFunction<int[]> fa,
3064                                           IntFunction<boolean[]> fm) {
3065         int[] a = fa.apply(SPECIES.length());
3066         int[] r = fr.apply(SPECIES.length());
3067         boolean[] mask = fm.apply(SPECIES.length());
3068         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3069 
3070         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3071             for (int i = 0; i < a.length; i += SPECIES.length()) {
3072                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3073                 av.lanewise(VectorOperators.ROL, CONST_SHIFT, vmask).intoArray(r, i);
3074             }
3075         }
3076 
3077         assertShiftConstEquals(r, a, mask, Int128VectorTests::ROL_binary_const);
3078     }
3079 
3080 


3081     @Test(dataProvider = "intUnaryOpProvider")
3082     static void MINInt128VectorTestsWithMemOp(IntFunction<int[]> fa) {
3083         int[] a = fa.apply(SPECIES.length());
3084         int[] r = fr.apply(SPECIES.length());
3085 
3086         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3087             for (int i = 0; i < a.length; i += SPECIES.length()) {
3088                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3089                 av.lanewise(VectorOperators.MIN, bcast_vec).intoArray(r, i);
3090             }
3091         }
3092 
3093         assertArraysEquals(r, a, (int)10, Int128VectorTests::MIN);
3094     }
3095 


3096     @Test(dataProvider = "intUnaryOpProvider")
3097     static void minInt128VectorTestsWithMemOp(IntFunction<int[]> fa) {
3098         int[] a = fa.apply(SPECIES.length());
3099         int[] r = fr.apply(SPECIES.length());
3100 
3101         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3102             for (int i = 0; i < a.length; i += SPECIES.length()) {
3103                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3104                 av.min(bcast_vec).intoArray(r, i);
3105             }
3106         }
3107 
3108         assertArraysEquals(r, a, (int)10, Int128VectorTests::min);
3109     }
3110 


3111     @Test(dataProvider = "intUnaryOpMaskProvider")
3112     static void MINInt128VectorTestsMaskedWithMemOp(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3113         int[] a = fa.apply(SPECIES.length());
3114         int[] r = fr.apply(SPECIES.length());
3115         boolean[] mask = fm.apply(SPECIES.length());
3116         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3117 
3118         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3119             for (int i = 0; i < a.length; i += SPECIES.length()) {
3120                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3121                 av.lanewise(VectorOperators.MIN, bcast_vec, vmask).intoArray(r, i);
3122             }
3123         }
3124 
3125         assertArraysEquals(r, a, (int)10, mask, Int128VectorTests::MIN);
3126     }
3127 


3128     @Test(dataProvider = "intUnaryOpProvider")
3129     static void MAXInt128VectorTestsWithMemOp(IntFunction<int[]> fa) {
3130         int[] a = fa.apply(SPECIES.length());
3131         int[] r = fr.apply(SPECIES.length());
3132 
3133         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3134             for (int i = 0; i < a.length; i += SPECIES.length()) {
3135                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3136                 av.lanewise(VectorOperators.MAX, bcast_vec).intoArray(r, i);
3137             }
3138         }
3139 
3140         assertArraysEquals(r, a, (int)10, Int128VectorTests::MAX);
3141     }
3142 


3143     @Test(dataProvider = "intUnaryOpProvider")
3144     static void maxInt128VectorTestsWithMemOp(IntFunction<int[]> fa) {
3145         int[] a = fa.apply(SPECIES.length());
3146         int[] r = fr.apply(SPECIES.length());
3147 
3148         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3149             for (int i = 0; i < a.length; i += SPECIES.length()) {
3150                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3151                 av.max(bcast_vec).intoArray(r, i);
3152             }
3153         }
3154 
3155         assertArraysEquals(r, a, (int)10, Int128VectorTests::max);
3156     }
3157 


3158     @Test(dataProvider = "intUnaryOpMaskProvider")
3159     static void MAXInt128VectorTestsMaskedWithMemOp(IntFunction<int[]> fa, IntFunction<boolean[]> fm) {
3160         int[] a = fa.apply(SPECIES.length());
3161         int[] r = fr.apply(SPECIES.length());
3162         boolean[] mask = fm.apply(SPECIES.length());
3163         VectorMask<Integer> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3164 
3165         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3166             for (int i = 0; i < a.length; i += SPECIES.length()) {
3167                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3168                 av.lanewise(VectorOperators.MAX, bcast_vec, vmask).intoArray(r, i);
3169             }
3170         }
3171 
3172         assertArraysEquals(r, a, (int)10, mask, Int128VectorTests::MAX);
3173     }
3174 
3175     static int MIN(int a, int b) {
3176         return (int)(Math.min(a, b));
3177     }
3178 
3179     @Test(dataProvider = "intBinaryOpProvider")
3180     static void MINInt128VectorTests(IntFunction<int[]> fa, IntFunction<int[]> fb) {
3181         int[] a = fa.apply(SPECIES.length());
3182         int[] b = fb.apply(SPECIES.length());
3183         int[] r = fr.apply(SPECIES.length());
3184 
3185         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3186             for (int i = 0; i < a.length; i += SPECIES.length()) {
3187                 IntVector av = IntVector.fromArray(SPECIES, a, i);
3188                 IntVector bv = IntVector.fromArray(SPECIES, b, i);
< prev index next >