Search in sources :

Example 6 with FloatStamp

use of org.graalvm.compiler.core.common.type.FloatStamp in project graal by oracle.

the class ReinterpretStampFloatToIntTest method data.

@Parameters(name = "{0}")
public static Collection<Object[]> data() {
    List<Object[]> ret = new ArrayList<>();
    for (int x : interestingInts) {
        float lowerBound = Float.intBitsToFloat(x);
        if (Float.isNaN(lowerBound)) {
            continue;
        }
        for (int y : interestingInts) {
            float upperBound = Float.intBitsToFloat(y);
            if (Float.isNaN(upperBound)) {
                continue;
            }
            if (Float.compare(lowerBound, upperBound) <= 0) {
                ret.add(new Object[] { new FloatStamp(Float.SIZE, lowerBound, upperBound, true) });
                ret.add(new Object[] { new FloatStamp(Float.SIZE, lowerBound, upperBound, false) });
            }
        }
    }
    ret.add(new Object[] { new FloatStamp(Float.SIZE, Float.NaN, Float.NaN, false) });
    return ret;
}
Also used : ArrayList(java.util.ArrayList) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) Parameters(org.junit.runners.Parameterized.Parameters)

Example 7 with FloatStamp

use of org.graalvm.compiler.core.common.type.FloatStamp in project graal by oracle.

the class ReinterpretStampLongToDoubleTest method run.

@Test
public void run() {
    ParameterNode param = new ParameterNode(0, StampPair.createSingle(inputStamp));
    ValueNode reinterpret = ReinterpretNode.create(JavaKind.Double, param, NodeView.DEFAULT);
    reinterpret.inferStamp();
    FloatStamp resultStamp = (FloatStamp) reinterpret.stamp(NodeView.DEFAULT);
    Assert.assertEquals(Double.SIZE, resultStamp.getBits());
    for (long input : interestingLongs) {
        double result = Double.longBitsToDouble(input);
        if (inputStamp.contains(input) && !resultStamp.contains(result)) {
            Assert.fail(String.format("value 0x%x (%f) is in input stamp, but not in result stamp (%s)", input, result, resultStamp));
        }
    }
}
Also used : ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) Test(org.junit.Test)

Example 8 with FloatStamp

use of org.graalvm.compiler.core.common.type.FloatStamp in project graal by oracle.

the class ConstantNode method forPrimitive.

/**
 * Returns a node for a primitive of a given type.
 */
public static ConstantNode forPrimitive(Stamp stamp, Constant constant) {
    if (stamp instanceof IntegerStamp) {
        PrimitiveConstant primitive = (PrimitiveConstant) constant;
        assert primitive.getJavaKind().isNumericInteger() && stamp.getStackKind() == primitive.getJavaKind().getStackKind();
        IntegerStamp istamp = (IntegerStamp) stamp;
        return forIntegerBits(istamp.getBits(), primitive);
    } else if (stamp instanceof FloatStamp) {
        PrimitiveConstant primitive = (PrimitiveConstant) constant;
        assert primitive.getJavaKind().isNumericFloat() && stamp.getStackKind() == primitive.getJavaKind();
        return forConstant(primitive, null);
    } else {
        assert !(stamp instanceof AbstractObjectStamp);
        return new ConstantNode(constant, stamp.constant(constant, null));
    }
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp)

Example 9 with FloatStamp

use of org.graalvm.compiler.core.common.type.FloatStamp in project graal by oracle.

the class PrimitiveStampBoundaryTest method checkBinaryOperation.

private static void checkBinaryOperation(ArithmeticOpTable.BinaryOp<?> op, Stamp result, Stamp v1stamp, Stamp v2stamp) {
    Stamp folded = op.foldStamp(v1stamp, v2stamp);
    if (v1stamp.isEmpty() || v2stamp.isEmpty()) {
        assertTrue(folded.isEmpty());
        assertTrue(v1stamp.asConstant() != null || v1stamp.isEmpty());
        assertTrue(v2stamp.asConstant() != null || v2stamp.isEmpty());
        return;
    }
    Constant constant = op.foldConstant(v1stamp.asConstant(), v2stamp.asConstant());
    if (constant != null) {
        assertFalse(folded.isEmpty());
        Constant constant2 = folded.asConstant();
        if (constant2 == null && v1stamp instanceof FloatStamp) {
            JavaConstant c = (JavaConstant) constant;
            assertTrue((c.getJavaKind() == JavaKind.Double && Double.isNaN(c.asDouble())) || (c.getJavaKind() == JavaKind.Float && Float.isNaN(c.asFloat())));
        } else {
            assertTrue(constant2 != null, "should constant fold %s %s %s %s", op, v1stamp, v2stamp, folded);
            if (!constant.equals(constant2)) {
                op.foldConstant(v1stamp.asConstant(), v2stamp.asConstant());
                op.foldStamp(v1stamp, v2stamp);
            }
            assertTrue(constant.equals(constant2), "should produce same constant %s %s %s %s %s", op, v1stamp, v2stamp, constant, constant2);
        }
        assertTrue(result.meet(folded).equals(result), "result out of range %s %s %s %s %s %s", op, v1stamp, v2stamp, folded, result, result.meet(folded));
    }
}
Also used : PrimitiveStamp(org.graalvm.compiler.core.common.type.PrimitiveStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) Constant(jdk.vm.ci.meta.Constant) JavaConstant(jdk.vm.ci.meta.JavaConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp)

Example 10 with FloatStamp

use of org.graalvm.compiler.core.common.type.FloatStamp in project graal by oracle.

the class PrimitiveStampBoundaryTest method checkUnaryOperation.

private static void checkUnaryOperation(ArithmeticOpTable.UnaryOp<?> op, Stamp result, Stamp v1stamp) {
    Stamp folded = op.foldStamp(v1stamp);
    Constant v1constant = v1stamp.asConstant();
    if (v1constant != null) {
        Constant constant = op.foldConstant(v1constant);
        if (constant != null) {
            Constant constant2 = folded.asConstant();
            if (constant2 == null && v1stamp instanceof FloatStamp) {
                JavaConstant c = (JavaConstant) constant;
                assertTrue((c.getJavaKind() == JavaKind.Double && Double.isNaN(c.asDouble())) || (c.getJavaKind() == JavaKind.Float && Float.isNaN(c.asFloat())));
            } else {
                assertTrue(constant2 != null, "should constant fold %s %s %s", op, v1stamp, folded);
                assertTrue(constant.equals(constant2), "should produce same constant %s %s %s %s", op, v1stamp, constant, constant2);
            }
        }
    } else {
        assertTrue(v1stamp.isEmpty() || v1stamp instanceof FloatStamp);
    }
    assertTrue(result.meet(folded).equals(result), "result out of range %s %s %s %s %s", op, v1stamp, folded, result, result.meet(folded));
}
Also used : PrimitiveStamp(org.graalvm.compiler.core.common.type.PrimitiveStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) Constant(jdk.vm.ci.meta.Constant) JavaConstant(jdk.vm.ci.meta.JavaConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp)

Aggregations

FloatStamp (org.graalvm.compiler.core.common.type.FloatStamp)14 ValueNode (org.graalvm.compiler.nodes.ValueNode)5 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)4 Stamp (org.graalvm.compiler.core.common.type.Stamp)3 ArrayList (java.util.ArrayList)2 Constant (jdk.vm.ci.meta.Constant)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 PrimitiveStamp (org.graalvm.compiler.core.common.type.PrimitiveStamp)2 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)2 Test (org.junit.Test)2 Parameters (org.junit.runners.Parameterized.Parameters)2 PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)1 AbstractObjectStamp (org.graalvm.compiler.core.common.type.AbstractObjectStamp)1 ArithmeticOpTable (org.graalvm.compiler.core.common.type.ArithmeticOpTable)1 Neg (org.graalvm.compiler.core.common.type.ArithmeticOpTable.UnaryOp.Neg)1 LogicNode (org.graalvm.compiler.nodes.LogicNode)1 NodeView (org.graalvm.compiler.nodes.NodeView)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)1 FloatDivNode (org.graalvm.compiler.nodes.calc.FloatDivNode)1