001/*
002 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.jtt.jdk;
024
025import org.junit.*;
026
027import com.oracle.graal.jtt.*;
028
029public class LongBits extends JTTTest {
030
031    @SuppressWarnings("unused") private static long init = Long.reverseBytes(42);
032    private static long original = 0x0102030405060708L;
033    private static long v = 0b1000L;
034    private static long v2 = 0x0100000000L;
035    private static long zero = 0L;
036
037    public static long test(long o) {
038        return Long.reverseBytes(o);
039    }
040
041    public static int test2(long o) {
042        return Long.numberOfLeadingZeros(o);
043    }
044
045    public static int test3(long o) {
046        return Long.numberOfTrailingZeros(o);
047    }
048
049    public static int test4(long o) {
050        return Long.bitCount(o);
051    }
052
053    @Test
054    public void run0() {
055        runTest("test", original);
056    }
057
058    @Test
059    public void run1() {
060        runTest("test3", v);
061    }
062
063    @Test
064    public void run2() {
065        runTest("test2", v);
066    }
067
068    @Test
069    public void run3() {
070        runTest("test3", zero);
071    }
072
073    @Test
074    public void run4() {
075        runTest("test2", zero);
076    }
077
078    @Test
079    public void run5() {
080        runTest("test", 0x0102030405060708L);
081    }
082
083    @Test
084    public void run6() {
085        runTest("test3", 0b1000L);
086    }
087
088    @Test
089    public void run7() {
090        runTest("test2", 0b1000L);
091    }
092
093    @Test
094    public void run8() {
095        runTest("test3", 0L);
096    }
097
098    @Test
099    public void run9() {
100        runTest("test2", 0L);
101    }
102
103    @Test
104    public void run10() {
105        runTest("test2", v2);
106    }
107
108    @Test
109    public void run11() {
110        runTest("test3", v2);
111    }
112
113    @Test
114    public void run12() {
115        runTest("test2", 0x0100000000L);
116    }
117
118    @Test
119    public void run13() {
120        runTest("test3", 0x0100000000L);
121    }
122
123    @Test
124    public void run14() {
125        runTest("test4", 0L);
126        runTest("test4", 1L);
127        runTest("test4", 0xffff00ffL);
128        runTest("test4", 0xffffffffL);
129        runTest("test4", 0x3ffffffffL);
130        runTest("test4", 0xffffffff3L);
131        runTest("test4", 0xffffffffffffffffL);
132    }
133}