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