1 /*
2  * Copyright (c) 2014, 2016, 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 /**
25  * @test
26  * @bug 8031321
27  * @summary Verify that results of computations are the same w/
28  *          and w/o usage of ANDN instruction
29  * @library /test/lib /
30  * @modules java.base/jdk.internal.misc
31  *          java.management
32  * @build sun.hotspot.WhiteBox
33  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
34  *                              sun.hotspot.WhiteBox$WhiteBoxPermission
35  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
36  *                   -XX:+WhiteBoxAPI compiler.intrinsics.bmi.TestAndnI
37  */
38 
39 package compiler.intrinsics.bmi;
40 
41 import sun.hotspot.cpuinfo.CPUInfo;
42 
43 public class TestAndnI {
44 
main(String args[])45     public static void main(String args[]) throws Throwable {
46         if (!CPUInfo.hasFeature("bmi1")) {
47             System.out.println("INFO: CPU does not support bmi1 feature.");
48         }
49 
50         BMITestRunner.runTests(AndnIExpr.class, args,
51                                "-XX:+IgnoreUnrecognizedVMOptions",
52                                "-XX:+UseBMI1Instructions");
53         BMITestRunner.runTests(AndnICommutativeExpr.class, args,
54                                "-XX:+IgnoreUnrecognizedVMOptions",
55                                "-XX:+UseBMI1Instructions");
56     }
57 
58     public static class AndnIExpr extends Expr.BMIBinaryIntExpr {
59 
intExpr(int src1, int src2)60         public int intExpr(int src1, int src2) {
61             return ~src1 & src2;
62         }
63 
intExpr(int src1, Expr.MemI src2)64         public int intExpr(int src1, Expr.MemI src2) {
65             if (src2 != null) {
66                 return ~src1 & src2.value;
67             } else {
68                 return 0;
69             }
70         }
71 
intExpr(Expr.MemI src1, int src2)72         public int intExpr(Expr.MemI src1, int src2) {
73             if (src1 != null) {
74                 return ~src1.value & src2;
75             } else {
76                 return 0;
77             }
78         }
79 
intExpr(Expr.MemI src1, Expr.MemI src2)80         public int intExpr(Expr.MemI src1, Expr.MemI src2) {
81             if (src1 != null && src2 != null) {
82                 return ~src1.value & src2.value;
83             } else {
84                 return 0;
85             }
86         }
87     }
88 
89     public static class AndnICommutativeExpr extends Expr.BMIBinaryIntExpr {
90 
intExpr(int src1, int src2)91         public int intExpr(int src1, int src2) {
92             return src1 & ~src2;
93         }
94 
intExpr(int src1, Expr.MemI src2)95         public int intExpr(int src1, Expr.MemI src2) {
96             if (src2 != null) {
97                 return src1 & ~src2.value;
98             } else {
99                 return 0;
100             }
101         }
102 
intExpr(Expr.MemI src1, int src2)103         public int intExpr(Expr.MemI src1, int src2) {
104             if (src1 != null) {
105                 return src1.value & ~src2;
106             } else {
107                 return 0;
108             }
109         }
110 
intExpr(Expr.MemI src1, Expr.MemI src2)111         public int intExpr(Expr.MemI src1, Expr.MemI src2) {
112             if (src1 != null && src2 != null) {
113                 return src1.value & ~src2.value;
114             } else {
115                 return 0;
116             }
117         }
118     }
119 }
120