1 /*
 2  * Copyright (c) 2021, 2022, 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  */
23 
24 package compiler.vectorapi.reshape;
25 
26 import compiler.vectorapi.reshape.tests.TestVectorDoubleExpandShrink;
27 import compiler.vectorapi.reshape.tests.TestVectorExpandShrink;
28 import compiler.vectorapi.reshape.tests.TestVectorRebracket;
29 import compiler.vectorapi.reshape.utils.VectorReshapeHelper;
30 import compiler.vectorapi.reshape.utils.VectorSpeciesPair;
31 import java.util.List;
32 import jdk.incubator.vector.VectorShape;
33 import jdk.incubator.vector.VectorSpecies;
34 
35 /*
36  * @test
37  * @bug 8259610
38  * @key randomness
39  * @modules jdk.incubator.vector
40  * @modules java.base/jdk.internal.misc
41  * @summary Test that vector reinterpret intrinsics work as intended.
42  * @library /test/lib /
43  * @run main compiler.vectorapi.reshape.TestVectorReinterpret
44  */
45 public class TestVectorReinterpret {
46     private static final List<VectorShape> SHAPE_LIST = List.of(VectorShape.values());
47     private static final List<Class<?>> ETYPE_LIST = List.of(
48             byte.class, short.class, int.class, long.class, float.class, double.class
49     );
50 
51     public static void main(String[] args) {
52         VectorReshapeHelper.runMainHelper(
53                 TestVectorExpandShrink.class,
54                 SHAPE_LIST.stream()
55                         .flatMap(s -> SHAPE_LIST.stream()
56                                 .filter(t -> t.vectorBitSize() != s.vectorBitSize())
57                                 .map(t -> VectorSpeciesPair.makePair(VectorSpecies.of(byte.class, s),
58                                         VectorSpecies.of(byte.class, t))))
59         );
60 
61         VectorReshapeHelper.runMainHelper(
62                 TestVectorDoubleExpandShrink.class,
63                 SHAPE_LIST.stream()
64                         .flatMap(s -> SHAPE_LIST.stream()
65                                 .filter(t -> t.vectorBitSize() != s.vectorBitSize())
66                                 .map(t -> VectorSpeciesPair.makePair(VectorSpecies.of(byte.class, s),
67                                         VectorSpecies.of(byte.class, t))))
68         );
69 
70         VectorReshapeHelper.runMainHelper(
71                 TestVectorRebracket.class,
72                 SHAPE_LIST.stream()
73                         .flatMap(shape -> ETYPE_LIST.stream()
74                                 .flatMap(etype -> ETYPE_LIST.stream()
75                                         .filter(ftype -> ftype != etype)
76                                         .map(ftype -> VectorSpeciesPair.makePair(VectorSpecies.of(etype, shape),
77                                                 VectorSpecies.of(ftype, shape)))))
78                         .filter(p -> p.isp().length() > 1 && p.osp().length() > 1)
79         );
80     }
81 }