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

Commits on Dec 3, 2015

  1. [Truffle] Use ConditionProfile in FixnumOrBignumNode.

    * May also omit the BigInteger case in compiled code now.
    eregon committed Dec 3, 2015
    Copy the full SHA
    1dacc10 View commit details
  2. Copy the full SHA
    4dc9ffd View commit details
Showing with 16 additions and 27 deletions.
  1. +16 −27 truffle/src/main/java/org/jruby/truffle/nodes/core/FixnumOrBignumNode.java
Original file line number Diff line number Diff line change
@@ -12,16 +12,21 @@
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 com.oracle.truffle.api.utilities.ConditionProfile;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.CoreLibrary;
import org.jruby.truffle.runtime.layouts.Layouts;

import java.math.BigDecimal;
import java.math.BigInteger;

public class FixnumOrBignumNode extends RubyNode {

private static final BigInteger LONG_MIN_BIGINT = BigInteger.valueOf(Long.MIN_VALUE);
private static final BigInteger LONG_MAX_BIGINT = BigInteger.valueOf(Long.MAX_VALUE);

public static FixnumOrBignumNode create(RubyContext context, SourceSection sourceSection) {
return new FixnumOrBignumNode(context, sourceSection);
}
@@ -30,27 +35,19 @@ public FixnumOrBignumNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

private final BranchProfile lowerProfile = BranchProfile.create();
private final BranchProfile integerFromBignumProfile = BranchProfile.create();
private final BranchProfile longFromBignumProfile = BranchProfile.create();

private final BranchProfile integerFromDoubleProfile = BranchProfile.create();
private final BranchProfile longFromDoubleProfile = BranchProfile.create();
private final ConditionProfile lowerProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile intProfile = ConditionProfile.createBinaryProfile();

private final BranchProfile bignumProfile = BranchProfile.create();
private final BranchProfile checkLongProfile = BranchProfile.create();
private final ConditionProfile integerFromDoubleProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile longFromDoubleProfile = ConditionProfile.createBinaryProfile();

public Object fixnumOrBignum(BigInteger value) {
if (value.compareTo(BigInteger.valueOf(Long.MIN_VALUE)) >= 0 && value.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) <= 0) {
lowerProfile.enter();

if (lowerProfile.profile(value.compareTo(LONG_MIN_BIGINT) >= 0 && value.compareTo(LONG_MAX_BIGINT) <= 0)) {
final long longValue = value.longValue();

if (longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE) {
integerFromBignumProfile.enter();
if (intProfile.profile(CoreLibrary.fitsIntoInteger(longValue))) {
return (int) longValue;
} else {
longFromBignumProfile.enter();
return longValue;
}
} else {
@@ -59,21 +56,13 @@ public Object fixnumOrBignum(BigInteger value) {
}

public Object fixnumOrBignum(double value) {
if (value > Integer.MIN_VALUE && value < Integer.MAX_VALUE) {
integerFromDoubleProfile.enter();
if (integerFromDoubleProfile.profile(value > Integer.MIN_VALUE && value < Integer.MAX_VALUE)) {
return (int) value;
}

checkLongProfile.enter();

if (value > Long.MIN_VALUE && value < Long.MAX_VALUE) {
longFromDoubleProfile.enter();
} else if (longFromDoubleProfile.profile(value > Long.MIN_VALUE && value < Long.MAX_VALUE)) {
return (long) value;
} else {
return fixnumOrBignum(doubleToBigInteger(value));
}

bignumProfile.enter();

return fixnumOrBignum(doubleToBigInteger(value));
}

@TruffleBoundary