1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker class Main { main(String[] args)18*795d594fSAndroid Build Coastguard Worker public static void main(String[] args) { 19*795d594fSAndroid Build Coastguard Worker testIntShiftRight(); 20*795d594fSAndroid Build Coastguard Worker testIntShiftLeft(); 21*795d594fSAndroid Build Coastguard Worker testIntUnsignedShiftRight(); 22*795d594fSAndroid Build Coastguard Worker testLongShiftRight(); 23*795d594fSAndroid Build Coastguard Worker testLongShiftLeft(); 24*795d594fSAndroid Build Coastguard Worker testLongUnsignedShiftRight(); 25*795d594fSAndroid Build Coastguard Worker } 26*795d594fSAndroid Build Coastguard Worker testIntShiftLeft()27*795d594fSAndroid Build Coastguard Worker public static void testIntShiftLeft() { 28*795d594fSAndroid Build Coastguard Worker int a = myField; 29*795d594fSAndroid Build Coastguard Worker int b = myOtherField << a; 30*795d594fSAndroid Build Coastguard Worker if (b != -2147483648) { 31*795d594fSAndroid Build Coastguard Worker throw new Error("Expected -2147483648, got " + b); 32*795d594fSAndroid Build Coastguard Worker } 33*795d594fSAndroid Build Coastguard Worker if (a != 0xFFF) { 34*795d594fSAndroid Build Coastguard Worker throw new Error("Expected 0xFFF, got " + a); 35*795d594fSAndroid Build Coastguard Worker } 36*795d594fSAndroid Build Coastguard Worker } 37*795d594fSAndroid Build Coastguard Worker testIntShiftRight()38*795d594fSAndroid Build Coastguard Worker public static void testIntShiftRight() { 39*795d594fSAndroid Build Coastguard Worker int a = myField; 40*795d594fSAndroid Build Coastguard Worker int b = myOtherField >> a; 41*795d594fSAndroid Build Coastguard Worker if (b != 0) { 42*795d594fSAndroid Build Coastguard Worker throw new Error("Expected 0, got " + b); 43*795d594fSAndroid Build Coastguard Worker } 44*795d594fSAndroid Build Coastguard Worker if (a != 0xFFF) { 45*795d594fSAndroid Build Coastguard Worker throw new Error("Expected 0xFFF, got " + a); 46*795d594fSAndroid Build Coastguard Worker } 47*795d594fSAndroid Build Coastguard Worker } 48*795d594fSAndroid Build Coastguard Worker testIntUnsignedShiftRight()49*795d594fSAndroid Build Coastguard Worker public static void testIntUnsignedShiftRight() { 50*795d594fSAndroid Build Coastguard Worker int a = myField; 51*795d594fSAndroid Build Coastguard Worker int b = myOtherField >>> a; 52*795d594fSAndroid Build Coastguard Worker if (b != 0) { 53*795d594fSAndroid Build Coastguard Worker throw new Error("Expected 0, got " + b); 54*795d594fSAndroid Build Coastguard Worker } 55*795d594fSAndroid Build Coastguard Worker if (a != 0xFFF) { 56*795d594fSAndroid Build Coastguard Worker throw new Error("Expected 0xFFF, got " + a); 57*795d594fSAndroid Build Coastguard Worker } 58*795d594fSAndroid Build Coastguard Worker } 59*795d594fSAndroid Build Coastguard Worker testLongShiftLeft()60*795d594fSAndroid Build Coastguard Worker public static void testLongShiftLeft() { 61*795d594fSAndroid Build Coastguard Worker long a = myLongField; 62*795d594fSAndroid Build Coastguard Worker long b = myOtherLongField << a; 63*795d594fSAndroid Build Coastguard Worker if (b != 0x2468ACF13579BDEL) { 64*795d594fSAndroid Build Coastguard Worker throw new Error("Expected 0x2468ACF13579BDEL, got " + b); 65*795d594fSAndroid Build Coastguard Worker } 66*795d594fSAndroid Build Coastguard Worker // The int conversion will be GVN'ed with the one required 67*795d594fSAndroid Build Coastguard Worker // by Java specification of long shift left. 68*795d594fSAndroid Build Coastguard Worker if ((int)a != 0x41) { 69*795d594fSAndroid Build Coastguard Worker throw new Error("Expected 0x41, got " + a); 70*795d594fSAndroid Build Coastguard Worker } 71*795d594fSAndroid Build Coastguard Worker } 72*795d594fSAndroid Build Coastguard Worker testLongShiftRight()73*795d594fSAndroid Build Coastguard Worker public static void testLongShiftRight() { 74*795d594fSAndroid Build Coastguard Worker long a = myLongField; 75*795d594fSAndroid Build Coastguard Worker long b = myOtherLongField >> a; 76*795d594fSAndroid Build Coastguard Worker if (b != 0x91A2B3C4D5E6F7L) { 77*795d594fSAndroid Build Coastguard Worker throw new Error("Expected 0x91A2B3C4D5E6F7L, got " + b); 78*795d594fSAndroid Build Coastguard Worker } 79*795d594fSAndroid Build Coastguard Worker // The int conversion will be GVN'ed with the one required 80*795d594fSAndroid Build Coastguard Worker // by Java specification of long shift right. 81*795d594fSAndroid Build Coastguard Worker if ((int)a != 0x41) { 82*795d594fSAndroid Build Coastguard Worker throw new Error("Expected 0x41, got " + a); 83*795d594fSAndroid Build Coastguard Worker } 84*795d594fSAndroid Build Coastguard Worker } 85*795d594fSAndroid Build Coastguard Worker testLongUnsignedShiftRight()86*795d594fSAndroid Build Coastguard Worker public static void testLongUnsignedShiftRight() { 87*795d594fSAndroid Build Coastguard Worker long a = myLongField; 88*795d594fSAndroid Build Coastguard Worker long b = myOtherLongField >>> a; 89*795d594fSAndroid Build Coastguard Worker if (b != 0x91A2B3C4D5E6F7L) { 90*795d594fSAndroid Build Coastguard Worker throw new Error("Expected 0x91A2B3C4D5E6F7L, got " + b); 91*795d594fSAndroid Build Coastguard Worker } 92*795d594fSAndroid Build Coastguard Worker // The int conversion will be GVN'ed with the one required 93*795d594fSAndroid Build Coastguard Worker // by Java specification of long shift right. 94*795d594fSAndroid Build Coastguard Worker if ((int)a != 0x41) { 95*795d594fSAndroid Build Coastguard Worker throw new Error("Expected 0x41, got " + a); 96*795d594fSAndroid Build Coastguard Worker } 97*795d594fSAndroid Build Coastguard Worker } 98*795d594fSAndroid Build Coastguard Worker 99*795d594fSAndroid Build Coastguard Worker static int myField = 0xFFF; 100*795d594fSAndroid Build Coastguard Worker static int myOtherField = 0x1; 101*795d594fSAndroid Build Coastguard Worker 102*795d594fSAndroid Build Coastguard Worker // Use a value that will need to be masked before doing the shift. 103*795d594fSAndroid Build Coastguard Worker // The maximum shift is 0x3F. 104*795d594fSAndroid Build Coastguard Worker static long myLongField = 0x41; 105*795d594fSAndroid Build Coastguard Worker static long myOtherLongField = 0x123456789abcdefL; 106*795d594fSAndroid Build Coastguard Worker } 107