diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageFlags.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageFlags.java index 4327a17d0..c66906939 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageFlags.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageFlags.java @@ -8,6 +8,7 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; +import com.oracle.truffle.api.dsl.Idempotent; public final class SqueakImageFlags { private static final int PRIMITIVE_DO_MIXED_ARITHMETIC = 0x100; @@ -21,7 +22,7 @@ public void initialize(final long oldBaseAddressValue, final long flags, final l CompilerDirectives.transferToInterpreterAndInvalidate(); oldBaseAddress = oldBaseAddressValue; // TruffleSqueak only supports mixed arithmetics, unset bit to ensure flag is always true - headerFlags = flags & ~PRIMITIVE_DO_MIXED_ARITHMETIC; + headerFlags = flags; // & ~PRIMITIVE_DO_MIXED_ARITHMETIC; snapshotScreenSize = screenSize; maxExternalSemaphoreTableSize = lastMaxExternalSemaphoreTableSize; } @@ -55,4 +56,9 @@ public int getSnapshotScreenHeight() { public int getMaxExternalSemaphoreTableSize() { return maxExternalSemaphoreTableSize; } + + @Idempotent + public boolean isPrimitiveDoMixedArithmetic() { + return (headerFlags & PRIMITIVE_DO_MIXED_ARITHMETIC) == 0; + } } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/AbstractNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/AbstractNode.java index a47de7afa..96eac57c1 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/AbstractNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/AbstractNode.java @@ -6,6 +6,7 @@ */ package de.hpi.swa.trufflesqueak.nodes; +import com.oracle.truffle.api.dsl.Idempotent; import com.oracle.truffle.api.dsl.ImportStatic; import com.oracle.truffle.api.dsl.TypeSystemReference; import com.oracle.truffle.api.nodes.Node; @@ -49,7 +50,13 @@ protected final boolean isPoint(final PointersObject object) { return getContext().isPointClass(object.getSqueakClass()); } + @Idempotent + protected final boolean isPrimitiveDoMixedArithmetic() { + return getContext().flags.isPrimitiveDoMixedArithmetic(); + } + protected final boolean isSemaphore(final PointersObject object) { return getContext().isSemaphoreClass(object.getSqueakClass()); } + } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ArithmeticPrimitives.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ArithmeticPrimitives.java index 9d84d8b67..1901389cb 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ArithmeticPrimitives.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ArithmeticPrimitives.java @@ -65,7 +65,7 @@ protected static final Object doLongLargeInteger(final long lhs, final LargeInte return rhs.add(lhs); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final double doLongDouble(final long lhs, final double rhs) { return lhs + rhs; } @@ -96,7 +96,7 @@ protected static final Object doLongLargeInteger(final long lhs, final LargeInte return LargeIntegerObject.subtract(lhs, rhs); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final double doLongDouble(final long lhs, final double rhs) { return lhs - rhs; } @@ -122,14 +122,14 @@ protected static final boolean doLargeInteger(final long lhs, final LargeInteger return BooleanObject.wrap(rhs.compareTo(lhs) >= 0); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doDouble(final long lhs, final double rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, (double) lhs == rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return doLong(lhs, (long) rhs); } else { - return BooleanObject.wrap((double) lhs < rhs); + return BooleanObject.wrap(lhs < rhs); } } } @@ -147,14 +147,14 @@ protected static final boolean doLargeInteger(final long lhs, final LargeInteger return BooleanObject.wrap(rhs.compareTo(lhs) <= 0); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doDouble(final long lhs, final double rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, (double) lhs == rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return doLong(lhs, (long) rhs); } else { - return BooleanObject.wrap((double) lhs > rhs); + return BooleanObject.wrap(lhs > rhs); } } } @@ -172,14 +172,14 @@ protected static final boolean doLargeInteger(final long lhs, final LargeInteger return BooleanObject.wrap(rhs.compareTo(lhs) > 0); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doDouble(final long lhs, final double rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, (double) lhs == rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return doLong(lhs, (long) rhs); } else { - return BooleanObject.wrap((double) lhs <= rhs); + return BooleanObject.wrap(lhs <= rhs); } } } @@ -197,14 +197,14 @@ protected static final boolean doLargeInteger(final long lhs, final LargeInteger return BooleanObject.wrap(rhs.compareTo(lhs) < 0); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doDouble(final long lhs, final double rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, (double) lhs == rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return doLong(lhs, (long) rhs); } else { - return BooleanObject.wrap((double) lhs >= rhs); + return BooleanObject.wrap(lhs >= rhs); } } } @@ -222,11 +222,11 @@ protected static final boolean doLargeInteger(final long lhs, final LargeInteger return BooleanObject.wrap(rhs.compareTo(lhs) == 0); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doDouble(final long lhs, final double rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, (double) lhs == rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return doLong(lhs, (long) rhs); } else { return BooleanObject.FALSE; @@ -254,11 +254,11 @@ protected static final boolean doLargeInteger(final long lhs, final LargeInteger return BooleanObject.wrap(rhs.compareTo(lhs) != 0); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doDouble(final long lhs, final double rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, (double) lhs == rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return doLong(lhs, (long) rhs); } else { return BooleanObject.TRUE; @@ -291,12 +291,12 @@ protected static final Object doLongLargeInteger(final long lhs, final LargeInte return rhs.multiply(lhs); } - @Specialization(rewriteOn = RespecializeException.class) + @Specialization(guards = "isPrimitiveDoMixedArithmetic()", rewriteOn = RespecializeException.class) protected static final double doLongDoubleFinite(final long lhs, final double rhs) throws RespecializeException { return ensureFinite(lhs * rhs); } - @Specialization(replaces = "doLongDoubleFinite") + @Specialization(guards = "isPrimitiveDoMixedArithmetic()", replaces = "doLongDoubleFinite") protected static final Object doLongDouble(final long lhs, final double rhs, @Bind("this") final Node node, @Cached final AsFloatObjectIfNessaryNode boxNode) { @@ -330,12 +330,12 @@ protected final LargeIntegerObject doLongOverflow(final long lhs, final long rhs return LargeIntegerObject.createLongMinOverflowResult(getContext()); } - @Specialization(guards = {"!isZero(rhs)"}, rewriteOn = RespecializeException.class) + @Specialization(guards = {"isPrimitiveDoMixedArithmetic()", "!isZero(rhs)"}, rewriteOn = RespecializeException.class) protected static final double doLongDoubleFinite(final long lhs, final double rhs) throws RespecializeException { return ensureFinite(lhs / rhs); } - @Specialization(guards = {"!isZero(rhs)"}, replaces = "doLongDoubleFinite") + @Specialization(guards = {"isPrimitiveDoMixedArithmetic()", "!isZero(rhs)"}, replaces = "doLongDoubleFinite") protected static final Object doLongDouble(final long lhs, final double rhs, @Bind("this") final Node node, @Cached final AsFloatObjectIfNessaryNode boxNode) { @@ -831,15 +831,15 @@ protected static final boolean doFloat(final FloatObject lhs, final FloatObject return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final FloatObject lhsObject, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { final double lhs = lhsObject.getValue(); - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs < rhs); } else { - return BooleanObject.wrap(lhs < (double) rhs); + return BooleanObject.wrap(lhs < rhs); } } } @@ -857,15 +857,15 @@ protected static final boolean doFloat(final FloatObject lhs, final FloatObject return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final FloatObject lhsObject, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { final double lhs = lhsObject.getValue(); - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs > rhs); } else { - return BooleanObject.wrap(lhs > (double) rhs); + return BooleanObject.wrap(lhs > rhs); } } } @@ -883,15 +883,15 @@ protected static final boolean doFloat(final FloatObject lhs, final FloatObject return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final FloatObject lhsObject, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { final double lhs = lhsObject.getValue(); - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs <= rhs); } else { - return BooleanObject.wrap(lhs <= (double) rhs); + return BooleanObject.wrap(lhs <= rhs); } } } @@ -909,15 +909,15 @@ protected static final boolean doFloat(final FloatObject lhs, final FloatObject return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final FloatObject lhsObject, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { final double lhs = lhsObject.getValue(); - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs >= rhs); } else { - return BooleanObject.wrap(lhs >= (double) rhs); + return BooleanObject.wrap(lhs >= rhs); } } } @@ -935,12 +935,12 @@ protected static final boolean doFloat(final FloatObject lhs, final FloatObject return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final FloatObject lhsObject, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { final double lhs = lhsObject.getValue(); - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs == rhs); } else { return BooleanObject.FALSE; @@ -961,12 +961,12 @@ protected static final boolean doFloat(final FloatObject lhs, final FloatObject return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final FloatObject lhsObject, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { final double lhs = lhsObject.getValue(); - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs != rhs); } else { return BooleanObject.TRUE; @@ -1198,7 +1198,7 @@ protected static final double doDouble(final double lhs, final double rhs) { return lhs + rhs; } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final double doLong(final double lhs, final long rhs) { return doDouble(lhs, rhs); } @@ -1219,7 +1219,7 @@ protected static final double doDouble(final double lhs, final double rhs) { return lhs - rhs; } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final double doLong(final double lhs, final long rhs) { return doDouble(lhs, rhs); } @@ -1253,14 +1253,14 @@ protected static final boolean doFloat(final double lhs, final FloatObject rhs) return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final double lhs, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs < rhs); } else { - return doDouble(lhs, (double) rhs); + return doDouble(lhs, rhs); } } } @@ -1278,14 +1278,14 @@ protected static final boolean doFloat(final double lhs, final FloatObject rhs) return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final double lhs, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs > rhs); } else { - return doDouble(lhs, (double) rhs); + return doDouble(lhs, rhs); } } } @@ -1303,14 +1303,14 @@ protected static final boolean doFloat(final double lhs, final FloatObject rhs) return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final double lhs, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs <= rhs); } else { - return doDouble(lhs, (double) rhs); + return doDouble(lhs, rhs); } } } @@ -1328,14 +1328,14 @@ protected static final boolean doFloat(final double lhs, final FloatObject rhs) return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final double lhs, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs >= rhs); } else { - return doDouble(lhs, (double) rhs); + return doDouble(lhs, rhs); } } } @@ -1353,11 +1353,11 @@ protected static final boolean doFloat(final double lhs, final FloatObject rhs) return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final double lhs, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs == rhs); } else { return BooleanObject.FALSE; @@ -1378,11 +1378,11 @@ protected static final boolean doFloat(final double lhs, final FloatObject rhs) return doDouble(lhs, rhs.getValue()); } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final boolean doLong(final double lhs, final long rhs, @Bind("this") final Node node, @Cached final InlinedConditionProfile isExactProfile) { - if (isExactProfile.profile(node, lhs == (double) rhs)) { + if (isExactProfile.profile(node, lhs == rhs)) { return BooleanObject.wrap((long) lhs != rhs); } else { return BooleanObject.TRUE; @@ -1399,7 +1399,7 @@ protected static final double doDoubleFinite(final double lhs, final double rhs) return ensureFinite(lhs * rhs); } - @Specialization(rewriteOn = RespecializeException.class) + @Specialization(guards = "isPrimitiveDoMixedArithmetic()", rewriteOn = RespecializeException.class) protected static final double doLongFinite(final double lhs, final long rhs) throws RespecializeException { return doDoubleFinite(lhs, rhs); } @@ -1411,7 +1411,7 @@ protected static final Object doDouble(final double lhs, final double rhs, return boxNode.execute(node, lhs * rhs); } - @Specialization(replaces = "doLongFinite") + @Specialization(guards = "isPrimitiveDoMixedArithmetic()", replaces = "doLongFinite") protected static final Object doLong(final double lhs, final long rhs, @Bind("this") final Node node, @Shared("boxNode") @Cached final AsFloatObjectIfNessaryNode boxNode) { @@ -1435,7 +1435,7 @@ protected static final double doDoubleFinite(final double lhs, final double rhs) return ensureFinite(lhs / rhs); } - @Specialization(guards = "!isZero(rhs)", rewriteOn = RespecializeException.class) + @Specialization(guards = {"isPrimitiveDoMixedArithmetic()", "!isZero(rhs)"}, rewriteOn = RespecializeException.class) protected static final double doLongFinite(final double lhs, final long rhs) throws RespecializeException { return doDoubleFinite(lhs, rhs); } @@ -1447,7 +1447,7 @@ protected static final Object doDouble(final double lhs, final double rhs, return boxNode.execute(node, lhs / rhs); } - @Specialization(guards = "!isZero(rhs)", replaces = "doLongFinite") + @Specialization(guards = {"isPrimitiveDoMixedArithmetic()", "!isZero(rhs)"}, replaces = "doLongFinite") protected static final Object doLong(final double lhs, final long rhs, @Bind("this") final Node node, @Shared("boxNode") @Cached final AsFloatObjectIfNessaryNode boxNode) { @@ -1694,7 +1694,7 @@ protected static final double doDouble(final double value) { return value; } - @Specialization + @Specialization(guards = "isPrimitiveDoMixedArithmetic()") protected static final double doLong(final long value) { return value; } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java index ba29b1b39..515432b32 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/MiscellaneousPrimitives.java @@ -1013,7 +1013,7 @@ protected static final Object vmParameterAt(final SqueakImageContext image, fina case 71 -> 13L; // do mixed arithmetic; if false binary arithmetic primitives will fail unless // receiver and argument are of the same type - case 75 -> BooleanObject.TRUE; + case 75 -> image.flags.isPrimitiveDoMixedArithmetic(); default -> NilObject.SINGLETON; }; }