001/*
002 * Copyright (c) 2011, 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.optimize;
024
025import java.util.*;
026
027import org.junit.*;
028
029import com.oracle.graal.jtt.*;
030
031/*
032 */
033@SuppressWarnings("unused")
034public class Conditional01 extends JTTTest {
035
036    private static class TestClass {
037        private int nextPC;
038        private int pc;
039        private boolean aC;
040        private boolean aH;
041        private boolean aN;
042        private boolean aZ;
043        private boolean aV;
044        private boolean aS;
045        private int cyclesConsumed;
046        private int[] sram = new int[RAM_SIZE];
047
048        public void visit(CPC i) {
049            nextPC = pc + 2;
050            int tmp0 = getRegisterByte(i.r1);
051            int tmp1 = getRegisterByte(i.r2);
052            int tmp2 = bit(aC);
053            int tmp3 = tmp0 - tmp1 - tmp2;
054            boolean tmp4 = ((tmp0 & 128) != 0);
055            boolean tmp5 = ((tmp1 & 128) != 0);
056            boolean tmp6 = ((tmp3 & 128) != 0);
057            boolean tmp7 = ((tmp0 & 8) != 0);
058            boolean tmp8 = ((tmp1 & 8) != 0);
059            boolean tmp9 = ((tmp3 & 8) != 0);
060            aH = !tmp7 && tmp8 || tmp8 && tmp9 || tmp9 && !tmp7;
061            aC = !tmp4 && tmp5 || tmp5 && tmp6 || tmp6 && !tmp4;
062            aN = tmp6;
063            aZ = low(tmp3) == 0 && aZ;
064            aV = tmp4 && !tmp5 && !tmp6 || !tmp4 && tmp5 && tmp6;
065            aS = (aN != aV);
066            cyclesConsumed++;
067        }
068
069        public int getRegisterByte(Register r1) {
070            if ((r1.val % 10) == 0) {
071                return sram[r1.num];
072            }
073            return r1.val;
074        }
075
076        public int low(int tmp3) {
077            return tmp3 & 0x01;
078        }
079
080        public int bit(boolean c2) {
081            return c2 ? 1 : 0;
082        }
083    }
084
085    private static final int RAM_SIZE = 0x100;
086    private static final int init = new Random().nextInt();
087    private static final int init1 = new Register().val;
088    private static final Register init2 = new CPC().r1;
089
090    public static int test(int arg) {
091        TestClass c = new TestClass();
092        Random rnd = new Random();
093        for (int i = 0; i < arg; i++) {
094            CPC i2 = new CPC();
095            i2.r1 = new Register();
096            i2.r1.val = i;
097            i2.r1.num = i + RAM_SIZE - 20;
098            i2.r2 = new Register();
099            i2.r2.val = rnd.nextInt();
100            i2.r2.num = rnd.nextInt(RAM_SIZE);
101            try {
102                c.visit(i2);
103            } catch (RuntimeException re) {
104
105            }
106        }
107        return c.cyclesConsumed;
108    }
109
110    private static class Register {
111
112        int val;
113        int num;
114    }
115
116    private static class CPC {
117
118        public Register r1;
119        public Register r2;
120
121    }
122
123    @Test
124    public void run0() throws Throwable {
125        runTest("test", 0);
126    }
127
128    @Test
129    public void run1() throws Throwable {
130        runTest("test", 10);
131    }
132
133    @Test
134    public void run2() throws Throwable {
135        runTest("test", 20);
136    }
137
138    @Test
139    public void run3() throws Throwable {
140        runTest("test", 40);
141    }
142
143}