hotspot/test/compiler/codegen/IntRotateWithImmediate.java
author roland
Tue, 19 Apr 2016 19:52:39 -0700
changeset 38052 6ab6e9bc4759
parent 35594 cc13089c6327
child 40059 c2304140ed64
permissions -rw-r--r--
8154537: AArch64: some integer rotate instructions are never emitted Reviewed-by: aph, adinn, kvn
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
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    31
 * @run main/othervm -Xbatch -XX:-UseOnStackReplacement IntRotateWithImmediate
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    32
 * @author volker.simonis@gmail.com
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    33
 */
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
public class IntRotateWithImmediate {
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    36
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    37
  // This is currently the same as Integer.rotateRight()
38052
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    38
  static int rotateRight1(int i, int distance) {
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    39
    // On some architectures (i.e. x86_64 and ppc64) the following computation is
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    40
    // matched in the .ad file into a single MachNode which emmits a single rotate
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    41
    // machine instruction. It is important that the shift amount is masked to match
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    42
    // corresponding immediate width in the native instruction. On x86_64 the rotate
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    43
    // left instruction ('rol') encodes an 8-bit immediate while the corresponding
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    44
    // 'rotlwi' instruction on Power only encodes a 5-bit immediate.
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    45
    return ((i >>> distance) | (i << -distance));
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    46
  }
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    47
38052
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    48
  static int rotateRight2(int i, int distance) {
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    49
      return ((i >>> distance) | (i << (32-distance)));
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    50
  }
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    51
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    52
  static int compute1(int x) {
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    53
    return rotateRight1(x, 3);
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    54
  }
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    55
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    56
  static int compute2(int x) {
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    57
    return rotateRight2(x, 3);
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    58
  }
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    59
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    60
  public static void main(String args[]) {
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    61
    int val = 4096;
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    62
38052
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    63
    int firstResult = compute1(val);
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    64
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    65
    for (int i = 0; i < 100000; i++) {
38052
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    66
      int newResult = compute1(val);
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    67
      if (firstResult != newResult) {
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    68
        throw new InternalError(firstResult + " != " + newResult);
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    69
      }
6ab6e9bc4759 8154537: AArch64: some integer rotate instructions are never emitted
roland
parents: 35594
diff changeset
    70
      newResult = compute2(val);
30758
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    71
      if (firstResult != newResult) {
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    72
        throw new InternalError(firstResult + " != " + newResult);
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    73
      }
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    74
    }
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    75
    System.out.println("OK");
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    76
  }
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    77
97072ce7c6fe 8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff changeset
    78
}