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

Commits on May 27, 2015

  1. Copy the full SHA
    4d4ffdd View commit details
  2. [Truffle] Remove some extra FixnumNodes specializations.

    * The (int,Bignum) creating a BigInteger out of the int.
    * The (int,*) just calling a method taking longs.
    eregon committed May 27, 2015
    3
    Copy the full SHA
    f48a2eb View commit details
  3. Copy the full SHA
    c868823 View commit details
  4. [Truffle] Remove some extra FixnumNodes specializations.

    * The (Bignum,int) creating a BigInteger out of the int.
    eregon committed May 27, 2015
    Copy the full SHA
    2ce76a5 View commit details
99 changes: 18 additions & 81 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/BignumNodes.java
Original file line number Diff line number Diff line change
@@ -96,11 +96,6 @@ public AddNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public Object add(RubyBasicObject a, int b) {
return fixnumOrBignum(getBigIntegerValue(a).add(BigInteger.valueOf(b)));
}

@Specialization
public Object add(RubyBasicObject a, long b) {
return fixnumOrBignum(getBigIntegerValue(a).add(BigInteger.valueOf(b)));
@@ -125,11 +120,6 @@ public SubNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public Object sub(RubyBasicObject a, int b) {
return fixnumOrBignum(getBigIntegerValue(a).subtract(BigInteger.valueOf(b)));
}

@Specialization
public Object sub(RubyBasicObject a, long b) {
return fixnumOrBignum(getBigIntegerValue(a).subtract(BigInteger.valueOf(b)));
@@ -154,12 +144,6 @@ public MulNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@TruffleBoundary
@Specialization
public Object mul(RubyBasicObject a, int b) {
return fixnumOrBignum(getBigIntegerValue(a).multiply(BigInteger.valueOf(b)));
}

@TruffleBoundary
@Specialization
public Object mul(RubyBasicObject a, long b) {
@@ -186,11 +170,6 @@ public DivNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public Object div(RubyBasicObject a, int b) {
return fixnumOrBignum(getBigIntegerValue(a).divide(BigInteger.valueOf(b)));
}

@Specialization
public Object div(RubyBasicObject a, long b) {
return fixnumOrBignum(getBigIntegerValue(a).divide(BigInteger.valueOf(b)));
@@ -215,18 +194,6 @@ public ModNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public Object mod(RubyBasicObject a, int b) {
if (b == 0) {
throw new ArithmeticException("divide by zero");
} else if (b < 0) {
final BigInteger bigint = BigInteger.valueOf(b);
final BigInteger mod = getBigIntegerValue(a).mod(bigint.negate());
return fixnumOrBignum(mod.add(bigint));
}
return fixnumOrBignum(getBigIntegerValue(a).mod(BigInteger.valueOf(b)));
}

@Specialization
public Object mod(RubyBasicObject a, long b) {
if (b == 0) {
@@ -266,11 +233,6 @@ public LessNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public boolean less(RubyBasicObject a, int b) {
return getBigIntegerValue(a).compareTo(BigInteger.valueOf(b)) < 0;
}

@Specialization
public boolean less(RubyBasicObject a, long b) {
return getBigIntegerValue(a).compareTo(BigInteger.valueOf(b)) < 0;
@@ -300,11 +262,6 @@ public LessEqualNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public boolean lessEqual(RubyBasicObject a, int b) {
return getBigIntegerValue(a).compareTo(BigInteger.valueOf(b)) <= 0;
}

@Specialization
public boolean lessEqual(RubyBasicObject a, long b) {
return getBigIntegerValue(a).compareTo(BigInteger.valueOf(b)) <= 0;
@@ -333,12 +290,12 @@ public EqualNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public boolean equal(RubyBasicObject a, int b) {
return getBigIntegerValue(a).equals(BigInteger.valueOf(b));
return false;
}

@Specialization
public boolean equal(RubyBasicObject a, long b) {
return getBigIntegerValue(a).equals(BigInteger.valueOf(b));
return false;
}

@Specialization
@@ -378,11 +335,6 @@ public CompareNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public int compare(RubyBasicObject a, int b) {
return getBigIntegerValue(a).compareTo(BigInteger.valueOf(b));
}

@Specialization
public int compare(RubyBasicObject a, long b) {
return getBigIntegerValue(a).compareTo(BigInteger.valueOf(b));
@@ -410,11 +362,6 @@ public GreaterEqualNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public boolean greaterEqual(RubyBasicObject a, int b) {
return getBigIntegerValue(a).compareTo(BigInteger.valueOf(b)) >= 0;
}

@Specialization
public boolean greaterEqual(RubyBasicObject a, long b) {
return getBigIntegerValue(a).compareTo(BigInteger.valueOf(b)) >= 0;
@@ -438,11 +385,6 @@ public GreaterNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public boolean greater(RubyBasicObject a, int b) {
return getBigIntegerValue(a).compareTo(BigInteger.valueOf(b)) > 0;
}

@Specialization
public boolean greater(RubyBasicObject a, long b) {
return getBigIntegerValue(a).compareTo(BigInteger.valueOf(b)) > 0;
@@ -466,11 +408,6 @@ public BitAndNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public Object bitAnd(RubyBasicObject a, int b) {
return fixnumOrBignum(getBigIntegerValue(a).and(BigInteger.valueOf(b)));
}

@Specialization
public Object bitAnd(RubyBasicObject a, long b) {
return fixnumOrBignum(getBigIntegerValue(a).and(BigInteger.valueOf(b)));
@@ -489,11 +426,6 @@ public BitOrNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public Object bitOr(RubyBasicObject a, int b) {
return fixnumOrBignum(getBigIntegerValue(a).or(BigInteger.valueOf(b)));
}

@Specialization
public Object bitOr(RubyBasicObject a, long b) {
return fixnumOrBignum(getBigIntegerValue(a).or(BigInteger.valueOf(b)));
@@ -512,11 +444,6 @@ public BitXOrNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public Object bitXOr(RubyBasicObject a, int b) {
return fixnumOrBignum(getBigIntegerValue(a).xor(BigInteger.valueOf(b)));
}

@Specialization
public Object bitXOr(RubyBasicObject a, long b) {
return fixnumOrBignum(getBigIntegerValue(a).xor(BigInteger.valueOf(b)));
@@ -645,11 +572,6 @@ public DivModNode(RubyContext context, SourceSection sourceSection) {
divModNode = new GeneralDivModNode(context, sourceSection);
}

@Specialization
public RubyArray divMod(RubyBasicObject a, int b) {
return divModNode.execute(getBigIntegerValue(a), b);
}

@Specialization
public RubyArray divMod(RubyBasicObject a, long b) {
return divModNode.execute(getBigIntegerValue(a), b);
@@ -672,7 +594,7 @@ public EvenNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization
public boolean even(RubyBasicObject value) {
return getBigIntegerValue(value).getLowestSetBit() != 0;
return !getBigIntegerValue(value).testBit(0);
}

}
@@ -691,6 +613,21 @@ public int hash(RubyBasicObject value) {

}

@CoreMethod(names = "odd?")
public abstract static class OddNode extends BignumCoreMethodNode {

public OddNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public boolean odd(RubyBasicObject value) {
return getBigIntegerValue(value).testBit(0);
}

}

@CoreMethod(names = "size")
public abstract static class SizeNode extends CoreMethodArrayArgumentsNode {

Original file line number Diff line number Diff line change
@@ -9,16 +9,16 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;

import java.math.BigInteger;

@@ -40,26 +40,10 @@ public GeneralDivModNode(RubyContext context, SourceSection sourceSection) {
fixnumOrBignumRemainder = new FixnumOrBignumNode(context, sourceSection);
}

public RubyArray execute(int a, int b) {
return divMod(a, b);
}

public RubyArray execute(int a, long b) {
return divMod(a, b);
}

public RubyArray execute(int a, BigInteger b) {
return divMod(BigInteger.valueOf(a), b);
}

public RubyArray execute(int a, double b) {
return divMod(a, b);
}

public RubyArray execute(long a, int b) {
return divMod(a, b);
}

public RubyArray execute(long a, long b) {
return divMod(a, b);
}
@@ -72,10 +56,6 @@ public RubyArray execute(long a, double b) {
return divMod(a, b);
}

public RubyArray execute(BigInteger a, int b) {
return divMod(a, BigInteger.valueOf(b));
}

public RubyArray execute(BigInteger a, long b) {
return divMod(a, BigInteger.valueOf(b));
}
@@ -105,7 +85,7 @@ public RubyArray execute(double a, double b) {
* and contributors there.
*/

@CompilerDirectives.TruffleBoundary
@TruffleBoundary
private RubyArray divMod(long a, long b) {
if (b == 0) {
bZeroProfile.enter();
@@ -148,7 +128,7 @@ private RubyArray divMod(long a, long b) {
}
}

@CompilerDirectives.TruffleBoundary
@TruffleBoundary
private RubyArray divMod(double a, double b) {
if (b == 0) {
bZeroProfile.enter();
@@ -173,7 +153,7 @@ private RubyArray divMod(double a, double b) {
mod}, 2);
}

@CompilerDirectives.TruffleBoundary
@TruffleBoundary
private RubyArray divMod(BigInteger a, BigInteger b) {
if (b.signum() == 0) {
bZeroProfile.enter();
Loading