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: 7457dde76699
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c7c9e3044345
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Dec 2, 2015

  1. [Truffle] Clean up Fixnum#{<<,>>}.

    * Proper types, no transfer, lower the rhs before the node.
    eregon committed Dec 2, 2015
    Copy the full SHA
    f91a591 View commit details
  2. Copy the full SHA
    c7c9e30 View commit details
Showing with 9 additions and 23 deletions.
  1. +9 −23 truffle/src/main/java/org/jruby/truffle/nodes/core/fixnum/FixnumNodes.java
Original file line number Diff line number Diff line change
@@ -833,7 +833,7 @@ public Object bitXOr(VirtualFrame frame, Object a, DynamicObject b) {

}

@CoreMethod(names = "<<", required = 1, lowerFixnumParameters = 0)
@CoreMethod(names = "<<", required = 1, lowerFixnumParameters = { 0, 1 })
public abstract static class LeftShiftNode extends BignumNodes.BignumCoreMethodNode {

@Child private RightShiftNode rightShiftNode;
@@ -850,11 +850,6 @@ public int leftShift(int a, int b) {
return a << b;
}

@Specialization(guards = { "b >= 0", "canShiftIntoInt(a, b)" })
public int leftShift(int a, long b) {
return a << b;
}

@Specialization(guards = { "b >= 0", "canShiftIntoLong(a, b)" })
public long leftShiftToLong(long a, int b) {
return a << b;
@@ -891,17 +886,13 @@ static boolean canShiftIntoInt(int a, int b) {
return Integer.numberOfLeadingZeros(a) - b > 0;
}

static boolean canShiftIntoInt(int a, long b) {
return Integer.numberOfLeadingZeros(a) - b > 0;
}

static boolean canShiftIntoLong(long a, int b) {
return Long.numberOfLeadingZeros(a) - b > 0;
}

}

@CoreMethod(names = ">>", required = 1, lowerFixnumParameters = 0)
@CoreMethod(names = ">>", required = 1, lowerFixnumParameters = { 0, 1 })
public abstract static class RightShiftNode extends CoreMethodArrayArgumentsNode {

@Child private CallDispatchHeadNode fallbackCallNode;
@@ -914,16 +905,7 @@ public RightShiftNode(RubyContext context, SourceSection sourceSection) {
public abstract Object executeRightShift(VirtualFrame frame, Object a, Object b);

@Specialization(guards = "b >= 0")
public Object rightShift(VirtualFrame frame, int a, int b) {
if (b >= Integer.SIZE - 1) {
return a < 0 ? -1 : 0;
} else {
return a >> b;
}
}

@Specialization(guards = "b >= 0")
public Object rightShift(VirtualFrame frame, int a, long b) {
public int rightShift(VirtualFrame frame, int a, int b) {
if (b >= Integer.SIZE - 1) {
return a < 0 ? -1 : 0;
} else {
@@ -932,7 +914,7 @@ public Object rightShift(VirtualFrame frame, int a, long b) {
}

@Specialization(guards = "b >= 0")
public Object rightShift(VirtualFrame frame, long a, int b) {
public long rightShift(VirtualFrame frame, long a, int b) {
if (b >= Long.SIZE - 1) {
return a < 0 ? -1 : 0;
} else {
@@ -949,6 +931,11 @@ public Object rightShiftNeg(VirtualFrame frame, long a, int b) {
return leftShiftNode.executeLeftShift(frame, a, -b);
}

@Specialization(guards = "b >= 0")
public int rightShift(long a, long b) { // b is not in int range due to lowerFixnumParameters
return 0;
}

@Specialization(guards = { "isRubyBignum(b)", "isPositive(b)" })
public int rightShift(long a, DynamicObject b) {
return 0;
@@ -960,7 +947,6 @@ public Object rightShiftNeg(VirtualFrame frame, long a, DynamicObject b) {
CompilerDirectives.transferToInterpreter();
leftShiftNode = insert(FixnumNodesFactory.LeftShiftNodeFactory.create(getContext(), getSourceSection(), new RubyNode[] { null, null }));
}
CompilerDirectives.transferToInterpreter();
return leftShiftNode.executeLeftShift(frame, a, Layouts.BIGNUM.getValue(b).negate());
}