hotspot/test/compiler/6378821/Test6378821.java
author twisti
Fri, 13 Mar 2009 11:35:17 -0700
changeset 2255 54abdf3e1055
child 5547 f4b087cbb361
permissions -rw-r--r--
6378821: bitCount() should use POPC on SPARC processors and AMD+10h Summary: bitCount() should use POPC on SPARC processors where POPC is implemented directly in hardware. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2255
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
     1
/*
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
     4
 *
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
     8
 *
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    13
 * accompanied this code).
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    14
 *
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    18
 *
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    21
 * have any questions.
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    22
 */
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    23
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    24
/**
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    25
 * @test
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    26
 * @bug 6378821
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    27
 * @summary where available, bitCount() should use POPC on SPARC processors and AMD+10h
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    28
 *
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    29
 * @run main/othervm -Xcomp -XX:CompileOnly=Test6378821.fcomp Test6378821
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    30
 */
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    31
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    32
public class Test6378821 {
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    33
    static final int[]  ia = new int[]  { 0x12345678 };
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    34
    static final long[] la = new long[] { 0x12345678abcdefL };
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    35
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    36
    public static void main(String [] args) {
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    37
        // Resolve the class and the method.
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    38
        Integer.bitCount(1);
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    39
        Long.bitCount(1);
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    40
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    41
        sub(ia[0]);
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    42
        sub(la[0]);
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    43
        sub(ia);
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    44
        sub(la);
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    45
    }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    46
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    47
    static void check(int i, int expected, int result) {
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    48
        if (result != expected) {
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    49
            throw new InternalError("Wrong population count for " + i + ": " + result + " != " + expected);
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    50
        }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    51
    }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    52
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    53
    static void check(long l, int expected, int result) {
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    54
        if (result != expected) {
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    55
            throw new InternalError("Wrong population count for " + l + ": " + result + " != " + expected);
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    56
        }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    57
    }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    58
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    59
    static void sub(int i)     { check(i,     fint(i),  fcomp(i) ); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    60
    static void sub(int[] ia)  { check(ia[0], fint(ia), fcomp(ia)); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    61
    static void sub(long l)    { check(l,     fint(l),  fcomp(l) ); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    62
    static void sub(long[] la) { check(la[0], fint(la), fcomp(la)); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    63
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    64
    static int fint (int i)     { return Integer.bitCount(i); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    65
    static int fcomp(int i)     { return Integer.bitCount(i); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    66
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    67
    static int fint (int[] ia)  { return Integer.bitCount(ia[0]); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    68
    static int fcomp(int[] ia)  { return Integer.bitCount(ia[0]); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    69
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    70
    static int fint (long l)    { return Long.bitCount(l); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    71
    static int fcomp(long l)    { return Long.bitCount(l); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    72
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    73
    static int fint (long[] la) { return Long.bitCount(la[0]); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    74
    static int fcomp(long[] la) { return Long.bitCount(la[0]); }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents:
diff changeset
    75
}