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