tor-browser

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

effective-address1.js (1992B)


      1 // |jit-test| skip-if: wasmCompileMode() != "ion"
      2 
      3 // A minimal test for the formation of load-effective-address instructions on
      4 // x86_64.  The formation of LEAs is done at the MIR level, so this test
      5 // verifies formation on all targets.
      6 //
      7 // Test inspired by simd/pmaddubsw-x64-ion-codegen.js.
      8 
      9 const isX64 = getBuildConfiguration("x64") && !getBuildConfiguration("simulator");
     10 
     11 if (hasDisassembler() && isX64) {
     12  let t = `
     13  (module
     14    (memory (export "mem") 1)
     15    (func (export "writeArr32")
     16          (param $b i32) (param $ix i32) (param $data i32)
     17      (local $ea1 i32)
     18      (local $ea2 i32)
     19      (local $ea3 i32)
     20      (local $ea4 i32)
     21      (local $ea5 i32)
     22 
     23      ;; base(non-constant) + (index << const)
     24      (local.set $ea1
     25          (i32.add (local.get $b) (i32.shl (local.get $ix) (i32.const 2))
     26      ))
     27      (i32.store (local.get $ea1) (local.get $data))
     28 
     29      ;; (index << const) + base(non-constant)
     30      (local.set $ea2
     31          (i32.add (i32.shl (local.get $ix) (i32.const 3)) (local.get $b)
     32      ))
     33      (i32.store (local.get $ea2) (local.get $data))
     34 
     35      ;; base(constant) + (index << const)
     36      (local.set $ea3
     37          (i32.add (i32.const 0x1337) (i32.shl (local.get $ix) (i32.const 1))
     38      ))
     39      (i32.store (local.get $ea3) (local.get $data))
     40 
     41      ;; (index << const) + base(constant)
     42      (local.set $ea4
     43          (i32.add (i32.shl (local.get $ix) (i32.const 2)) (i32.const 0x4771)
     44      ))
     45      (i32.store (local.get $ea4) (local.get $data))
     46    )
     47  )`;
     48 
     49  let i = new WebAssembly.Instance(
     50              new WebAssembly.Module(wasmTextToBinary(t)));
     51 
     52  const output = wasmDis(i.exports.writeArr32, {tier:"ion", asString:true});
     53 
     54  // Find exactly four " lea " bits of text in the output.    
     55  const re = /\blea\b/g;
     56  assertEq(re.exec(output) != null, true);
     57  assertEq(re.exec(output) != null, true);
     58  assertEq(re.exec(output) != null, true);
     59  assertEq(re.exec(output) != null, true);
     60  assertEq(re.exec(output) == null, true);
     61 }