Bug 1015498 - Implement MFloor::computeRange using new Range::floor. r=nbp

This commit is contained in:
Julien Levesy 2014-06-11 13:19:31 -07:00
parent 95cea05798
commit 6f62a52677
3 changed files with 119 additions and 9 deletions

View File

@ -0,0 +1,91 @@
setJitCompilerOption("baseline.usecount.trigger", 10);
setJitCompilerOption("ion.usecount.trigger", 20);
function myFloor(x) {
if(x >= 0)
return x - Math.abs(x % 1);
else
return x - Math.abs(1 + (x % 1));
}
function floorRangeTest(x) {
if(10 < x) {
if(x < 100) {
assertEq(Math.floor(x), myFloor(x));
}
}
if(-100 < x) {
if(x < -10) {
assertEq(Math.floor(x), myFloor(x));
}
}
if (-(4294967296 - 1) < x) {
if(x < 10) {
assertEq(Math.floor(x), myFloor(x));
}
}
if (-10 < x) {
if(x < 4294967296) {
assertEq(Math.floor(x), myFloor(x));
}
}
if (-2147483648 < x) {
if(x < 10) {
assertEq(Math.floor(x), myFloor(x));
}
}
if ((-2147483648 -1) < x) {
if(x < 10) {
assertEq(Math.floor(x), myFloor(x));
}
}
if (10 < x) {
if(x < 2147483648) {
assertEq(Math.floor(x), myFloor(x));
}
}
if (10 < x) {
if(x < 2147483649) {
assertEq(Math.floor(x), myFloor(x));
}
}
if (Math.pow(2,31) < x) {
if(x < Math.pow(2,33)) {
assertEq(Math.floor(x), myFloor(x));
}
}
}
var a = [Math.pow(2,31), Math.pow(2,33), -4294967296.4, 214748364.2, -50.4, 50.4];
for(var i = 0; i < 10; i++) {
for (var j = 0; j < a.length; j++) {
floorRangeTest(a[j]);
}
}
for (var j = 0; j < 30; j++) {
(function() {
Math.floor(1.5);
})()
}
for (var j = 0; j < 30; j++) {
(function() {
Math.floor(-1.5);
})()
}
for (var j = 0; j < 30; j++) {
(function() {
Math.floor(-127.5);
})()
}

View File

@ -556,7 +556,7 @@ Range::setDouble(double l, double h)
{
// Infer lower_, upper_, hasInt32LowerBound_, and hasInt32UpperBound_.
if (l >= INT32_MIN && l <= INT32_MAX) {
lower_ = int32_t(floor(l));
lower_ = int32_t(::floor(l));
hasInt32LowerBound_ = true;
} else {
lower_ = INT32_MIN;
@ -954,6 +954,31 @@ Range::max(TempAllocator &alloc, const Range *lhs, const Range *rhs)
Max(lhs->max_exponent_, rhs->max_exponent_));
}
Range *
Range::floor(TempAllocator &alloc, const Range *op)
{
Range *copy = new(alloc) Range(*op);
// Decrement lower bound of copy range if op have a factional part and lower
// bound is Int32 defined. Also we avoid to decrement when op have a
// fractional part but lower_ >= JSVAL_INT_MAX.
if (op->canHaveFractionalPart() && op->hasInt32LowerBound())
copy->setLowerInit(int64_t(copy->lower_) - 1);
// Also refine max_exponent_ because floor may have decremented int value
// If we've got int32 defined bounds, just deduce it using defined bounds.
// But, if we don't have those, value's max_exponent_ may have changed.
// Because we're looking to maintain an over estimation, if we can,
// we increment it.
if(copy->hasInt32Bounds())
copy->max_exponent_ = copy->exponentImpliedByInt32Bounds();
else if(copy->max_exponent_ < MaxFiniteExponent)
copy->max_exponent_++;
copy->canHaveFractionalPart_ = false;
copy->assertInvariants();
return copy;
}
bool
Range::negativeZeroMul(const Range *lhs, const Range *rhs)
{
@ -1179,9 +1204,7 @@ void
MFloor::computeRange(TempAllocator &alloc)
{
Range other(getOperand(0));
Range *copy = new(alloc) Range(other);
copy->resetFractionalPart();
setRange(copy);
setRange(Range::floor(alloc, &other));
}
void

View File

@ -414,6 +414,7 @@ class Range : public TempObject {
static Range *abs(TempAllocator &alloc, const Range *op);
static Range *min(TempAllocator &alloc, const Range *lhs, const Range *rhs);
static Range *max(TempAllocator &alloc, const Range *lhs, const Range *rhs);
static Range *floor(TempAllocator &alloc, const Range *op);
static bool negativeZeroMul(const Range *lhs, const Range *rhs);
@ -587,11 +588,6 @@ class Range : public TempObject {
void setSymbolicUpper(SymbolicBound *bound) {
symbolicUpper_ = bound;
}
void resetFractionalPart() {
canHaveFractionalPart_ = false;
optimize();
}
};
} // namespace jit