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