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);
}
}
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));
}
}
Aggregations