comparison graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/optimize/Fold_Float01.java @ 5061:e808627bd16f

Renamed projects.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 08 Mar 2012 19:24:17 +0100
parents graal/com.oracle.max.graal.jtt/src/com/oracle/graal/jtt/optimize/Fold_Float01.java@4ed4295ce15f
children 390448a6b535
comparison
equal deleted inserted replaced
5060:4ed4295ce15f 5061:e808627bd16f
1 /*
2 * Copyright (c) 2009, 2012, 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 package com.oracle.graal.jtt.optimize;
24
25 import org.junit.*;
26
27 /*
28 * Tests constant folding of float operations.
29 */
30 public class Fold_Float01 {
31
32 public static float test(float arg) {
33 if (arg == 0) {
34 return add();
35 }
36 if (arg == 1) {
37 return sub();
38 }
39 if (arg == 2) {
40 return mul();
41 }
42 if (arg == 3) {
43 return div();
44 }
45 if (arg == 4) {
46 return mod();
47 }
48 return 0;
49 }
50
51 public static float add() {
52 float x = 3;
53 return x + 7;
54 }
55
56 public static float sub() {
57 float x = 15;
58 return x - 4;
59 }
60
61 public static float mul() {
62 float x = 6;
63 return x * 2;
64 }
65
66 public static float div() {
67 float x = 26;
68 return x / 2;
69 }
70
71 public static float mod() {
72 float x = 29;
73 return x % 15;
74 }
75
76 @Test
77 public void run0() throws Throwable {
78 Assert.assertEquals(10f, test(0f), 0);
79 }
80
81 @Test
82 public void run1() throws Throwable {
83 Assert.assertEquals(11f, test(1f), 0);
84 }
85
86 @Test
87 public void run2() throws Throwable {
88 Assert.assertEquals(12f, test(2f), 0);
89 }
90
91 @Test
92 public void run3() throws Throwable {
93 Assert.assertEquals(13f, test(3f), 0);
94 }
95
96 @Test
97 public void run4() throws Throwable {
98 Assert.assertEquals(14f, test(4f), 0);
99 }
100
101 }