summaryrefslogtreecommitdiff
path: root/js/src/jit-test/tests/ion/ceil.js
blob: 1f058cf07393eb77579f18a9299fbc3e0bd37386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
setJitCompilerOption("baseline.warmup.trigger", 10);
setJitCompilerOption("ion.warmup.trigger", 20);

//var log = print;
var log = function(x){}

function ceil(x) {
    // A nice but not always efficient polyfill.
    return -Math.floor(-x);
}

function doubleCheck(g) {
    for (var j = 0; j < 200; j++) {
        var i = j;
        assertEq(g(i), i);
        assertEq(g(i+.5), i+1);
        assertEq(g(-i), -i);
        assertEq(g(-i-.5), -i);
    }
}

function floatCheck(g, val) {
    for (var j = 0; j < 200; j++) {
        var i = Math.fround(j);
        assertEq(g(i), i);
        assertEq(g(i+.5), i+1);
        assertEq(g(-i), -i);
        assertEq(g(-i-.5), -i);
    }
}

function testBailout(value) {
    var dceil = eval('(function(x) { return Math.ceil(x) })');
    log('start double');
    doubleCheck(dceil);
    log('bailout');
    // At this point, the compiled code should bailout, if 'value' is in the
    // edge case set.
    assertEq(dceil(value), ceil(value));

    var fceil = eval('(function(x) { return Math.ceil(Math.fround(x)) })');
    log('start float');
    floatCheck(fceil, value);
    log('bailout');
    assertEq(fceil(Math.fround(value)), ceil(Math.fround(value)));
}

var INT_MAX = Math.pow(2, 31) - 1;
var INT_MIN = INT_MAX + 1 | 0;
var UINT_MAX = Math.pow(2, 32) - 1;

// Values in ]-1; -0]
testBailout(-0);
testBailout(-.5);
// Values outside the INT32 range, when represented in either double or
// single precision
testBailout(INT_MAX + .5);
testBailout(INT_MIN - 129);
// (UINT_MAX; +inf] have special behavior on ARM
testBailout(UINT_MAX);
testBailout(UINT_MAX + .5);
testBailout(UINT_MAX + 1);
testBailout(UINT_MAX + 2);
// BatNaN
testBailout(NaN);