001/*
002 * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.jtt.bytecode;
024
025import org.junit.*;
026
027import com.oracle.graal.jtt.*;
028
029/*
030 */
031public class BC_ifeq extends JTTTest {
032
033    public static int test(int a) {
034        int n = 0;
035        if (a == 0) {
036            n += 1;
037        } else {
038            n -= 1;
039        }
040        if (a != 0) {
041            n -= 1;
042        } else {
043            n += 1;
044        }
045        return n;
046    }
047
048    @Test
049    public void run0() throws Throwable {
050        runTest("test", 0);
051    }
052
053    @Test
054    public void run1() throws Throwable {
055        runTest("test", 1);
056    }
057
058    @Test
059    public void run3() {
060        runTest("testb", 0xff);
061    }
062
063    /**
064     * Tests if the if does work properly on byte stamp.
065     */
066    public static int testb(int b) {
067        byte x = (byte) b;
068        int y = x & 0xff;
069        if (y == 0xff) {
070            // Just do anything else to force jump instead of conditional move
071            y = (int) (System.currentTimeMillis() >> 32);
072        }
073        return y;
074    }
075
076    @Test
077    public void run4() {
078        runTest("tests", 0xffff);
079    }
080
081    /**
082     * Tests if the if does work properly on short stamp.
083     */
084    public static int tests(int b) {
085        short x = (short) b;
086        int y = x & 0xffff;
087        if (y == 0xffff) {
088            // Just do anything else to force jump instead of conditional move
089            y = (int) (System.currentTimeMillis() >> 32);
090        }
091        return y;
092    }
093
094    @Test
095    public void run5() {
096        runTest("testc", 0xffff);
097    }
098
099    /**
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}