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 package org.graalvm.compiler.core.test; 25 26 import org.junit.Test; 27 28 /* 29 * Test compilation of ZeroExtend and SignExtend nodes 30 */ 31 32 public class ZeroSignExtendTest extends GraalCompilerTest { 33 34 int testSnippet1(char[] chars) { 35 int x = 1; 36 x += chars[0]; 37 x -= chars[1]; 38 x *= chars[2]; 39 x /= chars[3]; 40 x &= chars[4]; 41 x |= chars[5]; 42 x ^= chars[6]; 43 x <<= chars[7]; 44 x >>= (chars[8] - chars[0]); 45 x >>>= (chars[9] - chars[0]); 46 x += chars[1]; 47 return x; 48 } 49 50 long testSnippet2(char[] chars) { 51 long y = 2; 52 y += chars[0]; 53 y -= chars[1]; 54 y *= chars[2]; 55 y /= chars[3]; 56 y &= chars[4]; 57 y |= chars[5]; 58 y ^= chars[6]; 59 y <<= chars[7]; 60 y >>= (chars[8] - chars[0]); 61 y >>>= (chars[9] - chars[0]); 62 y += chars[1]; 63 return y; 64 } 65 66 int testSnippet3(short[] shorts) { 67 int x = 1; 68 x += shorts[0]; 69 x -= shorts[1]; 70 x *= shorts[2]; 71 x /= shorts[3]; 72 x &= shorts[4]; 73 x |= shorts[5]; 74 x ^= shorts[6]; 75 x <<= shorts[7]; 76 x >>= (shorts[8] - shorts[0]); 77 x >>>= (shorts[9] - shorts[0]); 78 x += shorts[1]; 79 return x; 80 } 81 82 long testSnippet4(short[] shorts) { 83 long y = 2; 84 y += shorts[0]; 85 y -= shorts[1]; 86 y *= shorts[2]; 87 y /= shorts[3]; 88 y &= shorts[4]; 89 y |= shorts[5]; 90 y ^= shorts[6]; 91 y <<= shorts[7]; 92 y >>= (shorts[8] - shorts[0]); 93 y >>>= (shorts[9] - shorts[0]); 94 y += shorts[1]; 95 return y; 96 } 97 98 int testSnippet5(byte[] bytes) { 99 int x = 1; 100 x += bytes[0]; 101 x -= bytes[1]; 102 x *= bytes[2]; 103 x /= bytes[3]; 104 x &= bytes[4]; 105 x |= bytes[5]; 106 x ^= bytes[6]; 107 x <<= bytes[7]; 108 x >>= (bytes[8] - bytes[0]); 109 x >>>= (bytes[9] - bytes[0]); 110 x += bytes[1]; 111 return x; 112 } 113 114 long testSnippet6(byte[] bytes) { 115 long y = 2; 116 y += bytes[0]; 117 y -= bytes[1]; 118 y *= bytes[2]; 119 y /= bytes[3]; 120 y &= bytes[4]; 121 y |= bytes[5]; 122 y ^= bytes[6]; 123 y <<= bytes[7]; 124 y >>= (bytes[8] - bytes[0]); 125 y >>>= (bytes[9] - bytes[0]); 126 y += bytes[1]; 127 return y; 128 } 129 130 @Test 131 132 public void test() { 133 char[] input1 = new char[]{'0', '1', '2', '3', '4', '5', '7', '8', '9', 'A'}; 134 char[] input2 = new char[]{'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'}; 135 136 short[] input3 = new short[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 137 short[] input4 = new short[]{11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; 138 139 byte[] input5 = new byte[]{21, 22, 23, 24, 25, 26, 27, 28, 29, 30}; 140 byte[] input6 = new byte[]{11, 12, 13, 14, 15, 16, 17, 18, 19, 40}; 141 142 test("testSnippet1", input1); 143 test("testSnippet2", input2); 144 test("testSnippet3", input3); 145 test("testSnippet4", input4); 146 test("testSnippet5", input5); 147 test("testSnippet6", input6); 148 } 149 }