author | simonis |
Tue, 19 May 2015 11:06:34 +0200 | |
changeset 30758 | 97072ce7c6fe |
child 35594 | cc13089c6327 |
permissions | -rw-r--r-- |
30758
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
1 |
/* |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
2 |
* Copyright 2015 SAP AG. All Rights Reserved. |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
3 |
* 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
|
4 |
* |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
5 |
* 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
|
6 |
* 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
|
7 |
* published by the Free Software Foundation. |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
8 |
* |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
9 |
* 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
|
10 |
* 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
|
11 |
* 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
|
12 |
* 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
|
13 |
* accompanied this code). |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
14 |
* |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
15 |
* 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
|
16 |
* 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
|
17 |
* 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
|
18 |
* |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
19 |
* 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
|
20 |
* 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
|
21 |
* questions. |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
22 |
*/ |
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 |
* @test |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
26 |
* @bug 8080190 |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
27 |
* @key regression |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
28 |
* @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
|
29 |
* @run main/othervm -Xbatch -XX:-UseOnStackReplacement IntRotateWithImmediate |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
30 |
* @author volker.simonis@gmail.com |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
31 |
*/ |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
32 |
|
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
33 |
public class IntRotateWithImmediate { |
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 |
// This is currently the same as Integer.rotateRight() |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
36 |
static int rotateRight(int i, int distance) { |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
37 |
// 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
|
38 |
// 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
|
39 |
// 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
|
40 |
// 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
|
41 |
// 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
|
42 |
// '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
|
43 |
return ((i >>> distance) | (i << -distance)); |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
44 |
} |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
45 |
|
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
46 |
static int compute(int x) { |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
47 |
return rotateRight(x, 3); |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
48 |
} |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
49 |
|
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
50 |
public static void main(String args[]) { |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
51 |
int val = 4096; |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
52 |
|
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
53 |
int firstResult = compute(val); |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
54 |
|
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
55 |
for (int i = 0; i < 100000; i++) { |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
56 |
int newResult = compute(val); |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
57 |
if (firstResult != newResult) { |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
58 |
throw new InternalError(firstResult + " != " + newResult); |
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 |
} |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
61 |
System.out.println("OK"); |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
62 |
} |
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
63 |
|
97072ce7c6fe
8080190: PPC64: Fix wrong rotate instructions in the .ad file
simonis
parents:
diff
changeset
|
64 |
} |