hotspot/test/compiler/codegen/IntRotateWithImmediate.java
author hseigel
Wed, 01 Mar 2017 08:00:02 -0500
changeset 46194 5596e6f63072
parent 40059 c2304140ed64
permissions -rw-r--r--
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
     1
/*
35594
cc13089c6327 8147937: Adapt SAP copyrights to new company name.
goetz
parents: 30758
diff changeset
     2
 * Copyright (c) 2015 SAP SE. All rights reserved.
38052
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
     3
 * Copyright (c) 2016, Red Hat, Inc. All rights reserved.
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
     5
 *
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
     8
 * published by the Free Software Foundation.
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
     9
 *
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    14
 * accompanied this code).
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    15
 *
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    19
 *
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    22
 * questions.
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    23
 */
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    24
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    25
/*
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    26
 * @test
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    27
 * @bug 8080190
38052
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    28
 * @bug 8154537
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    29
 * @key regression
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    30
 * @summary Test that the rotate distance used in the rotate instruction is properly masked with 0x1f
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    31
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    32
 * @run main/othervm -Xbatch -XX:-UseOnStackReplacement compiler.codegen.IntRotateWithImmediate
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    33
 * @author volker.simonis@gmail.com
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    34
 */
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    35
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    36
package compiler.codegen;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    37
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    38
public class IntRotateWithImmediate {
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    39
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    40
    // This is currently the same as Integer.rotateRight()
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    41
    static int rotateRight1(int i, int distance) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    42
        // On some architectures (i.e. x86_64 and ppc64) the following computation is
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    43
        // matched in the .ad file into a single MachNode which emmits a single rotate
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    44
        // machine instruction. It is important that the shift amount is masked to match
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    45
        // corresponding immediate width in the native instruction. On x86_64 the rotate
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    46
        // left instruction ('rol') encodes an 8-bit immediate while the corresponding
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    47
        // 'rotlwi' instruction on Power only encodes a 5-bit immediate.
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    48
        return ((i >>> distance) | (i << -distance));
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    49
    }
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    50
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    51
    static int rotateRight2(int i, int distance) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    52
        return ((i >>> distance) | (i << (32 - distance)));
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    53
    }
38052
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    54
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    55
    static int compute1(int x) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    56
        return rotateRight1(x, 3);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    57
    }
38052
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    58
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    59
    static int compute2(int x) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    60
        return rotateRight2(x, 3);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    61
    }
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    62
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    63
    public static void main(String args[]) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    64
        int val = 4096;
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    65
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    66
        int firstResult = compute1(val);
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    67
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    68
        for (int i = 0; i < 100000; i++) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    69
            int newResult = compute1(val);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    70
            if (firstResult != newResult) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    71
                throw new InternalError(firstResult + " != " + newResult);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    72
            }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    73
            newResult = compute2(val);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    74
            if (firstResult != newResult) {
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    75
                throw new InternalError(firstResult + " != " + newResult);
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    76
            }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    77
        }
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38052
diff changeset
    78
        System.out.println("OK");
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    79
    }
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    80
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    81
}