BC_ifeq.java revision 12651:6ef01bd40ce2
1295367Sdes/*
298937Sdes * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
398937Sdes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
498937Sdes *
598937Sdes * This code is free software; you can redistribute it and/or modify it
6295367Sdes * under the terms of the GNU General Public License version 2 only, as
7157016Sdes * published by the Free Software Foundation.
898937Sdes *
998937Sdes * This code is distributed in the hope that it will be useful, but WITHOUT
1098937Sdes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1198937Sdes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1298937Sdes * version 2 for more details (a copy is included in the LICENSE file that
1398937Sdes * accompanied this code).
1498937Sdes *
1598937Sdes * 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 */
23package org.graalvm.compiler.jtt.bytecode;
24
25import org.junit.Test;
26
27import org.graalvm.compiler.jtt.JTTTest;
28
29/*
30 */
31public class BC_ifeq extends JTTTest {
32
33    public static int test(int a) {
34        int n = 0;
35        if (a == 0) {
36            n += 1;
37        } else {
38            n -= 1;
39        }
40        if (a != 0) {
41            n -= 1;
42        } else {
43            n += 1;
44        }
45        return n;
46    }
47
48    @Test
49    public void run0() throws Throwable {
50        runTest("test", 0);
51    }
52
53    @Test
54    public void run1() throws Throwable {
55        runTest("test", 1);
56    }
57
58    @Test
59    public void run3() {
60        runTest("testb", 0xff);
61    }
62
63    /**
64     * Tests if the if does work properly on byte stamp.
65     */
66    public static int testb(int b) {
67        byte x = (byte) b;
68        int y = x & 0xff;
69        if (y == 0xff) {
70            // Just do anything else to force jump instead of conditional move
71            y = (int) (System.currentTimeMillis() >> 32);
72        }
73        return y;
74    }
75
76    @Test
77    public void run4() {
78        runTest("tests", 0xffff);
79    }
80
81    /**
82     * Tests if the if does work properly on short stamp.
83     */
84    public static int tests(int b) {
85        short x = (short) b;
86        int y = x & 0xffff;
87        if (y == 0xffff) {
88            // Just do anything else to force jump instead of conditional move
89            y = (int) (System.currentTimeMillis() >> 32);
90        }
91        return y;
92    }
93
94    @Test
95    public void run5() {
96        runTest("testc", 0xffff);
97    }
98
99    /**
100     * Tests if the if does work properly on char stamp (boils down to short, just to cover all the
101     * java types).
102     */
103    public static int testc(int b) {
104        char x = (char) b;
105        int y = x & 0xffff;
106        if (y == 0xffff) {
107            // Just do anything else to force jump instead of conditional move
108            y = (int) (System.currentTimeMillis() >> 32);
109        }
110        return y;
111    }
112
113    // the same with conditional move
114    @Test
115    public void run6() {
116        runTest("testCondb", 0xff);
117    }
118
119    /**
120     * Tests if the if does work properly on byte stamp.
121     */
122    public static boolean testCondb(int b) {
123        byte x = (byte) b;
124        int y = x & 0xff;
125        return y == 0xff;
126    }
127
128    @Test
129    public void run7() {
130        runTest("testConds", 0xffff);
131    }
132
133    /**
134     * Tests if the if does work properly on short stamp.
135     */
136    public static boolean testConds(int b) {
137        short x = (short) b;
138        int y = x & 0xffff;
139        return y == 0xffff;
140    }
141
142    @Test
143    public void run8() {
144        runTest("testCondc", 0xffff);
145    }
146
147    /**
148     * Tests if the if does work properly on char type.
149     */
150    public static boolean testCondc(int b) {
151        char x = (char) b;
152        int y = x & 0xffff;
153        return y == 0xffff;
154    }
155}
156