< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/BitOpNodesTest.java

Print this page
rev 59103 : imported patch hotspot


  25 package org.graalvm.compiler.replacements.test;
  26 
  27 import org.graalvm.compiler.core.common.type.StampFactory;
  28 import org.graalvm.compiler.core.test.GraalCompilerTest;
  29 import org.graalvm.compiler.nodes.NodeView;
  30 import org.graalvm.compiler.nodes.ReturnNode;
  31 import org.graalvm.compiler.nodes.StructuredGraph;
  32 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  33 import org.graalvm.compiler.nodes.ValueNode;
  34 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  35 import org.graalvm.compiler.phases.tiers.HighTierContext;
  36 import org.graalvm.compiler.replacements.nodes.BitScanReverseNode;
  37 import org.junit.Assert;
  38 import org.junit.Assume;
  39 import org.junit.Test;
  40 
  41 import jdk.vm.ci.aarch64.AArch64;
  42 import jdk.vm.ci.amd64.AMD64;
  43 import jdk.vm.ci.code.Architecture;
  44 import jdk.vm.ci.meta.JavaKind;
  45 import jdk.vm.ci.sparc.SPARC;
  46 
  47 public class BitOpNodesTest extends GraalCompilerTest {
  48 
  49     private static final int INT_CONSTANT_1 = 0x80100010;
  50     private static final int INT_CONSTANT_2 = 0x00011110;
  51     private static final int INT_CONSTANT_3 = 0x00000000;
  52 
  53     private static final long LONG_CONSTANT_1 = 0x8000000000100010L;
  54     private static final long LONG_CONSTANT_2 = 0x0000000000011110L;
  55     private static final long LONG_CONSTANT_3 = 0x0000000000000000L;
  56 
  57     public static long dummyField;
  58 
  59     /*
  60      * Tests for BitCountNode canonicalizations.
  61      */
  62 
  63     /**
  64      * Determines if the current VM context supports intrinsics for the {@code bitCount} methods in
  65      * {@link Integer} and {@link Long}.
  66      */
  67     public static boolean isBitCountIntrinsicSupported(Architecture arch) {
  68         if (arch instanceof AMD64) {
  69             AMD64 amd64 = (AMD64) arch;
  70             return amd64.getFeatures().contains(AMD64.CPUFeature.POPCNT);
  71         } else {
  72             // Even though there are AArch64 intrinsics for bitCount, they do
  73             // not use BitCountNode.
  74             return arch instanceof SPARC;
  75         }
  76     }
  77 
  78     /**
  79      * Determines if the current VM context supports intrinsics for the {@code numberOfLeadingZeros}
  80      * methods in {@link Integer} and {@link Long}.
  81      */
  82     public static boolean isNumberLeadingZerosIntrinsicSupported(Architecture arch) {
  83         if (arch instanceof AMD64) {
  84             AMD64 amd64 = (AMD64) arch;
  85             return amd64.getFeatures().contains(AMD64.CPUFeature.LZCNT) && amd64.getFlags().contains(AMD64.Flag.UseCountLeadingZerosInstruction);
  86         } else {
  87             return arch instanceof SPARC || arch instanceof AArch64;
  88         }
  89     }
  90 
  91     /**
  92      * Determines if the current VM context supports intrinsics for the
  93      * {@code numberOfTrailingZeros} methods in {@link Integer} and {@link Long}.
  94      */
  95     public static boolean isNumberTrailingZerosIntrinsicSupported(Architecture arch) {
  96         if (arch instanceof AMD64) {
  97             AMD64 amd64 = (AMD64) arch;
  98             return amd64.getFeatures().contains(AMD64.CPUFeature.BMI1) && amd64.getFlags().contains(AMD64.Flag.UseCountTrailingZerosInstruction);
  99         } else {
 100             return arch instanceof SPARC || arch instanceof AArch64;
 101         }
 102     }
 103 
 104     public static int bitCountIntConstantSnippet() {
 105         return Integer.bitCount(INT_CONSTANT_1) + Integer.bitCount(INT_CONSTANT_2) + Integer.bitCount(INT_CONSTANT_3);
 106     }
 107 
 108     @Test
 109     public void testBitCountIntConstant() {
 110         ValueNode result = parseAndInline("bitCountIntConstantSnippet");
 111         Assert.assertEquals(7, result.asJavaConstant().asInt());
 112     }
 113 
 114     public static int bitCountLongConstantSnippet() {
 115         return Long.bitCount(LONG_CONSTANT_1) + Long.bitCount(LONG_CONSTANT_2) + Long.bitCount(LONG_CONSTANT_3);
 116     }
 117 
 118     public static int bitCountIntSnippet(int v) {
 119         return Integer.bitCount(v & 0xFFFFFF | 0xFF);
 120     }




  25 package org.graalvm.compiler.replacements.test;
  26 
  27 import org.graalvm.compiler.core.common.type.StampFactory;
  28 import org.graalvm.compiler.core.test.GraalCompilerTest;
  29 import org.graalvm.compiler.nodes.NodeView;
  30 import org.graalvm.compiler.nodes.ReturnNode;
  31 import org.graalvm.compiler.nodes.StructuredGraph;
  32 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  33 import org.graalvm.compiler.nodes.ValueNode;
  34 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  35 import org.graalvm.compiler.phases.tiers.HighTierContext;
  36 import org.graalvm.compiler.replacements.nodes.BitScanReverseNode;
  37 import org.junit.Assert;
  38 import org.junit.Assume;
  39 import org.junit.Test;
  40 
  41 import jdk.vm.ci.aarch64.AArch64;
  42 import jdk.vm.ci.amd64.AMD64;
  43 import jdk.vm.ci.code.Architecture;
  44 import jdk.vm.ci.meta.JavaKind;

  45 
  46 public class BitOpNodesTest extends GraalCompilerTest {
  47 
  48     private static final int INT_CONSTANT_1 = 0x80100010;
  49     private static final int INT_CONSTANT_2 = 0x00011110;
  50     private static final int INT_CONSTANT_3 = 0x00000000;
  51 
  52     private static final long LONG_CONSTANT_1 = 0x8000000000100010L;
  53     private static final long LONG_CONSTANT_2 = 0x0000000000011110L;
  54     private static final long LONG_CONSTANT_3 = 0x0000000000000000L;
  55 
  56     public static long dummyField;
  57 
  58     /*
  59      * Tests for BitCountNode canonicalizations.
  60      */
  61 
  62     /**
  63      * Determines if the current VM context supports intrinsics for the {@code bitCount} methods in
  64      * {@link Integer} and {@link Long}.
  65      */
  66     public static boolean isBitCountIntrinsicSupported(Architecture arch) {
  67         if (arch instanceof AMD64) {
  68             AMD64 amd64 = (AMD64) arch;
  69             return amd64.getFeatures().contains(AMD64.CPUFeature.POPCNT);
  70         } else {
  71             // Even though there are AArch64 intrinsics for bitCount, they do
  72             // not use BitCountNode.
  73             return false;
  74         }
  75     }
  76 
  77     /**
  78      * Determines if the current VM context supports intrinsics for the {@code numberOfLeadingZeros}
  79      * methods in {@link Integer} and {@link Long}.
  80      */
  81     public static boolean isNumberLeadingZerosIntrinsicSupported(Architecture arch) {
  82         if (arch instanceof AMD64) {
  83             AMD64 amd64 = (AMD64) arch;
  84             return amd64.getFeatures().contains(AMD64.CPUFeature.LZCNT) && amd64.getFlags().contains(AMD64.Flag.UseCountLeadingZerosInstruction);
  85         } else {
  86             return arch instanceof AArch64;
  87         }
  88     }
  89 
  90     /**
  91      * Determines if the current VM context supports intrinsics for the
  92      * {@code numberOfTrailingZeros} methods in {@link Integer} and {@link Long}.
  93      */
  94     public static boolean isNumberTrailingZerosIntrinsicSupported(Architecture arch) {
  95         if (arch instanceof AMD64) {
  96             AMD64 amd64 = (AMD64) arch;
  97             return amd64.getFeatures().contains(AMD64.CPUFeature.BMI1) && amd64.getFlags().contains(AMD64.Flag.UseCountTrailingZerosInstruction);
  98         } else {
  99             return arch instanceof AArch64;
 100         }
 101     }
 102 
 103     public static int bitCountIntConstantSnippet() {
 104         return Integer.bitCount(INT_CONSTANT_1) + Integer.bitCount(INT_CONSTANT_2) + Integer.bitCount(INT_CONSTANT_3);
 105     }
 106 
 107     @Test
 108     public void testBitCountIntConstant() {
 109         ValueNode result = parseAndInline("bitCountIntConstantSnippet");
 110         Assert.assertEquals(7, result.asJavaConstant().asInt());
 111     }
 112 
 113     public static int bitCountLongConstantSnippet() {
 114         return Long.bitCount(LONG_CONSTANT_1) + Long.bitCount(LONG_CONSTANT_2) + Long.bitCount(LONG_CONSTANT_3);
 115     }
 116 
 117     public static int bitCountIntSnippet(int v) {
 118         return Integer.bitCount(v & 0xFFFFFF | 0xFF);
 119     }


< prev index next >