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
21 * questions.
22 */
23
24 /*
25 * @test
26 * @modules jdk.incubator.vector
27 #if[MaxBit]
28 * @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
29 * $vectorteststype$
30 #else[MaxBit]
31 * @run testng $vectorteststype$
32 #end[MaxBit]
33 *
34 */
35
36 import jdk.incubator.vector.Vector.Shape;
37 import jdk.incubator.vector.Vector.Species;
38 import jdk.incubator.vector.Vector;
39
40 import jdk.incubator.vector.$Type$Vector;
41
42 import org.testng.Assert;
43 import org.testng.annotations.DataProvider;
44 import org.testng.annotations.Test;
45
46 #if[MaxBit]
47 import java.lang.invoke.MethodHandles;
48 import java.lang.invoke.VarHandle;
49 #end[MaxBit]
50 import java.nio.ByteBuffer;
51 #if[!byte]
52 import java.nio.$Type$Buffer;
53 #end[!byte]
54 import java.nio.ByteOrder;
55 import java.util.List;
56 import java.util.function.IntFunction;
57
58 @Test
59 public class $vectorteststype$ extends AbstractVectorTest {
60 #if[MaxBit]
61 static final Species<$Wideboxtype$> SPECIES =
62 $Type$Vector.SPECIES_MAX;
63 #else[MaxBit]
64 static final Species<$Wideboxtype$> SPECIES =
65 $Type$Vector.SPECIES_$bits$;
66 #end[MaxBit]
67
68 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10);
69
70 #if[MaxBit]
71 static Shape getMaxBit() {
72 return Shape.S_Max_BIT;
73 }
74
75 #end[MaxBit]
76 static void assertArraysEquals($type$[] a, $type$[] r, boolean[] mask) {
77 int i = 0;
78 try {
79 for (; i < a.length; i++) {
80 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : ($type$) 0, r[i]);
81 }
82 } catch (AssertionError e) {
83 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : ($type$) 0, r[i], "at index #" + i);
84 }
85 }
86
87 static void assertArraysEquals($type$[] a, $type$[] r, int[] im) {
88 int i = 0;
89 try {
90 for (; i < a.length; i++) {
91 Assert.assertEquals(a[im[i]], r[i]);
92 }
204 @Test(dataProvider = "$type$Provider")
205 static void loadStoreArray(IntFunction<$type$[]> fa) {
206 $type$[] a = fa.apply(SPECIES.length());
207 $type$[] r = new $type$[a.length];
208
209 for (int ic = 0; ic < INVOC_COUNT; ic++) {
210 for (int i = 0; i < a.length; i += SPECIES.length()) {
211 $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i);
212 av.intoArray(r, i);
213 }
214 }
215 Assert.assertEquals(a, r);
216 }
217
218 @Test(dataProvider = "$type$MaskProvider")
219 static void loadStoreMaskArray(IntFunction<$type$[]> fa,
220 IntFunction<boolean[]> fm) {
221 $type$[] a = fa.apply(SPECIES.length());
222 $type$[] r = new $type$[a.length];
223 boolean[] mask = fm.apply(SPECIES.length());
224 Vector.Mask<$Boxtype$> vmask = $abstractvectortype$.maskFromValues(SPECIES, mask);
225
226 for (int ic = 0; ic < INVOC_COUNT; ic++) {
227 for (int i = 0; i < a.length; i += SPECIES.length()) {
228 $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i, vmask);
229 av.intoArray(r, i);
230 }
231 }
232 assertArraysEquals(a, r, mask);
233
234 r = new $type$[a.length];
235 for (int ic = 0; ic < INVOC_COUNT; ic++) {
236 for (int i = 0; i < a.length; i += SPECIES.length()) {
237 $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i);
238 av.intoArray(r, i, vmask);
239 }
240 }
241
242 assertArraysEquals(a, r, mask);
243 }
244
278 for (int ic = 0; ic < INVOC_COUNT; ic++) {
279 for (int i = 0; i < l; i += s) {
280 $abstractvectortype$ av = $abstractvectortype$.fromByteBuffer(SPECIES, a, i);
281 av.intoByteBuffer(r, i);
282 }
283 }
284 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
285 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
286 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
287 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
288 Assert.assertEquals(a, r, "Buffers not equal");
289 }
290
291 @Test(dataProvider = "$type$ByteBufferMaskProvider")
292 static void loadStoreByteBufferMask(IntFunction<$type$[]> fa,
293 IntFunction<ByteBuffer> fb,
294 IntFunction<boolean[]> fm) {
295 ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
296 ByteBuffer r = fb.apply(a.limit());
297 boolean[] mask = fm.apply(SPECIES.length());
298 Vector.Mask<$Boxtype$> vmask = $abstractvectortype$.maskFromValues(SPECIES, mask);
299
300 int l = a.limit();
301 int s = SPECIES.length() * SPECIES.elementSize() / 8;
302
303 for (int ic = 0; ic < INVOC_COUNT; ic++) {
304 for (int i = 0; i < l; i += s) {
305 $abstractvectortype$ av = $abstractvectortype$.fromByteBuffer(SPECIES, a, i, vmask);
306 av.intoByteBuffer(r, i);
307 }
308 }
309 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
310 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
311 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
312 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
313 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
314
315 a = toBuffer(fa.apply(SPECIES.length()), fb);
316 r = fb.apply(a.limit());
317 for (int ic = 0; ic < INVOC_COUNT; ic++) {
318 for (int i = 0; i < l; i += s) {
319 $abstractvectortype$ av = $abstractvectortype$.fromByteBuffer(SPECIES, a, i);
320 av.intoByteBuffer(r, i, vmask);
321 }
322 }
323 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
324 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
325 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
326 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
327 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
328 }
329
330 @Test(dataProvider = "$type$ByteBufferMaskProvider")
331 static void loadReadOnlyStoreByteBufferMask(IntFunction<$type$[]> fa,
332 IntFunction<ByteBuffer> fb,
333 IntFunction<boolean[]> fm) {
334 ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
335 a = a.asReadOnlyBuffer().order(a.order());
336 ByteBuffer r = fb.apply(a.limit());
337 boolean[] mask = fm.apply(SPECIES.length());
338 Vector.Mask<$Boxtype$> vmask = $abstractvectortype$.maskFromValues(SPECIES, mask);
339
340 int l = a.limit();
341 int s = SPECIES.length() * SPECIES.elementSize() / 8;
342
343 for (int ic = 0; ic < INVOC_COUNT; ic++) {
344 for (int i = 0; i < l; i += s) {
345 $abstractvectortype$ av = $abstractvectortype$.fromByteBuffer(SPECIES, a, i, vmask);
346 av.intoByteBuffer(r, i);
347 }
348 }
349 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
350 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
351 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
352 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
353 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
354 }
355 }
|
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
21 * questions.
22 */
23
24 /*
25 * @test
26 * @modules jdk.incubator.vector
27 #if[MaxBit]
28 * @run testng/othervm --add-opens jdk.incubator.vector/jdk.incubator.vector=ALL-UNNAMED
29 * $vectorteststype$
30 #else[MaxBit]
31 * @run testng $vectorteststype$
32 #end[MaxBit]
33 *
34 */
35
36 import jdk.incubator.vector.VectorShape;
37 import jdk.incubator.vector.VectorSpecies;
38 import jdk.incubator.vector.VectorMask;
39 import jdk.incubator.vector.Vector;
40
41 import jdk.incubator.vector.$Type$Vector;
42
43 import org.testng.Assert;
44 import org.testng.annotations.DataProvider;
45 import org.testng.annotations.Test;
46
47 #if[MaxBit]
48 import java.lang.invoke.MethodHandles;
49 import java.lang.invoke.VarHandle;
50 #end[MaxBit]
51 import java.nio.ByteBuffer;
52 #if[!byte]
53 import java.nio.$Type$Buffer;
54 #end[!byte]
55 import java.nio.ByteOrder;
56 import java.util.List;
57 import java.util.function.IntFunction;
58
59 @Test
60 public class $vectorteststype$ extends AbstractVectorTest {
61 #if[MaxBit]
62 static final VectorSpecies<$Wideboxtype$> SPECIES =
63 $Type$Vector.SPECIES_MAX;
64 #else[MaxBit]
65 static final VectorSpecies<$Wideboxtype$> SPECIES =
66 $Type$Vector.SPECIES_$bits$;
67 #end[MaxBit]
68
69 static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 10);
70
71 #if[MaxBit]
72 static VectorShape getMaxBit() {
73 return VectorShape.S_Max_BIT;
74 }
75
76 #end[MaxBit]
77 static void assertArraysEquals($type$[] a, $type$[] r, boolean[] mask) {
78 int i = 0;
79 try {
80 for (; i < a.length; i++) {
81 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : ($type$) 0, r[i]);
82 }
83 } catch (AssertionError e) {
84 Assert.assertEquals(mask[i % SPECIES.length()] ? a[i] : ($type$) 0, r[i], "at index #" + i);
85 }
86 }
87
88 static void assertArraysEquals($type$[] a, $type$[] r, int[] im) {
89 int i = 0;
90 try {
91 for (; i < a.length; i++) {
92 Assert.assertEquals(a[im[i]], r[i]);
93 }
205 @Test(dataProvider = "$type$Provider")
206 static void loadStoreArray(IntFunction<$type$[]> fa) {
207 $type$[] a = fa.apply(SPECIES.length());
208 $type$[] r = new $type$[a.length];
209
210 for (int ic = 0; ic < INVOC_COUNT; ic++) {
211 for (int i = 0; i < a.length; i += SPECIES.length()) {
212 $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i);
213 av.intoArray(r, i);
214 }
215 }
216 Assert.assertEquals(a, r);
217 }
218
219 @Test(dataProvider = "$type$MaskProvider")
220 static void loadStoreMaskArray(IntFunction<$type$[]> fa,
221 IntFunction<boolean[]> fm) {
222 $type$[] a = fa.apply(SPECIES.length());
223 $type$[] r = new $type$[a.length];
224 boolean[] mask = fm.apply(SPECIES.length());
225 VectorMask<$Boxtype$> vmask = VectorMask.fromValues(SPECIES, mask);
226
227 for (int ic = 0; ic < INVOC_COUNT; ic++) {
228 for (int i = 0; i < a.length; i += SPECIES.length()) {
229 $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i, vmask);
230 av.intoArray(r, i);
231 }
232 }
233 assertArraysEquals(a, r, mask);
234
235 r = new $type$[a.length];
236 for (int ic = 0; ic < INVOC_COUNT; ic++) {
237 for (int i = 0; i < a.length; i += SPECIES.length()) {
238 $abstractvectortype$ av = $abstractvectortype$.fromArray(SPECIES, a, i);
239 av.intoArray(r, i, vmask);
240 }
241 }
242
243 assertArraysEquals(a, r, mask);
244 }
245
279 for (int ic = 0; ic < INVOC_COUNT; ic++) {
280 for (int i = 0; i < l; i += s) {
281 $abstractvectortype$ av = $abstractvectortype$.fromByteBuffer(SPECIES, a, i);
282 av.intoByteBuffer(r, i);
283 }
284 }
285 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
286 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
287 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
288 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
289 Assert.assertEquals(a, r, "Buffers not equal");
290 }
291
292 @Test(dataProvider = "$type$ByteBufferMaskProvider")
293 static void loadStoreByteBufferMask(IntFunction<$type$[]> fa,
294 IntFunction<ByteBuffer> fb,
295 IntFunction<boolean[]> fm) {
296 ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
297 ByteBuffer r = fb.apply(a.limit());
298 boolean[] mask = fm.apply(SPECIES.length());
299 VectorMask<$Boxtype$> vmask = VectorMask.fromValues(SPECIES, mask);
300
301 int l = a.limit();
302 int s = SPECIES.length() * SPECIES.elementSize() / 8;
303
304 for (int ic = 0; ic < INVOC_COUNT; ic++) {
305 for (int i = 0; i < l; i += s) {
306 $abstractvectortype$ av = $abstractvectortype$.fromByteBuffer(SPECIES, a, i, vmask);
307 av.intoByteBuffer(r, i);
308 }
309 }
310 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
311 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
312 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
313 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
314 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
315
316 a = toBuffer(fa.apply(SPECIES.length()), fb);
317 r = fb.apply(a.limit());
318 for (int ic = 0; ic < INVOC_COUNT; ic++) {
319 for (int i = 0; i < l; i += s) {
320 $abstractvectortype$ av = $abstractvectortype$.fromByteBuffer(SPECIES, a, i);
321 av.intoByteBuffer(r, i, vmask);
322 }
323 }
324 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
325 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
326 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
327 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
328 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
329 }
330
331 @Test(dataProvider = "$type$ByteBufferMaskProvider")
332 static void loadReadOnlyStoreByteBufferMask(IntFunction<$type$[]> fa,
333 IntFunction<ByteBuffer> fb,
334 IntFunction<boolean[]> fm) {
335 ByteBuffer a = toBuffer(fa.apply(SPECIES.length()), fb);
336 a = a.asReadOnlyBuffer().order(a.order());
337 ByteBuffer r = fb.apply(a.limit());
338 boolean[] mask = fm.apply(SPECIES.length());
339 VectorMask<$Boxtype$> vmask = VectorMask.fromValues(SPECIES, mask);
340
341 int l = a.limit();
342 int s = SPECIES.length() * SPECIES.elementSize() / 8;
343
344 for (int ic = 0; ic < INVOC_COUNT; ic++) {
345 for (int i = 0; i < l; i += s) {
346 $abstractvectortype$ av = $abstractvectortype$.fromByteBuffer(SPECIES, a, i, vmask);
347 av.intoByteBuffer(r, i);
348 }
349 }
350 Assert.assertEquals(a.position(), 0, "Input buffer position changed");
351 Assert.assertEquals(a.limit(), l, "Input buffer limit changed");
352 Assert.assertEquals(r.position(), 0, "Result buffer position changed");
353 Assert.assertEquals(r.limit(), l, "Result buffer limit changed");
354 assertArraysEquals(bufferToArray(a), bufferToArray(r), mask);
355 }
356 }
|