1 /* 2 * Copyright (c) 2013, 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.compiler.ptx.test; 24 25 import org.junit.Test; 26 27 import java.lang.reflect.Method; 28 29 30 public class IntegerPTXTest extends PTXTestBase { 31 32 @Test 33 public void testAdd() { 34 compile("testAdd2I"); 35 compile("testAdd2L"); 36 compile("testAdd2B"); 37 compile("testAddIConst"); 38 compile("testAddConstI"); 39 } 40 41 public static int testAdd2I(int a, int b) { 42 return a + b; 43 } 44 45 public static long testAdd2L(long a, long b) { 46 return a + b; 47 } 48 49 public static int testAdd2B(byte a, byte b) { 50 return a + b; 51 } 52 53 public static int testAddIConst(int a) { 54 return a + 32; 55 } 56 57 public static int testAddConstI(int a) { 58 return 32 + a; 59 } 60 61 @Test 62 public void testSub() { 63 compile("testSub2I"); 64 compile("testSub2L"); 65 compile("testSubIConst"); 66 compile("testSubConstI"); 67 } 68 69 public static int testSub2I(int a, int b) { 70 return a - b; 71 } 72 73 public static long testSub2L(long a, long b) { 74 return a - b; 75 } 76 77 public static int testSubIConst(int a) { 78 return a - 32; 79 } 80 81 public static int testSubConstI(int a) { 82 return 32 - a; 83 } 84 85 @Test 86 public void testMul() { 87 compile("testMul2I"); 88 compile("testMul2L"); 89 compile("testMulIConst"); 90 compile("testMulConstI"); 91 } 92 93 public static int testMul2I(int a, int b) { 94 return a * b; 95 } 96 97 public static long testMul2L(long a, long b) { 98 return a * b; 99 } 100 101 public static int testMulIConst(int a) { 102 return a * 32; 103 } 104 105 public static int testMulConstI(int a) { 106 return 32 * a; 107 } 108 109 @Test 110 public void testDiv() { 111 compile("testDiv2I"); 112 compile("testDiv2L"); 113 compile("testDivIConst"); 114 compile("testDivConstI"); 115 } 116 117 public static int testDiv2I(int a, int b) { 118 return a / b; 119 } 120 121 public static long testDiv2L(long a, long b) { 122 return a / b; 123 } 124 125 public static int testDivIConst(int a) { 126 return a / 32; 127 } 128 129 public static int testDivConstI(int a) { 130 return 32 / a; 131 } 132 133 @Test 134 public void testRem() { 135 compile("testRem2I"); 136 compile("testRem2L"); 137 } 138 139 public static int testRem2I(int a, int b) { 140 return a % b; 141 } 142 143 public static long testRem2L(long a, long b) { 144 return a % b; 145 } 146 147 @Test 148 public void testIntConversion() { 149 compile("testI2L"); 150 compile("testL2I"); 151 compile("testI2C"); 152 compile("testI2B"); 153 compile("testI2F"); 154 compile("testI2D"); 155 } 156 157 public static long testI2L(int a) { 158 return (long)a; 159 } 160 161 public static char testI2C(int a) { 162 return (char)a; 163 } 164 165 public static byte testI2B(int a) { 166 return (byte)a; 167 } 168 169 public static float testI2F(int a) { 170 return (float)a; 171 } 172 173 public static double testI2D(int a) { 174 return (double)a; 175 } 176 177 public static int testL2I(long a) { 178 return (int)a; 179 } 180 181 public static void main(String[] args) { 182 IntegerPTXTest test = new IntegerPTXTest(); 183 for (Method m : IntegerPTXTest.class.getMethods()) { 184 String name = m.getName(); 185 if (m.getAnnotation(Test.class) == null && name.startsWith("test")) { 186 System.out.println(name + ": \n" + new String(test.compile(name).getTargetCode())); 187 } 188 } 189 } 190 }