summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/wasm/regress/unaligned-store64.js
blob: b87809345104a318f3ecb40f774d3212dfbe7a2f (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
var ins = new WebAssembly.Instance(new WebAssembly.Module(wasmTextToBinary(
    `(module
       (memory (export "mem") 1 1)
       (func (export "store_32_1") (param $ptr i32)
         (i64.store32 align=1 (local.get $ptr) (i64.const 0xabba1337)))
       (func (export "store_32_2") (param $ptr i32)
         (i64.store32 align=2 (local.get $ptr) (i64.const 0xabba1337)))
       (func (export "store_16") (param $ptr i32)
         (i64.store16 align=1 (local.get $ptr) (i64.const 0x1337))))`))).exports;

var mem = new Uint8Array(ins.mem.buffer);

ins.store_16(1);
assertEq(mem[1], 0x37);
assertEq(mem[2], 0x13);

ins.store_32_1(11);
assertEq(mem[11], 0x37);
assertEq(mem[12], 0x13);
assertEq(mem[13], 0xba);
assertEq(mem[14], 0xab);

ins.store_32_2(18);
assertEq(mem[18], 0x37);
assertEq(mem[19], 0x13);
assertEq(mem[20], 0xba);
assertEq(mem[21], 0xab);

// This must also work on all platforms even though we're lying about the
// alignment.
ins.store_32_2(29);
assertEq(mem[29], 0x37);
assertEq(mem[30], 0x13);
assertEq(mem[31], 0xba);
assertEq(mem[32], 0xab);