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