Skip to content

Commit

Permalink
Showing 2 changed files with 22 additions and 7 deletions.
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/bignum/left_shift_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -435,18 +435,36 @@ public Object bitXOr(DynamicObject a, DynamicObject b) {
@CoreMethod(names = "<<", required = 1, lowerFixnumParameters = 0)
public abstract static class LeftShiftNode extends BignumCoreMethodNode {

private final BranchProfile bLessThanZero = BranchProfile.create();
public abstract Object executeLeftShift(VirtualFrame frame, DynamicObject a, Object b);

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

@Specialization(guards = "isRubyBignum(b)")
public Object leftShift(VirtualFrame frame, DynamicObject a, DynamicObject b,
@Cached("create()") ToIntNode toIntNode) {
final BigInteger bBigInt = Layouts.BIGNUM.getValue(b);
if (bBigInt.signum() == -1) {
return 0;
} else {
// MRI would raise a NoMemoryError; JRuby would raise a coercion error.
return executeLeftShift(frame, a, toIntNode.doInt(frame, b));
}
}

@Specialization(guards = {"!isRubyBignum(b)", "!isInteger(b)", "!isLong(b)"})
public Object leftShift(VirtualFrame frame, DynamicObject a, Object b,
@Cached("create()") ToIntNode toIntNode) {
return executeLeftShift(frame, a, toIntNode.doInt(frame, b));
}

}

@CoreMethod(names = ">>", required = 1, lowerFixnumParameters = 0)

0 comments on commit 31e6aa4

Please sign in to comment.