< prev index next >

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


  66 
  67     private static final byte CONST_SHIFT = Byte.SIZE / 2;
  68 
  69     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
  70 
  71     static void assertArraysStrictlyEquals(byte[] r, byte[] 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         byte apply(byte a);
  81     }
  82 
  83     static void assertArraysEquals(byte[] r, byte[] a, FUnOp f) {
  84         int i = 0;
  85         try {

3015 
3016     @Test(dataProvider = "byteUnaryOpMaskProvider")
3017     static void ROLByte512VectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa,
3018                                           IntFunction<boolean[]> fm) {
3019         byte[] a = fa.apply(SPECIES.length());
3020         byte[] r = fr.apply(SPECIES.length());
3021         boolean[] mask = fm.apply(SPECIES.length());
3022         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3023 
3024         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3025             for (int i = 0; i < a.length; i += SPECIES.length()) {
3026                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3027                 av.lanewise(VectorOperators.ROL, CONST_SHIFT, vmask).intoArray(r, i);
3028             }
3029         }
3030 
3031         assertShiftConstEquals(r, a, mask, Byte512VectorTests::ROL_binary_const);
3032     }
3033 
3034 
3035     static ByteVector bv_MIN = ByteVector.broadcast(SPECIES, (byte)10);
3036 
3037     @Test(dataProvider = "byteUnaryOpProvider")
3038     static void MINByte512VectorTestsWithMemOp(IntFunction<byte[]> fa) {
3039         byte[] a = fa.apply(SPECIES.length());
3040         byte[] r = fr.apply(SPECIES.length());
3041 
3042         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3043             for (int i = 0; i < a.length; i += SPECIES.length()) {
3044                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3045                 av.lanewise(VectorOperators.MIN, bv_MIN).intoArray(r, i);
3046             }
3047         }
3048 
3049         assertArraysEquals(r, a, (byte)10, Byte512VectorTests::MIN);
3050     }
3051 
3052     static ByteVector bv_min = ByteVector.broadcast(SPECIES, (byte)10);
3053 
3054     @Test(dataProvider = "byteUnaryOpProvider")
3055     static void minByte512VectorTestsWithMemOp(IntFunction<byte[]> fa) {
3056         byte[] a = fa.apply(SPECIES.length());
3057         byte[] r = fr.apply(SPECIES.length());
3058 
3059         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3060             for (int i = 0; i < a.length; i += SPECIES.length()) {
3061                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3062                 av.min(bv_min).intoArray(r, i);
3063             }
3064         }
3065 
3066         assertArraysEquals(r, a, (byte)10, Byte512VectorTests::min);
3067     }
3068 
3069     static ByteVector bv_MIN_M = ByteVector.broadcast(SPECIES, (byte)10);
3070 
3071     @Test(dataProvider = "byteUnaryOpMaskProvider")
3072     static void MINByte512VectorTestsMaskedWithMemOp(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
3073         byte[] a = fa.apply(SPECIES.length());
3074         byte[] r = fr.apply(SPECIES.length());
3075         boolean[] mask = fm.apply(SPECIES.length());
3076         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3077 
3078         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3079             for (int i = 0; i < a.length; i += SPECIES.length()) {
3080                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3081                 av.lanewise(VectorOperators.MIN, bv_MIN_M, vmask).intoArray(r, i);
3082             }
3083         }
3084 
3085         assertArraysEquals(r, a, (byte)10, mask, Byte512VectorTests::MIN);
3086     }
3087 
3088     static ByteVector bv_MAX = ByteVector.broadcast(SPECIES, (byte)10);
3089 
3090     @Test(dataProvider = "byteUnaryOpProvider")
3091     static void MAXByte512VectorTestsWithMemOp(IntFunction<byte[]> fa) {
3092         byte[] a = fa.apply(SPECIES.length());
3093         byte[] r = fr.apply(SPECIES.length());
3094 
3095         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3096             for (int i = 0; i < a.length; i += SPECIES.length()) {
3097                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3098                 av.lanewise(VectorOperators.MAX, bv_MAX).intoArray(r, i);
3099             }
3100         }
3101 
3102         assertArraysEquals(r, a, (byte)10, Byte512VectorTests::MAX);
3103     }
3104 
3105     static ByteVector bv_max = ByteVector.broadcast(SPECIES, (byte)10);
3106 
3107     @Test(dataProvider = "byteUnaryOpProvider")
3108     static void maxByte512VectorTestsWithMemOp(IntFunction<byte[]> fa) {
3109         byte[] a = fa.apply(SPECIES.length());
3110         byte[] r = fr.apply(SPECIES.length());
3111 
3112         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3113             for (int i = 0; i < a.length; i += SPECIES.length()) {
3114                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3115                 av.max(bv_max).intoArray(r, i);
3116             }
3117         }
3118 
3119         assertArraysEquals(r, a, (byte)10, Byte512VectorTests::max);
3120     }
3121 
3122     static ByteVector bv_MAX_M = ByteVector.broadcast(SPECIES, (byte)10);
3123 
3124     @Test(dataProvider = "byteUnaryOpMaskProvider")
3125     static void MAXByte512VectorTestsMaskedWithMemOp(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
3126         byte[] a = fa.apply(SPECIES.length());
3127         byte[] r = fr.apply(SPECIES.length());
3128         boolean[] mask = fm.apply(SPECIES.length());
3129         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3130 
3131         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3132             for (int i = 0; i < a.length; i += SPECIES.length()) {
3133                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3134                 av.lanewise(VectorOperators.MAX, bv_MAX_M, vmask).intoArray(r, i);
3135             }
3136         }
3137 
3138         assertArraysEquals(r, a, (byte)10, mask, Byte512VectorTests::MAX);
3139     }
3140 
3141     static byte MIN(byte a, byte b) {
3142         return (byte)(Math.min(a, b));
3143     }
3144 
3145     @Test(dataProvider = "byteBinaryOpProvider")
3146     static void MINByte512VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3147         byte[] a = fa.apply(SPECIES.length());
3148         byte[] b = fb.apply(SPECIES.length());
3149         byte[] r = fr.apply(SPECIES.length());
3150 
3151         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3152             for (int i = 0; i < a.length; i += SPECIES.length()) {
3153                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3154                 ByteVector bv = ByteVector.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 Byte512VectorTests extends AbstractVectorTest {
  60 
  61     static final VectorSpecies<Byte> SPECIES =
  62                 ByteVector.SPECIES_512;
  63 
  64     static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
  65 
  66     static ByteVector bcast_vec = ByteVector.broadcast(SPECIES, (byte)10);
  67 
  68 
  69     private static final byte CONST_SHIFT = Byte.SIZE / 2;
  70 
  71     static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
  72 
  73     static void assertArraysStrictlyEquals(byte[] r, byte[] 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         byte apply(byte a);
  83     }
  84 
  85     static void assertArraysEquals(byte[] r, byte[] a, FUnOp f) {
  86         int i = 0;
  87         try {

3017 
3018     @Test(dataProvider = "byteUnaryOpMaskProvider")
3019     static void ROLByte512VectorTestsScalarShiftMaskedConst(IntFunction<byte[]> fa,
3020                                           IntFunction<boolean[]> fm) {
3021         byte[] a = fa.apply(SPECIES.length());
3022         byte[] r = fr.apply(SPECIES.length());
3023         boolean[] mask = fm.apply(SPECIES.length());
3024         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3025 
3026         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3027             for (int i = 0; i < a.length; i += SPECIES.length()) {
3028                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3029                 av.lanewise(VectorOperators.ROL, CONST_SHIFT, vmask).intoArray(r, i);
3030             }
3031         }
3032 
3033         assertShiftConstEquals(r, a, mask, Byte512VectorTests::ROL_binary_const);
3034     }
3035 
3036 


3037     @Test(dataProvider = "byteUnaryOpProvider")
3038     static void MINByte512VectorTestsWithMemOp(IntFunction<byte[]> fa) {
3039         byte[] a = fa.apply(SPECIES.length());
3040         byte[] r = fr.apply(SPECIES.length());
3041 
3042         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3043             for (int i = 0; i < a.length; i += SPECIES.length()) {
3044                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3045                 av.lanewise(VectorOperators.MIN, bcast_vec).intoArray(r, i);
3046             }
3047         }
3048 
3049         assertArraysEquals(r, a, (byte)10, Byte512VectorTests::MIN);
3050     }
3051 


3052     @Test(dataProvider = "byteUnaryOpProvider")
3053     static void minByte512VectorTestsWithMemOp(IntFunction<byte[]> fa) {
3054         byte[] a = fa.apply(SPECIES.length());
3055         byte[] r = fr.apply(SPECIES.length());
3056 
3057         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3058             for (int i = 0; i < a.length; i += SPECIES.length()) {
3059                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3060                 av.min(bcast_vec).intoArray(r, i);
3061             }
3062         }
3063 
3064         assertArraysEquals(r, a, (byte)10, Byte512VectorTests::min);
3065     }
3066 


3067     @Test(dataProvider = "byteUnaryOpMaskProvider")
3068     static void MINByte512VectorTestsMaskedWithMemOp(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
3069         byte[] a = fa.apply(SPECIES.length());
3070         byte[] r = fr.apply(SPECIES.length());
3071         boolean[] mask = fm.apply(SPECIES.length());
3072         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3073 
3074         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3075             for (int i = 0; i < a.length; i += SPECIES.length()) {
3076                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3077                 av.lanewise(VectorOperators.MIN, bcast_vec, vmask).intoArray(r, i);
3078             }
3079         }
3080 
3081         assertArraysEquals(r, a, (byte)10, mask, Byte512VectorTests::MIN);
3082     }
3083 


3084     @Test(dataProvider = "byteUnaryOpProvider")
3085     static void MAXByte512VectorTestsWithMemOp(IntFunction<byte[]> fa) {
3086         byte[] a = fa.apply(SPECIES.length());
3087         byte[] r = fr.apply(SPECIES.length());
3088 
3089         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3090             for (int i = 0; i < a.length; i += SPECIES.length()) {
3091                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3092                 av.lanewise(VectorOperators.MAX, bcast_vec).intoArray(r, i);
3093             }
3094         }
3095 
3096         assertArraysEquals(r, a, (byte)10, Byte512VectorTests::MAX);
3097     }
3098 


3099     @Test(dataProvider = "byteUnaryOpProvider")
3100     static void maxByte512VectorTestsWithMemOp(IntFunction<byte[]> fa) {
3101         byte[] a = fa.apply(SPECIES.length());
3102         byte[] r = fr.apply(SPECIES.length());
3103 
3104         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3105             for (int i = 0; i < a.length; i += SPECIES.length()) {
3106                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3107                 av.max(bcast_vec).intoArray(r, i);
3108             }
3109         }
3110 
3111         assertArraysEquals(r, a, (byte)10, Byte512VectorTests::max);
3112     }
3113 


3114     @Test(dataProvider = "byteUnaryOpMaskProvider")
3115     static void MAXByte512VectorTestsMaskedWithMemOp(IntFunction<byte[]> fa, IntFunction<boolean[]> fm) {
3116         byte[] a = fa.apply(SPECIES.length());
3117         byte[] r = fr.apply(SPECIES.length());
3118         boolean[] mask = fm.apply(SPECIES.length());
3119         VectorMask<Byte> vmask = VectorMask.fromArray(SPECIES, mask, 0);
3120 
3121         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3122             for (int i = 0; i < a.length; i += SPECIES.length()) {
3123                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3124                 av.lanewise(VectorOperators.MAX, bcast_vec, vmask).intoArray(r, i);
3125             }
3126         }
3127 
3128         assertArraysEquals(r, a, (byte)10, mask, Byte512VectorTests::MAX);
3129     }
3130 
3131     static byte MIN(byte a, byte b) {
3132         return (byte)(Math.min(a, b));
3133     }
3134 
3135     @Test(dataProvider = "byteBinaryOpProvider")
3136     static void MINByte512VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
3137         byte[] a = fa.apply(SPECIES.length());
3138         byte[] b = fb.apply(SPECIES.length());
3139         byte[] r = fr.apply(SPECIES.length());
3140 
3141         for (int ic = 0; ic < INVOC_COUNT; ic++) {
3142             for (int i = 0; i < a.length; i += SPECIES.length()) {
3143                 ByteVector av = ByteVector.fromArray(SPECIES, a, i);
3144                 ByteVector bv = ByteVector.fromArray(SPECIES, b, i);
< prev index next >