Path: blob/master/test/hotspot/jtreg/compiler/codegen/IntRotateWithImmediate.java
41149 views
/*1* Copyright (c) 2015 SAP SE. All rights reserved.2* Copyright (c) 2016, Red Hat, Inc. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* @test26* @bug 808019027* @bug 815453728* @summary Test that the rotate distance used in the rotate instruction is properly masked with 0x1f29*30* @run main/othervm -Xbatch -XX:-UseOnStackReplacement compiler.codegen.IntRotateWithImmediate31* @author [email protected]32*/3334package compiler.codegen;3536public class IntRotateWithImmediate {3738// This is currently the same as Integer.rotateRight()39static int rotateRight1(int i, int distance) {40// On some architectures (i.e. x86_64 and ppc64) the following computation is41// matched in the .ad file into a single MachNode which emmits a single rotate42// machine instruction. It is important that the shift amount is masked to match43// corresponding immediate width in the native instruction. On x86_64 the rotate44// left instruction ('rol') encodes an 8-bit immediate while the corresponding45// 'rotlwi' instruction on Power only encodes a 5-bit immediate.46return ((i >>> distance) | (i << -distance));47}4849static int rotateRight2(int i, int distance) {50return ((i >>> distance) | (i << (32 - distance)));51}5253static int compute1(int x) {54return rotateRight1(x, 3);55}5657static int compute2(int x) {58return rotateRight2(x, 3);59}6061public static void main(String args[]) {62int val = 4096;6364int firstResult = compute1(val);6566for (int i = 0; i < 100000; i++) {67int newResult = compute1(val);68if (firstResult != newResult) {69throw new InternalError(firstResult + " != " + newResult);70}71newResult = compute2(val);72if (firstResult != newResult) {73throw new InternalError(firstResult + " != " + newResult);74}75}76System.out.println("OK");77}7879}808182