tor-browser

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

globals-impl.js (1757B)


      1 // This is intended to test that Ion correctly handles the combination
      2 // {direct, indirect} x {i32, i64} for global variables, following GVN
      3 // improvements pertaining to globals in bug 1448277.
      4 
      5 let txt =
      6  `(module
      7     ;; -------- Globals --------
      8     (global $ind64 (export "ind64") (mut i64) (i64.const 4242))
      9     (global $ind32 (export "ind32") (mut i32) (i32.const 3141))
     10     (global $dir64 (mut i64) (i64.const 5927))
     11     (global $dir32 (mut i32) (i32.const 2718))
     12     ;; -------- FUNCTION 0 --------
     13     (func (export "function0") (result i32)
     14       (local $loopctr i32)
     15       (local $sum     i32)
     16       (local $tmp64   i64)
     17       (local $tmp32   i32)
     18       (loop
     19          (global.set $ind64 (i64.add (global.get $ind64) (i64.const 11)))
     20          (global.set $ind32 (i32.add (global.get $ind32) (i32.const 22)))
     21          (global.set $dir64 (i64.add (global.get $dir64) (i64.const 33)))
     22          (global.set $dir32 (i32.add (global.get $dir32) (i32.const 44)))
     23 
     24          (local.set $tmp64 (i64.and (global.get $ind64) (global.get $dir64)))
     25          (local.set $tmp32 (i32.or  (global.get $ind32) (global.get $dir32)))
     26 
     27          (local.set $sum
     28            (i32.sub (local.get $sum) (i32.xor (i32.wrap_i64 (local.get $tmp64))
     29                                               (local.get $tmp32))))
     30 
     31          (local.set $loopctr
     32            (i32.add (local.get $loopctr) (i32.const 1)))
     33          (br_if 0
     34            (i32.lt_u (local.get $loopctr) (i32.const 10)))
     35 
     36       )
     37       (local.get $sum)
     38     )
     39   )`;
     40 
     41 function test_driver()
     42 {
     43    let bin  = wasmTextToBinary(txt);
     44    let inst = new WebAssembly.Instance(new WebAssembly.Module(bin));
     45    let res  = inst.exports.function0();
     46    assertEq(res, -79170);
     47 }
     48 
     49 test_driver();