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

Commits on Dec 3, 2015

  1. [Truffle] Lower parameters to int or let the implicit cast to long.

    * Fixes lowerFixnumParameters on shift nodes.
    eregon committed Dec 3, 2015
    Copy the full SHA
    f01511d View commit details
  2. [Truffle] Do not contain other specializations in Fixnum#&.

    * Otherwise it gets to long in all cases in pure interpreter.
    eregon committed Dec 3, 2015
    Copy the full SHA
    92288e6 View commit details
  3. Copy the full SHA
    5a5fe17 View commit details
  4. Copy the full SHA
    4168709 View commit details
  5. [Truffle] Make sure the @Mask is a int in the Fixnum#& spec.

    * Since in interpreter nodes are not split, either of the two operations might return long.
    eregon committed Dec 3, 2015
    Copy the full SHA
    f2f03cd View commit details
2 changes: 1 addition & 1 deletion spec/truffle/specs/truffle/fixnum/and_spec.rb
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
describe "Fixnum#&" do
before :each do
@long = (1 << 48) + 1
@mask = (1 << 30) - 1
@mask = Truffle::Primitive.fixnum_lower((1 << 30) - 1)
end

it "returns an int for (int, int)" do
Original file line number Diff line number Diff line change
@@ -12,12 +12,15 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.ExactMath;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.jcodings.specific.USASCIIEncoding;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.*;
@@ -28,6 +31,7 @@
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.CoreLibrary;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.StringSupport;
@@ -770,7 +774,7 @@ public int bitAndLongInt(long a, int b) {
return (int) (a & b);
}

@Specialization(contains = { "bitAndIntInt", "bitAndIntLong", "bitAndLongInt" })
@Specialization
public long bitAndLongLong(long a, long b) {
return a & b;
}
@@ -833,7 +837,7 @@ public Object bitXOr(VirtualFrame frame, Object a, DynamicObject b) {

}

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

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

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

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

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

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

}

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

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

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

@Specialization(guards = "b >= 0")
public long rightShift(VirtualFrame frame, long a, int b) {
if (b >= Long.SIZE - 1) {
return a < 0 ? -1 : 0;
public Object rightShift(VirtualFrame frame, long a, int b,
@Cached("createBinaryProfile()") ConditionProfile profile) {
if (profile.profile(b >= Long.SIZE - 1)) {
return a < 0 ? -1 : 0; // int
} else {
return a >> b;
return a >> b; // long
}
}

@@ -933,6 +948,7 @@ public Object rightShiftNeg(VirtualFrame frame, long a, int b) {

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

Original file line number Diff line number Diff line change
@@ -149,7 +149,7 @@ private void newOpenFd(int newFd) {
}
}

@RubiniusPrimitive(name = "io_open", needsSelf = false)
@RubiniusPrimitive(name = "io_open", needsSelf = false, lowerFixnumParameters = { 1, 2 })
public static abstract class IOOpenPrimitiveNode extends RubiniusPrimitiveNode {

public IOOpenPrimitiveNode(RubyContext context, SourceSection sourceSection) {
@@ -171,11 +171,6 @@ public IOTruncatePrimitiveNode(RubyContext context, SourceSection sourceSection)
super(context, sourceSection);
}

@Specialization(guards = "isRubyString(path)")
public int truncate(DynamicObject path, int length) {
return truncate(path, (long) length);
}

@Specialization(guards = "isRubyString(path)")
public int truncate(DynamicObject path, long length) {
final int result = posix().truncate(StringOperations.getString(getContext(), path), length);
@@ -195,11 +190,6 @@ public IOFTruncatePrimitiveNode(RubyContext context, SourceSection sourceSection
super(context, sourceSection);
}

@Specialization
public int ftruncate(VirtualFrame frame, DynamicObject io, int length) {
return ftruncate(frame, io, (long) length);
}

@Specialization
public int ftruncate(VirtualFrame frame, DynamicObject io, long length) {
final int fd = Layouts.IO.getDescriptor(io);
@@ -346,7 +336,7 @@ public Object reopen(VirtualFrame frame, DynamicObject file, DynamicObject io) {

}

@RubiniusPrimitive(name = "io_reopen_path")
@RubiniusPrimitive(name = "io_reopen_path", lowerFixnumParameters = 1)
public static abstract class IOReopenPathPrimitiveNode extends RubiniusPrimitiveNode {

@Child private CallDispatchHeadNode resetBufferingNode;
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ public boolean fixedEncoding(DynamicObject regexp) {

}

@RubiniusPrimitive(name = "regexp_initialize")
@RubiniusPrimitive(name = "regexp_initialize", lowerFixnumParameters = 1)
@ImportStatic(RegexpGuards.class)
public static abstract class RegexpInitializePrimitiveNode extends RubiniusPrimitiveNode {