use of jdk.vm.ci.meta.JavaConstant 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 jdk.vm.ci.meta.JavaConstant 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));
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class NegateNodeCanonicalizationTest method testChar.
@Test
public void testChar() {
char[] a = new char[] { Character.MIN_VALUE, Character.MIN_VALUE + 1, 0, 1, Character.MAX_VALUE - 1, Character.MAX_VALUE };
for (char i : a) {
ConstantNode node = ConstantNode.forChar(i, graph);
JavaConstant expected = JavaConstant.forInt(-i);
assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
}
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class NegateNodeCanonicalizationTest method testInt.
@Test
public void testInt() {
int[] a = new int[] { Integer.MIN_VALUE, Integer.MIN_VALUE + 1, -1, 0, 1, Integer.MAX_VALUE - 1, Integer.MAX_VALUE };
for (int i : a) {
ConstantNode node = ConstantNode.forInt(i, graph);
JavaConstant expected = JavaConstant.forInt(-i);
assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
}
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class NegateNodeCanonicalizationTest method testFloat.
@Test
public void testFloat() {
float[] a = new float[] { Float.MIN_VALUE, Float.MIN_VALUE + 1, -1, 0, 1, Float.MAX_VALUE - 1, Float.MAX_VALUE };
for (float i : a) {
ConstantNode node = ConstantNode.forFloat(i, graph);
JavaConstant expected = JavaConstant.forFloat(-i);
assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
}
}
Aggregations