Changeset 189844 in webkit


Ignore:
Timestamp:
Sep 15, 2015 8:52:20 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Fix asm.js errors in WebAssembly tests
https://bugs.webkit.org/show_bug.cgi?id=149203

Patch by Sukolsak Sakshuwong <Sukolsak Sakshuwong> on 2015-09-15
Reviewed by Geoffrey Garen.

Our WebAssembly implementation uses asm.js for testing. Using Firefox to
parse asm.js reveals many errors that are not caught by pack-asmjs. For
example,

  • asm.js does not allow the use of the multiplication operator (*) to multiply two integers, because the result can be so large that some lower bits of precision are lost. Math.imul is used instead.
  • an int variable must be coerced to either signed (via x|0) or unsigned (via x>>>0) before it's returned.
  • tests/stress/wasm-arithmetic-int32.js:
  • tests/stress/wasm-calls.js:
  • tests/stress/wasm-control-flow.js:
  • tests/stress/wasm-globals.js:
  • tests/stress/wasm-locals.js:
  • tests/stress/wasm-relational.js:
  • tests/stress/wasm/control-flow.wasm:
Location:
trunk/Source/JavaScriptCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r189841 r189844  
     12015-09-15  Sukolsak Sakshuwong  <sukolsak@gmail.com>
     2
     3        Fix asm.js errors in WebAssembly tests
     4        https://bugs.webkit.org/show_bug.cgi?id=149203
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Our WebAssembly implementation uses asm.js for testing. Using Firefox to
     9        parse asm.js reveals many errors that are not caught by pack-asmjs. For
     10        example,
     11        - asm.js does not allow the use of the multiplication operator (*) to
     12          multiply two integers, because the result can be so large that some
     13          lower bits of precision are lost. Math.imul is used instead.
     14        - an int variable must be coerced to either signed (via x|0) or unsigned
     15          (via x>>>0) before it's returned.
     16
     17        * tests/stress/wasm-arithmetic-int32.js:
     18        * tests/stress/wasm-calls.js:
     19        * tests/stress/wasm-control-flow.js:
     20        * tests/stress/wasm-globals.js:
     21        * tests/stress/wasm-locals.js:
     22        * tests/stress/wasm-relational.js:
     23        * tests/stress/wasm/control-flow.wasm:
     24
    1252015-09-15  Ryosuke Niwa  <rniwa@webkit.org>
    226
  • trunk/Source/JavaScriptCore/tests/stress/wasm-arithmetic-int32.js

    r189532 r189844  
    2626
    2727    var clz32 = global.Math.clz32;
     28    var imul = global.Math.imul;
    2829    var abs = global.Math.abs;
    2930
    3031    function negate(x) {
    3132        x = x | 0;
    32         return -x;
     33        return (-x) | 0;
    3334    }
    3435
     
    4849        x = x | 0;
    4950        y = y | 0;
    50         return (x * y) | 0;
     51        return imul(x, y) | 0;
    5152    }
    5253
     
    113114        x = x | 0;
    114115        y = y | 0;
    115         return x >>> y;
     116        return (x >>> y) | 0;
    116117    }
    117118
     
    128129    function absolute(x) {
    129130        x = x | 0;
    130         return abs(x | 0);
     131        return abs(x | 0) | 0;
    131132    }
    132133
  • trunk/Source/JavaScriptCore/tests/stress/wasm-calls.js

    r189822 r189844  
    1212    "use asm";
    1313
     14    var imul = global.Math.imul;
    1415    var sum = imports.sum;
    1516    var max = imports.max;
     
    2526        x = x | 0;
    2627        y = y | 0;
    27         if (y == 0)
    28             return x;
    29         return gcd(y, (x | 0) % (y | 0)) | 0;
     28        if ((y | 0) == 0)
     29            return x | 0;
     30        return gcd(y, ((x | 0) % (y | 0)) | 0) | 0;
    3031    }
    3132
     
    3334        x = x | 0;
    3435        y = y | 0;
    35         return (((x * y) | 0) / (gcd(x, y) | 0)) | 0;
     36        return (imul(x, y) / (gcd(x, y) | 0)) | 0;
    3637    }
    3738
     
    3940        x = x | 0;
    4041        y = y | 0;
    41         return sum(x, y) | 0;
     42        return sum(x | 0, y | 0) | 0;
    4243    }
    4344
     
    4546        x = x | 0;
    4647        y = y | 0;
    47         return max(x, y) | 0;
     48        return max(x | 0, y | 0) | 0;
    4849    }
    4950
  • trunk/Source/JavaScriptCore/tests/stress/wasm-control-flow.js

    r189599 r189844  
    3434        else
    3535            return 2;
     36        return 0;
    3637    }
    3738
     
    4243        else
    4344            return 2;
     45        return 0;
    4446    }
    4547
     
    4749        var x = 0, y = 0;
    4850        x = 1;
    49         if (x == 0) {
    50             if (y == 0)
     51        if ((x | 0) == 0) {
     52            if ((y | 0) == 0)
    5153                return 1;
    5254            else
    5355                return 2;
    5456        } else {
    55             if (y == 0)
     57            if ((y | 0) == 0)
    5658                return 3;
    5759            else
    5860                return 4;
    5961        }
     62        return 0;
    6063    }
    6164
     
    6669            i = (i + 1) | 0;
    6770        }
    68         return x;
     71        return x | 0;
    6972    }
    7073
     
    7275        var x = 0, i = 0;
    7376        while (1) {
    74             if (i == 2)
     77            if ((i | 0) == 2)
    7578                break;
    7679            x = (x + 1) | 0;
    7780            i = (i + 1) | 0;
    7881        }
    79         return x;
     82        return x | 0;
    8083    }
    8184
     
    8386        var x = 0, i = 0;
    8487        while ((i | 0) < 5) {
    85             if (i == 2) {
     88            if ((i | 0) == 2) {
    8689                i = 3;
    8790                continue;
     
    9093            i = (i + 1) | 0;
    9194        }
    92         return x;
     95        return x | 0;
    9396    }
    9497
     
    103106            i = (i + 1) | 0;
    104107        }
    105         return x;
     108        return x | 0;
    106109    }
    107110
     
    112115            i = (i + 1) | 0;
    113116        } while ((i | 0) < 0);
    114         return x;
     117        return x | 0;
    115118    }
    116119
     
    118121        var x = 0, i = 0;
    119122        do {
    120             if (i == 2)
     123            if ((i | 0) == 2)
    121124                break;
    122125            x = (x + 1) | 0;
    123126            i = (i + 1) | 0;
    124127        } while (1);
    125         return x;
     128        return x | 0;
    126129    }
    127130
     
    129132        var x = 0, i = 0;
    130133        do {
    131             if (i == 2) {
     134            if ((i | 0) == 2) {
    132135                i = 3;
    133136                continue;
     
    136139            i = (i + 1) | 0;
    137140        } while ((i | 0) < 5);
    138         return x;
     141        return x | 0;
    139142    }
    140143
     
    146149            x = 2;
    147150        } while (0);
    148         return x;
     151        return x | 0;
    149152    }
    150153
     
    152155        var x = 0;
    153156        label: do {
    154             if (x == 1)
     157            if ((x | 0) == 1)
    155158                break label;
    156159            x = 1;
     
    158161            x = 2;
    159162        } while (0);
    160         return x;
     163        return x | 0;
    161164    }
    162165
     
    172175            x = 4;
    173176        } while (0);
    174         return x;
     177        return x | 0;
    175178    }
    176179
     
    186189            x = 4;
    187190        } while (0);
    188         return x;
     191        return x | 0;
    189192    }
    190193
     
    196199            while ((j | 0) < 2) {
    197200                x = (x + 1) | 0;
    198                 if (x == 8)
     201                if ((x | 0) == 8)
    199202                    break label;
    200203                j = (j + 1) | 0;
     
    202205            i = (i + 1) | 0;
    203206        }
    204         return x;
     207        return x | 0;
    205208    }
    206209
     
    208211        x = x | 0;
    209212        var y = 0;
    210         switch (x) {
     213        switch (x | 0) {
    211214        case 0:
    212215            y = 1;
     
    219222            break;
    220223        }
    221         return y;
     224        return y | 0;
    222225    }
    223226
     
    225228        x = x | 0;
    226229        var y = 0;
    227         switch (x) {
     230        switch (x | 0) {
    228231        case 3:
    229232            y = (y + 1000) | 0;
     
    235238            y = (y + 1) | 0;
    236239        }
    237         return y;
     240        return y | 0;
    238241    }
    239242
  • trunk/Source/JavaScriptCore/tests/stress/wasm-globals.js

    r189624 r189844  
    1818
    1919    function getX() {
    20         return x;
     20        return x | 0;
    2121    }
    2222
  • trunk/Source/JavaScriptCore/tests/stress/wasm-locals.js

    r189458 r189844  
    1717        var result = 0;
    1818        result = (x + y) | 0;
    19         return result;
     19        return result | 0;
    2020    }
    2121
  • trunk/Source/JavaScriptCore/tests/stress/wasm-relational.js

    r189645 r189844  
    1212    "use asm";
    1313
     14    var fround = global.Math.fround;
     15
    1416    function equal(x, y) {
    1517        x = x | 0;
    1618        y = y | 0;
    17         return (x == y) | 0;
     19        return ((x | 0) == (y | 0)) | 0;
    1820    }
    1921
     
    2123        x = x | 0;
    2224        y = y | 0;
    23         return (x != y) | 0;
     25        return ((x | 0) != (y | 0)) | 0;
    2426    }
    2527
Note: See TracChangeset for help on using the changeset viewer.