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 */
45 import org.testng.annotations.DataProvider;
46 import org.testng.annotations.Test;
47
48 import java.lang.Integer;
49 import java.util.List;
50 import java.util.Arrays;
51 import java.util.function.BiFunction;
52 import java.util.function.IntFunction;
53 import java.util.Objects;
54 import java.util.stream.Collectors;
55 import java.util.stream.Stream;
56
57 @Test
58 public class Float512VectorTests extends AbstractVectorTest {
59
60 static final VectorSpecies<Float> SPECIES =
61 FloatVector.SPECIES_512;
62
63 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
64
65
66 // for floating point addition reduction ops that may introduce rounding errors
67 private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0;
68
69 // for floating point multiplication reduction ops that may introduce rounding errors
70 private static final float RELATIVE_ROUNDING_ERROR_FACTOR_MUL = (float)50.0;
71
72 static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
73
74 static void assertArraysStrictlyEquals(float[] r, float[] a) {
75 for (int i = 0; i < a.length; i++) {
76 int ir = Float.floatToRawIntBits(r[i]);
77 int ia = Float.floatToRawIntBits(a[i]);
78 if (ir != ia) {
79 Assert.fail(String.format("at index #%d, expected = %08X, actual = %08X", i, ia, ir));
80 }
81 }
82 }
83
84 interface FUnOp {
2090 assertBroadcastLongArraysEquals(r, a, b, Float512VectorTests::ADD);
2091 }
2092
2093 @Test(dataProvider = "floatBinaryOpMaskProvider")
2094 static void ADDFloat512VectorTestsBroadcastMaskedLongSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb,
2095 IntFunction<boolean[]> fm) {
2096 float[] a = fa.apply(SPECIES.length());
2097 float[] b = fb.apply(SPECIES.length());
2098 float[] r = fr.apply(SPECIES.length());
2099 boolean[] mask = fm.apply(SPECIES.length());
2100 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2101
2102 for (int i = 0; i < a.length; i += SPECIES.length()) {
2103 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2104 av.lanewise(VectorOperators.ADD, (long)b[i], vmask).intoArray(r, i);
2105 }
2106
2107 assertBroadcastLongArraysEquals(r, a, b, mask, Float512VectorTests::ADD);
2108 }
2109
2110 static FloatVector bv_MIN = FloatVector.broadcast(SPECIES, (float)10);
2111
2112 @Test(dataProvider = "floatUnaryOpProvider")
2113 static void MINFloat512VectorTestsWithMemOp(IntFunction<float[]> fa) {
2114 float[] a = fa.apply(SPECIES.length());
2115 float[] r = fr.apply(SPECIES.length());
2116
2117 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2118 for (int i = 0; i < a.length; i += SPECIES.length()) {
2119 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2120 av.lanewise(VectorOperators.MIN, bv_MIN).intoArray(r, i);
2121 }
2122 }
2123
2124 assertArraysEquals(r, a, (float)10, Float512VectorTests::MIN);
2125 }
2126
2127 static FloatVector bv_min = FloatVector.broadcast(SPECIES, (float)10);
2128
2129 @Test(dataProvider = "floatUnaryOpProvider")
2130 static void minFloat512VectorTestsWithMemOp(IntFunction<float[]> fa) {
2131 float[] a = fa.apply(SPECIES.length());
2132 float[] r = fr.apply(SPECIES.length());
2133
2134 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2135 for (int i = 0; i < a.length; i += SPECIES.length()) {
2136 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2137 av.min(bv_min).intoArray(r, i);
2138 }
2139 }
2140
2141 assertArraysEquals(r, a, (float)10, Float512VectorTests::min);
2142 }
2143
2144 static FloatVector bv_MIN_M = FloatVector.broadcast(SPECIES, (float)10);
2145
2146 @Test(dataProvider = "floatUnaryOpMaskProvider")
2147 static void MINFloat512VectorTestsMaskedWithMemOp(IntFunction<float[]> fa, IntFunction<boolean[]> fm) {
2148 float[] a = fa.apply(SPECIES.length());
2149 float[] r = fr.apply(SPECIES.length());
2150 boolean[] mask = fm.apply(SPECIES.length());
2151 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2152
2153 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2154 for (int i = 0; i < a.length; i += SPECIES.length()) {
2155 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2156 av.lanewise(VectorOperators.MIN, bv_MIN_M, vmask).intoArray(r, i);
2157 }
2158 }
2159
2160 assertArraysEquals(r, a, (float)10, mask, Float512VectorTests::MIN);
2161 }
2162
2163 static FloatVector bv_MAX = FloatVector.broadcast(SPECIES, (float)10);
2164
2165 @Test(dataProvider = "floatUnaryOpProvider")
2166 static void MAXFloat512VectorTestsWithMemOp(IntFunction<float[]> fa) {
2167 float[] a = fa.apply(SPECIES.length());
2168 float[] r = fr.apply(SPECIES.length());
2169
2170 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2171 for (int i = 0; i < a.length; i += SPECIES.length()) {
2172 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2173 av.lanewise(VectorOperators.MAX, bv_MAX).intoArray(r, i);
2174 }
2175 }
2176
2177 assertArraysEquals(r, a, (float)10, Float512VectorTests::MAX);
2178 }
2179
2180 static FloatVector bv_max = FloatVector.broadcast(SPECIES, (float)10);
2181
2182 @Test(dataProvider = "floatUnaryOpProvider")
2183 static void maxFloat512VectorTestsWithMemOp(IntFunction<float[]> fa) {
2184 float[] a = fa.apply(SPECIES.length());
2185 float[] r = fr.apply(SPECIES.length());
2186
2187 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2188 for (int i = 0; i < a.length; i += SPECIES.length()) {
2189 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2190 av.max(bv_max).intoArray(r, i);
2191 }
2192 }
2193
2194 assertArraysEquals(r, a, (float)10, Float512VectorTests::max);
2195 }
2196
2197 static FloatVector bv_MAX_M = FloatVector.broadcast(SPECIES, (float)10);
2198
2199 @Test(dataProvider = "floatUnaryOpMaskProvider")
2200 static void MAXFloat512VectorTestsMaskedWithMemOp(IntFunction<float[]> fa, IntFunction<boolean[]> fm) {
2201 float[] a = fa.apply(SPECIES.length());
2202 float[] r = fr.apply(SPECIES.length());
2203 boolean[] mask = fm.apply(SPECIES.length());
2204 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2205
2206 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2207 for (int i = 0; i < a.length; i += SPECIES.length()) {
2208 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2209 av.lanewise(VectorOperators.MAX, bv_MAX_M, vmask).intoArray(r, i);
2210 }
2211 }
2212
2213 assertArraysEquals(r, a, (float)10, mask, Float512VectorTests::MAX);
2214 }
2215
2216 static float MIN(float a, float b) {
2217 return (float)(Math.min(a, b));
2218 }
2219
2220 @Test(dataProvider = "floatBinaryOpProvider")
2221 static void MINFloat512VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
2222 float[] a = fa.apply(SPECIES.length());
2223 float[] b = fb.apply(SPECIES.length());
2224 float[] r = fr.apply(SPECIES.length());
2225
2226 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2227 for (int i = 0; i < a.length; i += SPECIES.length()) {
2228 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2229 FloatVector bv = FloatVector.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 */
45 import org.testng.annotations.DataProvider;
46 import org.testng.annotations.Test;
47
48 import java.lang.Integer;
49 import java.util.List;
50 import java.util.Arrays;
51 import java.util.function.BiFunction;
52 import java.util.function.IntFunction;
53 import java.util.Objects;
54 import java.util.stream.Collectors;
55 import java.util.stream.Stream;
56
57 @Test
58 public class Float512VectorTests extends AbstractVectorTest {
59
60 static final VectorSpecies<Float> SPECIES =
61 FloatVector.SPECIES_512;
62
63 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 100);
64
65 static FloatVector bcast_vec = FloatVector.broadcast(SPECIES, (float)10);
66
67
68 // for floating point addition reduction ops that may introduce rounding errors
69 private static final float RELATIVE_ROUNDING_ERROR_FACTOR_ADD = (float)10.0;
70
71 // for floating point multiplication reduction ops that may introduce rounding errors
72 private static final float RELATIVE_ROUNDING_ERROR_FACTOR_MUL = (float)50.0;
73
74 static final int BUFFER_REPS = Integer.getInteger("jdk.incubator.vector.test.buffer-vectors", 25000 / 512);
75
76 static void assertArraysStrictlyEquals(float[] r, float[] a) {
77 for (int i = 0; i < a.length; i++) {
78 int ir = Float.floatToRawIntBits(r[i]);
79 int ia = Float.floatToRawIntBits(a[i]);
80 if (ir != ia) {
81 Assert.fail(String.format("at index #%d, expected = %08X, actual = %08X", i, ia, ir));
82 }
83 }
84 }
85
86 interface FUnOp {
2092 assertBroadcastLongArraysEquals(r, a, b, Float512VectorTests::ADD);
2093 }
2094
2095 @Test(dataProvider = "floatBinaryOpMaskProvider")
2096 static void ADDFloat512VectorTestsBroadcastMaskedLongSmokeTest(IntFunction<float[]> fa, IntFunction<float[]> fb,
2097 IntFunction<boolean[]> fm) {
2098 float[] a = fa.apply(SPECIES.length());
2099 float[] b = fb.apply(SPECIES.length());
2100 float[] r = fr.apply(SPECIES.length());
2101 boolean[] mask = fm.apply(SPECIES.length());
2102 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2103
2104 for (int i = 0; i < a.length; i += SPECIES.length()) {
2105 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2106 av.lanewise(VectorOperators.ADD, (long)b[i], vmask).intoArray(r, i);
2107 }
2108
2109 assertBroadcastLongArraysEquals(r, a, b, mask, Float512VectorTests::ADD);
2110 }
2111
2112 @Test(dataProvider = "floatUnaryOpProvider")
2113 static void MINFloat512VectorTestsWithMemOp(IntFunction<float[]> fa) {
2114 float[] a = fa.apply(SPECIES.length());
2115 float[] r = fr.apply(SPECIES.length());
2116
2117 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2118 for (int i = 0; i < a.length; i += SPECIES.length()) {
2119 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2120 av.lanewise(VectorOperators.MIN, bcast_vec).intoArray(r, i);
2121 }
2122 }
2123
2124 assertArraysEquals(r, a, (float)10, Float512VectorTests::MIN);
2125 }
2126
2127 @Test(dataProvider = "floatUnaryOpProvider")
2128 static void minFloat512VectorTestsWithMemOp(IntFunction<float[]> fa) {
2129 float[] a = fa.apply(SPECIES.length());
2130 float[] r = fr.apply(SPECIES.length());
2131
2132 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2133 for (int i = 0; i < a.length; i += SPECIES.length()) {
2134 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2135 av.min(bcast_vec).intoArray(r, i);
2136 }
2137 }
2138
2139 assertArraysEquals(r, a, (float)10, Float512VectorTests::min);
2140 }
2141
2142 @Test(dataProvider = "floatUnaryOpMaskProvider")
2143 static void MINFloat512VectorTestsMaskedWithMemOp(IntFunction<float[]> fa, IntFunction<boolean[]> fm) {
2144 float[] a = fa.apply(SPECIES.length());
2145 float[] r = fr.apply(SPECIES.length());
2146 boolean[] mask = fm.apply(SPECIES.length());
2147 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2148
2149 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2150 for (int i = 0; i < a.length; i += SPECIES.length()) {
2151 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2152 av.lanewise(VectorOperators.MIN, bcast_vec, vmask).intoArray(r, i);
2153 }
2154 }
2155
2156 assertArraysEquals(r, a, (float)10, mask, Float512VectorTests::MIN);
2157 }
2158
2159 @Test(dataProvider = "floatUnaryOpProvider")
2160 static void MAXFloat512VectorTestsWithMemOp(IntFunction<float[]> fa) {
2161 float[] a = fa.apply(SPECIES.length());
2162 float[] r = fr.apply(SPECIES.length());
2163
2164 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2165 for (int i = 0; i < a.length; i += SPECIES.length()) {
2166 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2167 av.lanewise(VectorOperators.MAX, bcast_vec).intoArray(r, i);
2168 }
2169 }
2170
2171 assertArraysEquals(r, a, (float)10, Float512VectorTests::MAX);
2172 }
2173
2174 @Test(dataProvider = "floatUnaryOpProvider")
2175 static void maxFloat512VectorTestsWithMemOp(IntFunction<float[]> fa) {
2176 float[] a = fa.apply(SPECIES.length());
2177 float[] r = fr.apply(SPECIES.length());
2178
2179 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2180 for (int i = 0; i < a.length; i += SPECIES.length()) {
2181 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2182 av.max(bcast_vec).intoArray(r, i);
2183 }
2184 }
2185
2186 assertArraysEquals(r, a, (float)10, Float512VectorTests::max);
2187 }
2188
2189 @Test(dataProvider = "floatUnaryOpMaskProvider")
2190 static void MAXFloat512VectorTestsMaskedWithMemOp(IntFunction<float[]> fa, IntFunction<boolean[]> fm) {
2191 float[] a = fa.apply(SPECIES.length());
2192 float[] r = fr.apply(SPECIES.length());
2193 boolean[] mask = fm.apply(SPECIES.length());
2194 VectorMask<Float> vmask = VectorMask.fromArray(SPECIES, mask, 0);
2195
2196 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2197 for (int i = 0; i < a.length; i += SPECIES.length()) {
2198 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2199 av.lanewise(VectorOperators.MAX, bcast_vec, vmask).intoArray(r, i);
2200 }
2201 }
2202
2203 assertArraysEquals(r, a, (float)10, mask, Float512VectorTests::MAX);
2204 }
2205
2206 static float MIN(float a, float b) {
2207 return (float)(Math.min(a, b));
2208 }
2209
2210 @Test(dataProvider = "floatBinaryOpProvider")
2211 static void MINFloat512VectorTests(IntFunction<float[]> fa, IntFunction<float[]> fb) {
2212 float[] a = fa.apply(SPECIES.length());
2213 float[] b = fb.apply(SPECIES.length());
2214 float[] r = fr.apply(SPECIES.length());
2215
2216 for (int ic = 0; ic < INVOC_COUNT; ic++) {
2217 for (int i = 0; i < a.length; i += SPECIES.length()) {
2218 FloatVector av = FloatVector.fromArray(SPECIES, a, i);
2219 FloatVector bv = FloatVector.fromArray(SPECIES, b, i);
|