Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 446a6c7b7523
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 359e7e8e290f
Choose a head ref
  • 2 commits
  • 7 files changed
  • 1 contributor

Commits on Apr 27, 2016

  1. Copy the full SHA
    a8ee987 View commit details
  2. [Truffle] Cleanup Bignum#>>.

    eregon committed Apr 27, 2016
    Copy the full SHA
    359e7e8 View commit details
29 changes: 14 additions & 15 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -240,7 +240,7 @@ public Object mulObjectCount(
} else {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
final int count = toIntNode.doInt(frame, object);
return executeMul(frame, array, count);
@@ -544,7 +544,7 @@ private DynamicObject readSlice(DynamicObject array, int start, int length) {
private int toInt(VirtualFrame frame, Object indexObject) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
return toIntNode.doInt(frame, indexObject);
}
@@ -561,8 +561,7 @@ public abstract static class AtNode extends CoreMethodNode {
@Child private ArrayReadDenormalizedNode readNode;

@CreateCast("index") public RubyNode coerceOtherToInt(RubyNode index) {
return FixnumLowerNodeGen.create(null, null,
ToIntNodeGen.create(null, null, index));
return FixnumLowerNodeGen.create(null, null, ToIntNodeGen.create(index));
}

@Specialization
@@ -752,7 +751,7 @@ public void checkFrozen(Object object) {
public abstract static class DeleteAtNode extends CoreMethodNode {

@CreateCast("index") public RubyNode coerceOtherToInt(RubyNode index) {
return ToIntNodeGen.create(null, null, index);
return ToIntNodeGen.create(index);
}

@Specialization(guards = "isEmptyArray(array)")
@@ -1051,7 +1050,7 @@ protected Object callToAry(VirtualFrame frame, Object object) {
protected int toInt(VirtualFrame frame, Object value) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
return toIntNode.doInt(frame, value);
}
@@ -1676,7 +1675,7 @@ public Object popNotEmpty(DynamicObject array, int n,
private int toInt(VirtualFrame frame, Object indexObject) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
return toIntNode.doInt(frame, indexObject);
}
@@ -2494,7 +2493,7 @@ public Object shiftNilWithNum(VirtualFrame frame, DynamicObject array, Object ob
} else {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
final int n = toIntNode.doInt(frame, object);
if (n < 0) {
@@ -2649,7 +2648,7 @@ public Object shiftObjectWithNum(VirtualFrame frame, DynamicObject array, int nu
public DynamicObject shiftIntegerFixnumInBoundsWithNumObj(VirtualFrame frame, DynamicObject array, Object object) throws UnexpectedResultException {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
final int num = toIntNode.doInt(frame, object);
if (num < 0) {
@@ -2674,7 +2673,7 @@ public DynamicObject shiftIntegerFixnumInBoundsWithNumObj(VirtualFrame frame, Dy
public Object shiftIntegerFixnumWithNumObj(VirtualFrame frame, DynamicObject array, Object object) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
final int num = toIntNode.doInt(frame, object);
if (num < 0) {
@@ -2699,7 +2698,7 @@ public Object shiftIntegerFixnumWithNumObj(VirtualFrame frame, DynamicObject arr
public DynamicObject shiftLongFixnumInBoundsWithNumObj(VirtualFrame frame, DynamicObject array, Object object) throws UnexpectedResultException {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
final int num = toIntNode.doInt(frame, object);
if (num < 0) {
@@ -2724,7 +2723,7 @@ public DynamicObject shiftLongFixnumInBoundsWithNumObj(VirtualFrame frame, Dynam
public Object shiftLongFixnumWithNumObj(VirtualFrame frame, DynamicObject array, Object object) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
final int num = toIntNode.doInt(frame, object);
if (num < 0) {
@@ -2748,7 +2747,7 @@ public Object shiftLongFixnumWithNumObj(VirtualFrame frame, DynamicObject array,
public DynamicObject shiftFloatInBoundsWithNumObj(VirtualFrame frame, DynamicObject array, Object object) throws UnexpectedResultException {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
final int num = toIntNode.doInt(frame, object);
if (num < 0) {
@@ -2773,7 +2772,7 @@ public DynamicObject shiftFloatInBoundsWithNumObj(VirtualFrame frame, DynamicObj
public Object shiftFloatWithNumObj(VirtualFrame frame, DynamicObject array, Object object) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
final int num = toIntNode.doInt(frame, object);
if (num < 0) {
@@ -2798,7 +2797,7 @@ public Object shiftFloatWithNumObj(VirtualFrame frame, DynamicObject array, Obje
public Object shiftObjectWithNumObj(VirtualFrame frame, DynamicObject array, Object object) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}
final int num = toIntNode.doInt(frame, object);
if (num < 0) {
Original file line number Diff line number Diff line change
@@ -83,8 +83,9 @@ public Object passThroughNotProvided(NotProvided value) {
}

@Specialization(guards = { "!isInteger(value)", "!isLong(value)", "!isDouble(value)", "!isRubyBignum(value)", "!isRubyRange(value)" })
public Object coerce(VirtualFrame frame, DynamicObject value, @Cached("create(getContext(), getSourceSection())") ToIntNode coerceToIntNode) {
return coerceToIntNode.executeIntOrLong(frame, value);
public Object coerce(VirtualFrame frame, DynamicObject value,
@Cached("create()") ToIntNode toIntNode) {
return toIntNode.executeIntOrLong(frame, value);
}

@Fallback
10 changes: 2 additions & 8 deletions truffle/src/main/java/org/jruby/truffle/core/cast/ToIntNode.java
Original file line number Diff line number Diff line change
@@ -15,8 +15,6 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.CoreLibrary;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.numeric.FloatNodes;
@@ -37,12 +35,8 @@ public abstract class ToIntNode extends RubyNode {
private final ConditionProfile wasLong = ConditionProfile.createBinaryProfile();
private final ConditionProfile wasLongInRange = ConditionProfile.createBinaryProfile();

public static ToIntNode create(RubyContext context, SourceSection sourceSection) {
return ToIntNodeGen.create(context, sourceSection, null);
}

public ToIntNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
public static ToIntNode create() {
return ToIntNodeGen.create(null);
}

public int doInt(VirtualFrame frame, Object object) {
Original file line number Diff line number Diff line change
@@ -16,22 +16,24 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.CoreClass;
import org.jruby.truffle.core.CoreLibrary;
import org.jruby.truffle.core.CoreMethod;
import org.jruby.truffle.core.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.UnaryCoreMethodNode;
import org.jruby.truffle.core.cast.BooleanCastNode;
import org.jruby.truffle.core.cast.BooleanCastNodeGen;
import org.jruby.truffle.core.cast.ToIntNode;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.SnippetNode;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;

import java.math.BigInteger;

@CoreClass(name = "Bignum")
@@ -452,24 +454,22 @@ public abstract static class RightShiftNode extends BignumCoreMethodNode {

public abstract Object executeRightShift(VirtualFrame frame, DynamicObject a, Object b);

private final BranchProfile bLessThanZero = BranchProfile.create();

@Specialization
public Object rightShift(DynamicObject a, int b) {
if (b >= 0) {
public Object rightShift(DynamicObject a, int b,
@Cached("createBinaryProfile()") ConditionProfile bPositive) {
if (bPositive.profile(b >= 0)) {
return fixnumOrBignum(Layouts.BIGNUM.getValue(a).shiftRight(b));
} else {
bLessThanZero.enter();
return fixnumOrBignum(Layouts.BIGNUM.getValue(a).shiftLeft(-b));
}
}

@Specialization
public Object rightShift(DynamicObject a, long b) {
if (b > Integer.MAX_VALUE || b < Integer.MIN_VALUE) {
return 0;
public Object rightShift(VirtualFrame frame, DynamicObject a, long b) {
if (CoreLibrary.fitsIntoInteger(b)) {
return executeRightShift(frame, a, (int) b);
} else {
return rightShift(a, (int) b);
return 0;
}
}

@@ -479,11 +479,9 @@ public int rightShift(DynamicObject a, DynamicObject b) {
}

@Specialization(guards = {"!isRubyBignum(b)", "!isInteger(b)", "!isLong(b)"})
public Object rightShift(VirtualFrame frame,
DynamicObject a,
Object b,
@Cached("new()") SnippetNode snippetNode) {
return executeRightShift(frame, a, snippetNode.execute(frame, "Rubinius::Type.coerce_to(y, Integer, :to_int)", "y", b));
public Object rightShift(VirtualFrame frame, DynamicObject a, Object b,
@Cached("create()") ToIntNode toIntNode) {
return executeRightShift(frame, a, toIntNode.doInt(frame, b));
}


Original file line number Diff line number Diff line change
@@ -233,7 +233,7 @@ public Object getIndexString(DynamicObject matchData, DynamicObject index, NotPr
public Object getIndex(VirtualFrame frame, DynamicObject matchData, Object index, NotProvided length) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}

return getIndex(matchData, toIntNode.doInt(frame, index), NotProvided.INSTANCE);
Original file line number Diff line number Diff line change
@@ -231,7 +231,7 @@ public DynamicObject multiply(DynamicObject string, DynamicObject times) {
public DynamicObject multiply(VirtualFrame frame, DynamicObject string, Object times) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}

return executeInt(frame, string, toIntNode.doInt(frame, times));
@@ -557,7 +557,7 @@ public Object slice2(VirtualFrame frame, DynamicObject string, DynamicObject mat
private ToIntNode getToIntNode() {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
toIntNode = insert(ToIntNode.create());
}

return toIntNode;
@@ -1274,7 +1274,7 @@ public InsertNode(RubyContext context, SourceSection sourceSection) {
}

@CreateCast("index") public RubyNode coerceIndexToInt(RubyNode index) {
return ToIntNodeGen.create(null, null, index);
return ToIntNodeGen.create(index);
}

@CreateCast("otherString") public RubyNode coerceOtherToString(RubyNode other) {
@@ -1738,13 +1738,11 @@ public SetByteNode(RubyContext context, SourceSection sourceSection) {
}

@CreateCast("index") public RubyNode coerceIndexToInt(RubyNode index) {
return FixnumLowerNodeGen.create(null, null,
ToIntNodeGen.create(null, null, index));
return FixnumLowerNodeGen.create(null, null, ToIntNodeGen.create(index));
}

@CreateCast("value") public RubyNode coerceValueToInt(RubyNode value) {
return FixnumLowerNodeGen.create(null, null,
ToIntNodeGen.create(null, null, value));
return FixnumLowerNodeGen.create(null, null, ToIntNodeGen.create(value));
}

@Specialization(guards = "!isRopeBuffer(string)")
Original file line number Diff line number Diff line change
@@ -1618,7 +1618,7 @@ public abstract static class GetIntegerConstantNode extends RubyNode {
public GetIntegerConstantNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readConstantNode = new ReadConstantNode(context, sourceSection, false, false, null, null);
toIntNode = ToIntNodeGen.create(context, sourceSection, null);
toIntNode = ToIntNode.create();
integerCastNode = IntegerCastNodeGen.create(context, sourceSection, null);
}