LongBits.java revision 12651:6ef01bd40ce2
155682Smarkm/* 255682Smarkm * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. 355682Smarkm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 455682Smarkm * 555682Smarkm * This code is free software; you can redistribute it and/or modify it 655682Smarkm * under the terms of the GNU General Public License version 2 only, as 7178825Sdfr * published by the Free Software Foundation. 8178825Sdfr * 9178825Sdfr * This code is distributed in the hope that it will be useful, but WITHOUT 10178825Sdfr * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1155682Smarkm * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12102644Snectar * version 2 for more details (a copy is included in the LICENSE file that 13102644Snectar * accompanied this code). 14102644Snectar * 15102644Snectar * You should have received a copy of the GNU General Public License version 1672445Sassar * 2 along with this work; if not, write to the Free Software Foundation, 1772445Sassar * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18102644Snectar * 19102644Snectar * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20102644Snectar * or visit www.oracle.com if you need additional information or have any 2155682Smarkm * questions. 2255682Smarkm */ 23178825Sdfrpackage org.graalvm.compiler.jtt.jdk; 24178825Sdfr 25178825Sdfrimport org.junit.Test; 26178825Sdfr 27178825Sdfrimport org.graalvm.compiler.jtt.JTTTest; 28178825Sdfr 29102644Snectarpublic class LongBits extends JTTTest { 30102644Snectar 31102644Snectar @SuppressWarnings("unused") private static long init = Long.reverseBytes(42); 3255682Smarkm private static long original = 0x0102030405060708L; 3355682Smarkm private static long v = 0b1000L; 34102644Snectar private static long v2 = 0x0100000000L; 35102644Snectar private static long zero = 0L; 36102644Snectar 37102644Snectar public static long test(long o) { 3855682Smarkm return Long.reverseBytes(o); 3955682Smarkm } 40102644Snectar 41102644Snectar public static int test2(long o) { 42102644Snectar return Long.numberOfLeadingZeros(o); 43102644Snectar } 4455682Smarkm 45178825Sdfr public static int test3(long o) { 46178825Sdfr return Long.numberOfTrailingZeros(o); 47178825Sdfr } 48178825Sdfr 49178825Sdfr public static int test4(long o) { 50178825Sdfr return Long.bitCount(o); 51178825Sdfr } 52178825Sdfr 53178825Sdfr @Test 54178825Sdfr public void run0() { 55178825Sdfr runTest("test", original); 56178825Sdfr } 57178825Sdfr 58178825Sdfr @Test 59178825Sdfr public void run1() { 60178825Sdfr runTest("test3", v); 61178825Sdfr } 62178825Sdfr 63178825Sdfr @Test 64178825Sdfr public void run2() { 65178825Sdfr runTest("test2", v); 66178825Sdfr } 67178825Sdfr 68178825Sdfr @Test 69178825Sdfr public void run3() { 70178825Sdfr runTest("test3", zero); 71178825Sdfr } 72178825Sdfr 73178825Sdfr @Test 74178825Sdfr public void run4() { 75178825Sdfr runTest("test2", zero); 76178825Sdfr } 77178825Sdfr 78178825Sdfr @Test 79178825Sdfr public void run5() { 80178825Sdfr runTest("test", 0x0102030405060708L); 81178825Sdfr } 82178825Sdfr 83178825Sdfr @Test 84178825Sdfr public void run6() { 85178825Sdfr runTest("test3", 0b1000L); 86178825Sdfr } 87178825Sdfr 88178825Sdfr @Test 89178825Sdfr public void run7() { 90178825Sdfr runTest("test2", 0b1000L); 9155682Smarkm } 92102644Snectar 93102644Snectar @Test 94102644Snectar public void run8() { 95102644Snectar runTest("test3", 0L); 96102644Snectar } 9755682Smarkm 9855682Smarkm @Test 99102644Snectar public void run9() { 100102644Snectar runTest("test2", 0L); 101102644Snectar } 102102644Snectar 10355682Smarkm @Test 10455682Smarkm public void run10() { 105102644Snectar runTest("test2", v2); 106102644Snectar } 107178825Sdfr 108102644Snectar @Test 10955682Smarkm public void run11() { 110178825Sdfr runTest("test3", v2); 111178825Sdfr } 112178825Sdfr 113178825Sdfr @Test 114178825Sdfr public void run12() { 115178825Sdfr runTest("test2", 0x0100000000L); 11655682Smarkm } 117178825Sdfr 118178825Sdfr @Test 119178825Sdfr public void run13() { 120178825Sdfr runTest("test3", 0x0100000000L); 121178825Sdfr } 122178825Sdfr 123178825Sdfr @Test 124178825Sdfr public void run14() { 125178825Sdfr runTest("test4", 0L); 126178825Sdfr runTest("test4", 1L); 127178825Sdfr runTest("test4", 0xffff00ffL); 128178825Sdfr runTest("test4", 0xffffffffL); 129178825Sdfr runTest("test4", 0x3ffffffffL); 130178825Sdfr runTest("test4", 0xffffffff3L); 131178825Sdfr runTest("test4", 0xffffffffffffffffL); 132178825Sdfr } 133178825Sdfr} 134178825Sdfr