< prev index next >

test/compiler/codegen/IntRotateWithImmediate.java

Print this page
rev 11557 : 8132919: use package in compiler tests
Reviewed-by: duke


  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * @test
  27  * @bug 8080190
  28  * @bug 8154537
  29  * @key regression
  30  * @summary Test that the rotate distance used in the rotate instruction is properly masked with 0x1f
  31  * @run main/othervm -Xbatch -XX:-UseOnStackReplacement IntRotateWithImmediate

  32  * @author volker.simonis@gmail.com
  33  */
  34 


  35 public class IntRotateWithImmediate {
  36 
  37   // This is currently the same as Integer.rotateRight()
  38   static int rotateRight1(int i, int distance) {
  39     // On some architectures (i.e. x86_64 and ppc64) the following computation is
  40     // matched in the .ad file into a single MachNode which emmits a single rotate
  41     // machine instruction. It is important that the shift amount is masked to match
  42     // corresponding immediate width in the native instruction. On x86_64 the rotate
  43     // left instruction ('rol') encodes an 8-bit immediate while the corresponding
  44     // 'rotlwi' instruction on Power only encodes a 5-bit immediate.
  45     return ((i >>> distance) | (i << -distance));
  46   }
  47 
  48   static int rotateRight2(int i, int distance) {
  49       return ((i >>> distance) | (i << (32-distance)));
  50   }
  51 
  52   static int compute1(int x) {
  53     return rotateRight1(x, 3);
  54   }
  55 
  56   static int compute2(int x) {
  57     return rotateRight2(x, 3);
  58   }
  59 
  60   public static void main(String args[]) {
  61     int val = 4096;
  62 
  63     int firstResult = compute1(val);
  64 
  65     for (int i = 0; i < 100000; i++) {
  66       int newResult = compute1(val);
  67       if (firstResult != newResult) {
  68         throw new InternalError(firstResult + " != " + newResult);
  69       }


  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /*
  26  * @test
  27  * @bug 8080190
  28  * @bug 8154537
  29  * @key regression
  30  * @summary Test that the rotate distance used in the rotate instruction is properly masked with 0x1f
  31  *
  32  * @run main/othervm -Xbatch -XX:-UseOnStackReplacement compiler.codegen.IntRotateWithImmediate
  33  * @author volker.simonis@gmail.com
  34  */
  35 
  36 package compiler.codegen;
  37 
  38 public class IntRotateWithImmediate {
  39 
  40     // This is currently the same as Integer.rotateRight()
  41     static int rotateRight1(int i, int distance) {
  42         // On some architectures (i.e. x86_64 and ppc64) the following computation is
  43         // matched in the .ad file into a single MachNode which emmits a single rotate
  44         // machine instruction. It is important that the shift amount is masked to match
  45         // corresponding immediate width in the native instruction. On x86_64 the rotate
  46         // left instruction ('rol') encodes an 8-bit immediate while the corresponding
  47         // 'rotlwi' instruction on Power only encodes a 5-bit immediate.
  48         return ((i >>> distance) | (i << -distance));
  49     }
  50 
  51     static int rotateRight2(int i, int distance) {
  52         return ((i >>> distance) | (i << (32 - distance)));
  53     }
  54 
  55     static int compute1(int x) {
  56         return rotateRight1(x, 3);
  57     }
  58 
  59     static int compute2(int x) {
  60         return rotateRight2(x, 3);
  61     }
  62 
  63     public static void main(String args[]) {
  64         int val = 4096;
  65 
  66         int firstResult = compute1(val);
  67 
  68         for (int i = 0; i < 100000; i++) {
  69             int newResult = compute1(val);
  70             if (firstResult != newResult) {
  71                 throw new InternalError(firstResult + " != " + newResult);
  72             }
< prev index next >