tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

udiv-by-u32-constant.js (1898B)


      1 function uint_seq(count) {
      2    with({}){}
      3    var arr = [];
      4    var x = 0xfac83126;
      5    while (count--) {
      6        x ^= x << 13;
      7        x ^= x >> 17;
      8        x ^= x << 5;
      9        arr.push(x >>> 0);
     10    }
     11    return arr;
     12 }
     13 
     14 function test(name, asm, ion, int) {
     15    with({}){}
     16    let count = 10000;
     17    let seq = uint_seq(count);
     18    for (let x of seq) {
     19        let rint = int(x);
     20        let rasm = asm(x);
     21        let rion = ion(x);
     22        // console.log(name, x, rint, rasm, rion);
     23        assertEq(rasm, rint);
     24        assertEq(rion, rint);
     25    }
     26 }
     27 
     28 var asmdiv2 = (function(m) {
     29    "use asm"
     30    function f(x) {
     31        x = x|0;
     32        var z = 0;
     33        z = ((x>>>0) / 2)>>>0;
     34        return z|0;
     35    }
     36    return f;
     37 })()
     38 
     39 var plaindiv2 = function(x) {
     40    x = x|0;
     41    var z = 0;
     42    z = ((x>>>0) / 2)>>>0;
     43    return z|0;
     44 }
     45 
     46 var interpdiv2 = function(x) {
     47    with({}){};
     48    x = x|0;
     49    var z = 0;
     50    z = ((x>>>0) / 2)>>>0;
     51    return z|0;
     52 }
     53 
     54 test("div2", asmdiv2, plaindiv2, interpdiv2);
     55 
     56 var asmdiv3 = (function(m) {
     57    "use asm"
     58    function f(x) {
     59        x = x|0;
     60        var z = 0;
     61        z = ((x>>>0) / 3)>>>0;
     62        return z|0;
     63    }
     64    return f;
     65 })()
     66 
     67 var plaindiv3 = function(x) {
     68    x = x|0;
     69    var z = 0;
     70    z = ((x>>>0) / 3)>>>0;
     71    return z|0;
     72 }
     73 
     74 var interpdiv3 = function(x) {
     75    with({}){};
     76    x = x|0;
     77    var z = 0;
     78    z = ((x>>>0) / 3)>>>0;
     79    return z|0;
     80 }
     81 
     82 test("div3", asmdiv3, plaindiv3, interpdiv3);
     83 
     84 var asmdiv7 = (function(m) {
     85    "use asm"
     86    function f(x) {
     87        x = x|0;
     88        var z = 0;
     89        z = ((x>>>0) / 7)>>>0;
     90        return z|0;
     91    }
     92    return f;
     93 })()
     94 
     95 var plaindiv7 = function(x) {
     96    x = x|0;
     97    var z = 0;
     98    z = ((x>>>0) / 7)>>>0;
     99    return z|0;
    100 }
    101 
    102 var interpdiv7 = function(x) {
    103    with({}){};
    104    x = x|0;
    105    var z = 0;
    106    z = ((x>>>0) / 7)>>>0;
    107    return z|0;
    108 }
    109 
    110 test("div7", asmdiv7, plaindiv7, interpdiv7);