8005033: clear high word for integer pop count on SPARC

Wed, 19 Dec 2012 14:44:00 -0800

author
twisti
date
Wed, 19 Dec 2012 14:44:00 -0800
changeset 4362
65c8342f726a
parent 4361
1e41b0bc58a0
child 4363
2c7f594145dc

8005033: clear high word for integer pop count on SPARC
Reviewed-by: kvn, twisti
Contributed-by: Richard Reingruber <richard.reingruber@sap.com>

src/cpu/sparc/vm/sparc.ad file | annotate | diff | comparison | revisions
test/compiler/8005033/Test8005033.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/cpu/sparc/vm/sparc.ad	Tue Dec 18 17:37:44 2012 -0800
     1.2 +++ b/src/cpu/sparc/vm/sparc.ad	Wed Dec 19 14:44:00 2012 -0800
     1.3 @@ -10224,7 +10224,7 @@
     1.4  
     1.5  //---------- Zeros Count Instructions ------------------------------------------
     1.6  
     1.7 -instruct countLeadingZerosI(iRegI dst, iRegI src, iRegI tmp, flagsReg cr) %{
     1.8 +instruct countLeadingZerosI(iRegIsafe dst, iRegI src, iRegI tmp, flagsReg cr) %{
     1.9    predicate(UsePopCountInstruction);  // See Matcher::match_rule_supported
    1.10    match(Set dst (CountLeadingZerosI src));
    1.11    effect(TEMP dst, TEMP tmp, KILL cr);
    1.12 @@ -10321,7 +10321,7 @@
    1.13    ins_pipe(ialu_reg);
    1.14  %}
    1.15  
    1.16 -instruct countTrailingZerosI(iRegI dst, iRegI src, flagsReg cr) %{
    1.17 +instruct countTrailingZerosI(iRegIsafe dst, iRegI src, flagsReg cr) %{
    1.18    predicate(UsePopCountInstruction);  // See Matcher::match_rule_supported
    1.19    match(Set dst (CountTrailingZerosI src));
    1.20    effect(TEMP dst, KILL cr);
    1.21 @@ -10364,19 +10364,21 @@
    1.22  
    1.23  //---------- Population Count Instructions -------------------------------------
    1.24  
    1.25 -instruct popCountI(iRegI dst, iRegI src) %{
    1.26 +instruct popCountI(iRegIsafe dst, iRegI src) %{
    1.27    predicate(UsePopCountInstruction);
    1.28    match(Set dst (PopCountI src));
    1.29  
    1.30 -  format %{ "POPC   $src, $dst" %}
    1.31 -  ins_encode %{
    1.32 -    __ popc($src$$Register, $dst$$Register);
    1.33 +  format %{ "SRL    $src, G0, $dst\t! clear upper word for 64 bit POPC\n\t"
    1.34 +            "POPC   $dst, $dst" %}
    1.35 +  ins_encode %{
    1.36 +    __ srl($src$$Register, G0, $dst$$Register);
    1.37 +    __ popc($dst$$Register, $dst$$Register);
    1.38    %}
    1.39    ins_pipe(ialu_reg);
    1.40  %}
    1.41  
    1.42  // Note: Long.bitCount(long) returns an int.
    1.43 -instruct popCountL(iRegI dst, iRegL src) %{
    1.44 +instruct popCountL(iRegIsafe dst, iRegL src) %{
    1.45    predicate(UsePopCountInstruction);
    1.46    match(Set dst (PopCountL src));
    1.47  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/compiler/8005033/Test8005033.java	Wed Dec 19 14:44:00 2012 -0800
     2.3 @@ -0,0 +1,50 @@
     2.4 +/*
     2.5 + * Copyright 2012 SAP AG.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/**
    2.28 + * @test
    2.29 + * @bug 8005033
    2.30 + * @summary On sparcv9, C2's intrinsic for Integer.bitCount(OV) returns wrong result if OV is the result of an operation with int overflow.
    2.31 + * @run main/othervm -Xcomp -XX:CompileOnly=Test8005033::testBitCount Test8005033
    2.32 + * @author Richard Reingruber richard DOT reingruber AT sap DOT com
    2.33 + */
    2.34 +
    2.35 +public class Test8005033 {
    2.36 +    public static int MINUS_ONE = -1;
    2.37 +
    2.38 +    public static void main(String[] args) {
    2.39 +        System.out.println("EXECUTING test.");
    2.40 +        Integer.bitCount(1);   // load class
    2.41 +        int expectedBitCount = 0;
    2.42 +        int calculatedBitCount = testBitCount();
    2.43 +        if (expectedBitCount != calculatedBitCount) {
    2.44 +            throw new InternalError("got " + calculatedBitCount + " but expected " + expectedBitCount);
    2.45 +        }
    2.46 +        System.out.println("SUCCESSFULLY passed test.");
    2.47 +    }
    2.48 +
    2.49 +    // testBitCount will be compiled using the Integer.bitCount() intrinsic if possible
    2.50 +    private static int testBitCount() {
    2.51 +        return Integer.bitCount(MINUS_ONE+1);   // -1 + 1 => int overflow
    2.52 +    }
    2.53 +}

mercurial