1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2017, Red Hat Inc. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 26 package org.graalvm.compiler.core.test; 27 28 import org.junit.Test; 29 30 /* 31 * Test compilation of ZeroExtend and SignExtend nodes 32 */ 33 34 public class ZeroSignExtendTest extends GraalCompilerTest { 35 36 int testSnippet1(char[] chars) { 37 int x = 1; 38 x += chars[0]; 39 x -= chars[1]; 40 x *= chars[2]; 41 x /= chars[3]; 42 x &= chars[4]; 43 x |= chars[5]; 44 x ^= chars[6]; 45 x <<= chars[7]; 46 x >>= (chars[8] - chars[0]); 47 x >>>= (chars[9] - chars[0]); 48 x += chars[1]; 49 return x; 50 } 51 52 long testSnippet2(char[] chars) { 53 long y = 2; 54 y += chars[0]; 55 y -= chars[1]; 56 y *= chars[2]; 57 y /= chars[3]; 58 y &= chars[4]; 59 y |= chars[5]; 60 y ^= chars[6]; 61 y <<= chars[7]; 62 y >>= (chars[8] - chars[0]); 63 y >>>= (chars[9] - chars[0]); 64 y += chars[1]; 65 return y; 66 } 67 68 int testSnippet3(short[] shorts) { 69 int x = 1; 70 x += shorts[0]; 71 x -= shorts[1]; 72 x *= shorts[2]; 73 x /= shorts[3]; 74 x &= shorts[4]; 75 x |= shorts[5]; 76 x ^= shorts[6]; 77 x <<= shorts[7]; 78 x >>= (shorts[8] - shorts[0]); 79 x >>>= (shorts[9] - shorts[0]); 80 x += shorts[1]; 81 return x; 82 } 83 84 long testSnippet4(short[] shorts) { 85 long y = 2; 86 y += shorts[0]; 87 y -= shorts[1]; 88 y *= shorts[2]; 89 y /= shorts[3]; 90 y &= shorts[4]; 91 y |= shorts[5]; 92 y ^= shorts[6]; 93 y <<= shorts[7]; 94 y >>= (shorts[8] - shorts[0]); 95 y >>>= (shorts[9] - shorts[0]); 96 y += shorts[1]; 97 return y; 98 } 99 100 int testSnippet5(byte[] bytes) { 101 int x = 1; 102 x += bytes[0]; 103 x -= bytes[1]; 104 x *= bytes[2]; 105 x /= bytes[3]; 106 x &= bytes[4]; 107 x |= bytes[5]; 108 x ^= bytes[6]; 109 x <<= bytes[7]; 110 x >>= (bytes[8] - bytes[0]); 111 x >>>= (bytes[9] - bytes[0]); 112 x += bytes[1]; 113 return x; 114 } 115 116 long testSnippet6(byte[] bytes) { 117 long y = 2; 118 y += bytes[0]; 119 y -= bytes[1]; 120 y *= bytes[2]; 121 y /= bytes[3]; 122 y &= bytes[4]; 123 y |= bytes[5]; 124 y ^= bytes[6]; 125 y <<= bytes[7]; 126 y >>= (bytes[8] - bytes[0]); 127 y >>>= (bytes[9] - bytes[0]); 128 y += bytes[1]; 129 return y; 130 } 131 132 @Test 133 134 public void test() { 135 char[] input1 = new char[]{'0', '1', '2', '3', '4', '5', '7', '8', '9', 'A'}; 136 char[] input2 = new char[]{'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'}; 137 138 short[] input3 = new short[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 139 short[] input4 = new short[]{11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; 140 141 byte[] input5 = new byte[]{21, 22, 23, 24, 25, 26, 27, 28, 29, 30}; 142 byte[] input6 = new byte[]{11, 12, 13, 14, 15, 16, 17, 18, 19, 40}; 143 144 test("testSnippet1", input1); 145 test("testSnippet2", input2); 146 test("testSnippet3", input3); 147 test("testSnippet4", input4); 148 test("testSnippet5", input5); 149 test("testSnippet6", input6); 150 } 151 }