< prev index next >

test/jdk/jdk/incubator/vector/LongMaxVectorTests.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 LongMaxVectorTests extends AbstractVectorTest {
  60 
  61     static final VectorSpecies<Long> SPECIES =
  62                 LongVector.SPECIES_MAX;
  63 
  64     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  65 


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

3086 
3087     @Test(dataProvider = "longUnaryOpMaskProvider")
3088     static void ROLLongMaxVectorTestsScalarShiftMaskedConst(IntFunction<long[]> fa,
3089                                           IntFunction<boolean[]> fm) {
3090         long[] a = fa.apply(SPECIES.length());
3091         long[] r = fr.apply(SPECIES.length());
3092         boolean[] mask = fm.apply(SPECIES.length());
3093         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3094 
3095         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3096             for (int i = 0; i < a.length; i += SPECIES.length()) {
3097                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3098                 av.lanewise(VectorOperators.ROL, CONST_SHIFT, vmask).intoArray(r, i);
3099             }
3100         }
3101 
3102         assertShiftConstEquals(r, a, mask, LongMaxVectorTests::ROL_binary_const);
3103     }
3104 
3105 
3106     static LongVector bv_MIN = LongVector.broadcast(SPECIES, (long)10);
3107 
3108     @Test(dataProvider = "longUnaryOpProvider")
3109     static void MINLongMaxVectorTestsWithMemOp(IntFunction<long[]> fa) {
3110         long[] a = fa.apply(SPECIES.length());
3111         long[] r = fr.apply(SPECIES.length());
3112 
3113         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3114             for (int i = 0; i < a.length; i += SPECIES.length()) {
3115                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3116                 av.lanewise(VectorOperators.MIN, bv_MIN).intoArray(r, i);
3117             }
3118         }
3119 
3120         assertArraysEquals(r, a, (long)10, LongMaxVectorTests::MIN);
3121     }
3122 
3123     static LongVector bv_min = LongVector.broadcast(SPECIES, (long)10);
3124 
3125     @Test(dataProvider = "longUnaryOpProvider")
3126     static void minLongMaxVectorTestsWithMemOp(IntFunction<long[]> fa) {
3127         long[] a = fa.apply(SPECIES.length());
3128         long[] r = fr.apply(SPECIES.length());
3129 
3130         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3131             for (int i = 0; i < a.length; i += SPECIES.length()) {
3132                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3133                 av.min(bv_min).intoArray(r, i);
3134             }
3135         }
3136 
3137         assertArraysEquals(r, a, (long)10, LongMaxVectorTests::min);
3138     }
3139 
3140     static LongVector bv_MIN_M = LongVector.broadcast(SPECIES, (long)10);
3141 
3142     @Test(dataProvider = "longUnaryOpMaskProvider")
3143     static void MINLongMaxVectorTestsMaskedWithMemOp(IntFunction<long[]> fa, IntFunction<boolean[]> fm) {
3144         long[] a = fa.apply(SPECIES.length());
3145         long[] r = fr.apply(SPECIES.length());
3146         boolean[] mask = fm.apply(SPECIES.length());
3147         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3148 
3149         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3150             for (int i = 0; i < a.length; i += SPECIES.length()) {
3151                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3152                 av.lanewise(VectorOperators.MIN, bv_MIN_M, vmask).intoArray(r, i);
3153             }
3154         }
3155 
3156         assertArraysEquals(r, a, (long)10, mask, LongMaxVectorTests::MIN);
3157     }
3158 
3159     static LongVector bv_MAX = LongVector.broadcast(SPECIES, (long)10);
3160 
3161     @Test(dataProvider = "longUnaryOpProvider")
3162     static void MAXLongMaxVectorTestsWithMemOp(IntFunction<long[]> fa) {
3163         long[] a = fa.apply(SPECIES.length());
3164         long[] r = fr.apply(SPECIES.length());
3165 
3166         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3167             for (int i = 0; i < a.length; i += SPECIES.length()) {
3168                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3169                 av.lanewise(VectorOperators.MAX, bv_MAX).intoArray(r, i);
3170             }
3171         }
3172 
3173         assertArraysEquals(r, a, (long)10, LongMaxVectorTests::MAX);
3174     }
3175 
3176     static LongVector bv_max = LongVector.broadcast(SPECIES, (long)10);
3177 
3178     @Test(dataProvider = "longUnaryOpProvider")
3179     static void maxLongMaxVectorTestsWithMemOp(IntFunction<long[]> fa) {
3180         long[] a = fa.apply(SPECIES.length());
3181         long[] r = fr.apply(SPECIES.length());
3182 
3183         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3184             for (int i = 0; i < a.length; i += SPECIES.length()) {
3185                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3186                 av.max(bv_max).intoArray(r, i);
3187             }
3188         }
3189 
3190         assertArraysEquals(r, a, (long)10, LongMaxVectorTests::max);
3191     }
3192 
3193     static LongVector bv_MAX_M = LongVector.broadcast(SPECIES, (long)10);
3194 
3195     @Test(dataProvider = "longUnaryOpMaskProvider")
3196     static void MAXLongMaxVectorTestsMaskedWithMemOp(IntFunction<long[]> fa, IntFunction<boolean[]> fm) {
3197         long[] a = fa.apply(SPECIES.length());
3198         long[] r = fr.apply(SPECIES.length());
3199         boolean[] mask = fm.apply(SPECIES.length());
3200         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3201 
3202         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3203             for (int i = 0; i < a.length; i += SPECIES.length()) {
3204                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3205                 av.lanewise(VectorOperators.MAX, bv_MAX_M, vmask).intoArray(r, i);
3206             }
3207         }
3208 
3209         assertArraysEquals(r, a, (long)10, mask, LongMaxVectorTests::MAX);
3210     }
3211 
3212     static long MIN(long a, long b) {
3213         return (long)(Math.min(a, b));
3214     }
3215 
3216     @Test(dataProvider = "longBinaryOpProvider")
3217     static void MINLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) {
3218         long[] a = fa.apply(SPECIES.length());
3219         long[] b = fb.apply(SPECIES.length());
3220         long[] r = fr.apply(SPECIES.length());
3221 
3222         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3223             for (int i = 0; i < a.length; i += SPECIES.length()) {
3224                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3225                 LongVector bv = LongVector.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 LongMaxVectorTests extends AbstractVectorTest {
  60 
  61     static final VectorSpecies<Long> SPECIES =
  62                 LongVector.SPECIES_MAX;
  63 
  64     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  65 
  66     static LongVector bcast_vec = LongVector.broadcast(SPECIES, (long)10);
  67 
  68     static VectorShape getMaxBit() {
  69         return VectorShape.S_Max_BIT;
  70     }
  71 
  72     private static final int Max = 256;  // juts so we can do N/Max
  73 
  74     private static final long CONST_SHIFT = Long.SIZE / 2;
  75 
  76     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / Max);
  77 
  78     static void assertArraysStrictlyEquals(long[] r, long[] a) {
  79         for (int i = 0; i < a.length; i++) {
  80             if (r[i] != a[i]) {
  81                 Assert.fail("at index #" + i + ", expected = " + a[i] + ", actual = " + r[i]);
  82             }
  83         }
  84     }
  85 
  86     interface FUnOp {
  87         long apply(long a);

3088 
3089     @Test(dataProvider = "longUnaryOpMaskProvider")
3090     static void ROLLongMaxVectorTestsScalarShiftMaskedConst(IntFunction<long[]> fa,
3091                                           IntFunction<boolean[]> fm) {
3092         long[] a = fa.apply(SPECIES.length());
3093         long[] r = fr.apply(SPECIES.length());
3094         boolean[] mask = fm.apply(SPECIES.length());
3095         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3096 
3097         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3098             for (int i = 0; i < a.length; i += SPECIES.length()) {
3099                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3100                 av.lanewise(VectorOperators.ROL, CONST_SHIFT, vmask).intoArray(r, i);
3101             }
3102         }
3103 
3104         assertShiftConstEquals(r, a, mask, LongMaxVectorTests::ROL_binary_const);
3105     }
3106 
3107 


3108     @Test(dataProvider = "longUnaryOpProvider")
3109     static void MINLongMaxVectorTestsWithMemOp(IntFunction<long[]> fa) {
3110         long[] a = fa.apply(SPECIES.length());
3111         long[] r = fr.apply(SPECIES.length());
3112 
3113         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3114             for (int i = 0; i < a.length; i += SPECIES.length()) {
3115                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3116                 av.lanewise(VectorOperators.MIN, bcast_vec).intoArray(r, i);
3117             }
3118         }
3119 
3120         assertArraysEquals(r, a, (long)10, LongMaxVectorTests::MIN);
3121     }
3122 


3123     @Test(dataProvider = "longUnaryOpProvider")
3124     static void minLongMaxVectorTestsWithMemOp(IntFunction<long[]> fa) {
3125         long[] a = fa.apply(SPECIES.length());
3126         long[] r = fr.apply(SPECIES.length());
3127 
3128         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3129             for (int i = 0; i < a.length; i += SPECIES.length()) {
3130                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3131                 av.min(bcast_vec).intoArray(r, i);
3132             }
3133         }
3134 
3135         assertArraysEquals(r, a, (long)10, LongMaxVectorTests::min);
3136     }
3137 


3138     @Test(dataProvider = "longUnaryOpMaskProvider")
3139     static void MINLongMaxVectorTestsMaskedWithMemOp(IntFunction<long[]> fa, IntFunction<boolean[]> fm) {
3140         long[] a = fa.apply(SPECIES.length());
3141         long[] r = fr.apply(SPECIES.length());
3142         boolean[] mask = fm.apply(SPECIES.length());
3143         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3144 
3145         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3146             for (int i = 0; i < a.length; i += SPECIES.length()) {
3147                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3148                 av.lanewise(VectorOperators.MIN, bcast_vec, vmask).intoArray(r, i);
3149             }
3150         }
3151 
3152         assertArraysEquals(r, a, (long)10, mask, LongMaxVectorTests::MIN);
3153     }
3154 


3155     @Test(dataProvider = "longUnaryOpProvider")
3156     static void MAXLongMaxVectorTestsWithMemOp(IntFunction<long[]> fa) {
3157         long[] a = fa.apply(SPECIES.length());
3158         long[] r = fr.apply(SPECIES.length());
3159 
3160         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3161             for (int i = 0; i < a.length; i += SPECIES.length()) {
3162                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3163                 av.lanewise(VectorOperators.MAX, bcast_vec).intoArray(r, i);
3164             }
3165         }
3166 
3167         assertArraysEquals(r, a, (long)10, LongMaxVectorTests::MAX);
3168     }
3169 


3170     @Test(dataProvider = "longUnaryOpProvider")
3171     static void maxLongMaxVectorTestsWithMemOp(IntFunction<long[]> fa) {
3172         long[] a = fa.apply(SPECIES.length());
3173         long[] r = fr.apply(SPECIES.length());
3174 
3175         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3176             for (int i = 0; i < a.length; i += SPECIES.length()) {
3177                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3178                 av.max(bcast_vec).intoArray(r, i);
3179             }
3180         }
3181 
3182         assertArraysEquals(r, a, (long)10, LongMaxVectorTests::max);
3183     }
3184 


3185     @Test(dataProvider = "longUnaryOpMaskProvider")
3186     static void MAXLongMaxVectorTestsMaskedWithMemOp(IntFunction<long[]> fa, IntFunction<boolean[]> fm) {
3187         long[] a = fa.apply(SPECIES.length());
3188         long[] r = fr.apply(SPECIES.length());
3189         boolean[] mask = fm.apply(SPECIES.length());
3190         VectorMask<Long> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3191 
3192         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3193             for (int i = 0; i < a.length; i += SPECIES.length()) {
3194                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3195                 av.lanewise(VectorOperators.MAX, bcast_vec, vmask).intoArray(r, i);
3196             }
3197         }
3198 
3199         assertArraysEquals(r, a, (long)10, mask, LongMaxVectorTests::MAX);
3200     }
3201 
3202     static long MIN(long a, long b) {
3203         return (long)(Math.min(a, b));
3204     }
3205 
3206     @Test(dataProvider = "longBinaryOpProvider")
3207     static void MINLongMaxVectorTests(IntFunction<long[]> fa, IntFunction<long[]> fb) {
3208         long[] a = fa.apply(SPECIES.length());
3209         long[] b = fb.apply(SPECIES.length());
3210         long[] r = fr.apply(SPECIES.length());
3211 
3212         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3213             for (int i = 0; i < a.length; i += SPECIES.length()) {
3214                 LongVector av = LongVector.fromArray(SPECIES, a, i);
3215                 LongVector bv = LongVector.fromArray(SPECIES, b, i);
< prev index next >