Search in sources :

Example 1 with FloatConvert

use of org.graalvm.compiler.core.common.calc.FloatConvert in project graal by oracle.

the class PrimitiveStampBoundaryTest method testFloatConvertBoundaryValues.

@Test
public void testFloatConvertBoundaryValues() {
    for (FloatConvert op : EnumSet.allOf(FloatConvert.class)) {
        ArithmeticOpTable.FloatConvertOp floatConvert = IntegerStamp.OPS.getFloatConvert(op);
        if (floatConvert == null) {
            continue;
        }
        assert op.getCategory() == FloatConvertCategory.IntegerToFloatingPoint : op;
        testConvertBoundaryValues(floatConvert, op.getInputBits(), integerTestStamps);
    }
    for (FloatConvert op : EnumSet.allOf(FloatConvert.class)) {
        ArithmeticOpTable.FloatConvertOp floatConvert = FloatStamp.OPS.getFloatConvert(op);
        if (floatConvert == null) {
            continue;
        }
        assert op.getCategory() == FloatConvertCategory.FloatingPointToInteger || op.getCategory() == FloatConvertCategory.FloatingPointToFloatingPoint : op;
        testConvertBoundaryValues(floatConvert, op.getInputBits(), floatTestStamps);
    }
}
Also used : ArithmeticOpTable(org.graalvm.compiler.core.common.type.ArithmeticOpTable) FloatConvert(org.graalvm.compiler.core.common.calc.FloatConvert) Test(org.junit.Test) GraalTest(org.graalvm.compiler.test.GraalTest)

Example 2 with FloatConvert

use of org.graalvm.compiler.core.common.calc.FloatConvert in project graal by oracle.

the class CInterfaceInvocationPlugin method adaptPrimitiveType.

static ValueNode adaptPrimitiveType(StructuredGraph graph, ValueNode value, JavaKind fromKind, JavaKind toKind, boolean isUnsigned) {
    if (fromKind == toKind) {
        return value;
    }
    assert fromKind.isNumericFloat() == toKind.isNumericFloat();
    int fromBits = fromKind.getBitCount();
    int toBits = toKind.getBitCount();
    if (fromBits == toBits) {
        return value;
    } else if (fromKind.isNumericFloat()) {
        FloatConvert op;
        if (fromKind == JavaKind.Float && toKind == JavaKind.Double) {
            op = FloatConvert.F2D;
        } else if (fromKind == JavaKind.Double && toKind == JavaKind.Float) {
            op = FloatConvert.D2F;
        } else {
            throw shouldNotReachHere();
        }
        return graph.unique(new FloatConvertNode(op, value));
    } else if (toKind == JavaKind.Boolean) {
        JavaKind computeKind = fromKind == JavaKind.Long ? JavaKind.Long : JavaKind.Int;
        LogicNode comparison = graph.unique(new IntegerEqualsNode(adaptPrimitiveType(graph, value, fromKind, computeKind, true), ConstantNode.forIntegerKind(computeKind, 0, graph)));
        return graph.unique(new ConditionalNode(comparison, ConstantNode.forBoolean(false, graph), ConstantNode.forBoolean(true, graph)));
    } else if (fromBits > toBits) {
        return graph.unique(new NarrowNode(value, toBits));
    } else if (isUnsigned) {
        return graph.unique(new ZeroExtendNode(value, toBits));
    } else {
        return graph.unique(new SignExtendNode(value, toBits));
    }
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) FloatConvert(org.graalvm.compiler.core.common.calc.FloatConvert) LogicNode(org.graalvm.compiler.nodes.LogicNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

FloatConvert (org.graalvm.compiler.core.common.calc.FloatConvert)2 JavaKind (jdk.vm.ci.meta.JavaKind)1 ArithmeticOpTable (org.graalvm.compiler.core.common.type.ArithmeticOpTable)1 LogicNode (org.graalvm.compiler.nodes.LogicNode)1 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)1 FloatConvertNode (org.graalvm.compiler.nodes.calc.FloatConvertNode)1 IntegerEqualsNode (org.graalvm.compiler.nodes.calc.IntegerEqualsNode)1 NarrowNode (org.graalvm.compiler.nodes.calc.NarrowNode)1 SignExtendNode (org.graalvm.compiler.nodes.calc.SignExtendNode)1 ZeroExtendNode (org.graalvm.compiler.nodes.calc.ZeroExtendNode)1 GraalTest (org.graalvm.compiler.test.GraalTest)1 Test (org.junit.Test)1