Skip to content

Commit

Permalink
Simplify two fallback guards
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Oct 20, 2024
1 parent c63185a commit 04c454d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import de.hpi.swa.trufflesqueak.model.NativeObject;
import de.hpi.swa.trufflesqueak.model.NilObject;
import de.hpi.swa.trufflesqueak.model.PointersObject;
import de.hpi.swa.trufflesqueak.nodes.SqueakGuards;
import de.hpi.swa.trufflesqueak.nodes.accessing.AbstractPointersObjectNodes;
import de.hpi.swa.trufflesqueak.nodes.primitives.AbstractPrimitiveFactoryHolder;
import de.hpi.swa.trufflesqueak.nodes.primitives.AbstractPrimitiveNode;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.BinaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.TernaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.UnaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.SqueakPrimitive;

Expand Down Expand Up @@ -80,7 +80,7 @@ protected static final double doAt(final NativeObject receiver, final long index

@GenerateNodeFactory
@SqueakPrimitive(names = "primitiveAtPut")
public abstract static class PrimFloat64ArrayAtPutNode extends AbstractPrimitiveNode implements TernaryPrimitiveFallback {
public abstract static class PrimFloat64ArrayAtPutNode extends AbstractPrimitiveNode {

@Specialization(guards = {"receiver.isLongType()", "index <= receiver.getLongLength()"})
protected static final double doDouble(final NativeObject receiver, final long index, final double value) {
Expand All @@ -104,6 +104,18 @@ protected static final double doFraction(final NativeObject receiver, final long
@Cached final AbstractPointersObjectNodes.AbstractPointersObjectReadNode readNode) {
return doDouble(receiver, index, getContext(node).fromFraction(value, readNode, node));
}

@SuppressWarnings("unused")
@Specialization(guards = "isFallback(node, receiver, index, value)")
protected static final Object doFail(final NativeObject receiver, final long index, final Object value,
@Bind("this") final Node node) {
throw PrimitiveFailed.GENERIC_ERROR;
}

protected static final boolean isFallback(final Node node, final NativeObject receiver, final long index, final Object value) {
return !(receiver.isIntType() && index <= receiver.getIntLength() && (value instanceof Double || value instanceof FloatObject || value instanceof Long ||
(value instanceof PointersObject pointersObject && SqueakGuards.isFraction(pointersObject, node))));
}
}

@GenerateNodeFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import de.hpi.swa.trufflesqueak.model.NativeObject;
import de.hpi.swa.trufflesqueak.model.NilObject;
import de.hpi.swa.trufflesqueak.model.PointersObject;
import de.hpi.swa.trufflesqueak.nodes.SqueakGuards;
import de.hpi.swa.trufflesqueak.nodes.accessing.AbstractPointersObjectNodes;
import de.hpi.swa.trufflesqueak.nodes.primitives.AbstractPrimitiveFactoryHolder;
import de.hpi.swa.trufflesqueak.nodes.primitives.AbstractPrimitiveNode;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.BinaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.TernaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.UnaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.SqueakPrimitive;

Expand Down Expand Up @@ -81,7 +81,7 @@ protected static final double doAt(final NativeObject receiver, final long index

@GenerateNodeFactory
@SqueakPrimitive(names = "primitiveAtPut")
public abstract static class PrimFloatArrayAtPutNode extends AbstractPrimitiveNode implements TernaryPrimitiveFallback {
public abstract static class PrimFloatArrayAtPutNode extends AbstractPrimitiveNode {

@Specialization(guards = {"receiver.isIntType()", "index <= receiver.getIntLength()"})
protected static final double doDouble(final NativeObject receiver, final long index, final double value) {
Expand All @@ -105,6 +105,18 @@ protected static final double doFraction(final NativeObject receiver, final long
@Cached final AbstractPointersObjectNodes.AbstractPointersObjectReadNode readNode) {
return doDouble(receiver, index, getContext(node).fromFraction(value, readNode, node));
}

@SuppressWarnings("unused")
@Specialization(guards = "isFallback(node, receiver, index, value)")
protected static final Object doFail(final NativeObject receiver, final long index, final Object value,
@Bind("this") final Node node) {
throw PrimitiveFailed.GENERIC_ERROR;
}

protected static final boolean isFallback(final Node node, final NativeObject receiver, final long index, final Object value) {
return !(receiver.isIntType() && index <= receiver.getIntLength() && (value instanceof Double || value instanceof FloatObject || value instanceof Long ||
(value instanceof PointersObject pointersObject && SqueakGuards.isFraction(pointersObject, node))));
}
}

@GenerateNodeFactory
Expand Down

1 comment on commit 04c454d

@TruffleSqueak-Bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance Report (04c454d)

Benchmarks ran on 22.0.2-graal.

Steady (after 100 iterations)

Benchmark Name Min Geomean Median Mean Max Total (ms) Total (min)
Bounce 519 533 521.69 520 521.68 104338 1.74
CD 484 670 591.78 598 591.2 118356 1.97
DeltaBlue 304 771 609.55 639.5 600.94 121911 2.03
Havlak 1125 1176 1151.79 1153 1151.72 230357 3.84
Json 411 467 440.65 440 440.58 88130 1.47
List 307 321 308.44 308 308.43 61688 1.03
Mandelbrot 127 137 127.81 128 127.8 25562 0.43
NBody 261 350 281.87 280 281.68 56373 0.94
Permute 155 167 155.7 155 155.69 31140 0.52
Queens 230 243 232.39 232 232.38 46477 0.77
Richards 1243 1261 1247.89 1248 1247.88 249578 4.16
Sieve 178 201 182.33 181.5 182.28 36465 0.61
Storage 141 151 143.5 142 143.48 28700 0.48
Towers 198 215 200.25 200 200.23 40049 0.67
5683 6663 6195.62 6225 6185.98 1239124 20.65

04c454d-2-steady.svg

Warmup (first 100 iterations)

04c454d-3-warmup.svg

Please sign in to comment.