2017-08-02 21:40:45 +00:00
|
|
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
// Flags: --experimental-wasm-threads
|
|
|
|
|
|
|
|
load("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
const kMemtypeSize32 = 4;
|
|
|
|
const kMemtypeSize16 = 2;
|
|
|
|
const kMemtypeSize8 = 1;
|
2017-08-02 21:40:45 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
function Add(a, b) { return a + b; }
|
|
|
|
function Sub(a, b) { return a - b; }
|
|
|
|
function And(a, b) { return a & b; }
|
|
|
|
function Or(a, b) { return a | b; }
|
|
|
|
function Xor(a, b) { return a ^ b; }
|
2017-08-25 21:30:35 +00:00
|
|
|
function Exchange(a, b) { return b; }
|
2017-08-14 22:31:59 +00:00
|
|
|
|
|
|
|
let maxSize = 10;
|
|
|
|
let memory = new WebAssembly.Memory({initial: 1, maximum: maxSize, shared: true});
|
|
|
|
|
2017-09-23 18:59:12 +00:00
|
|
|
function GetAtomicBinOpFunction(wasmExpression, alignment, offset) {
|
2017-08-02 21:40:45 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
2017-09-14 06:14:48 +00:00
|
|
|
builder.addImportedMemory("m", "imported_mem", 0, maxSize, "shared");
|
2017-08-14 22:31:59 +00:00
|
|
|
builder.addFunction("main", kSig_i_ii)
|
2017-08-02 21:40:45 +00:00
|
|
|
.addBody([
|
|
|
|
kExprGetLocal, 0,
|
|
|
|
kExprGetLocal, 1,
|
|
|
|
kAtomicPrefix,
|
2017-09-23 18:59:12 +00:00
|
|
|
wasmExpression, alignment, offset])
|
2017-08-14 22:31:59 +00:00
|
|
|
.exportAs("main");
|
2017-08-02 21:40:45 +00:00
|
|
|
|
|
|
|
// Instantiate module, get function exports
|
|
|
|
let module = new WebAssembly.Module(builder.toBuffer());
|
2017-10-02 05:05:45 +00:00
|
|
|
let instance = new WebAssembly.Instance(module,
|
|
|
|
{m: {imported_mem: memory}});
|
2017-08-14 22:31:59 +00:00
|
|
|
return instance.exports.main;
|
|
|
|
}
|
2017-08-02 21:40:45 +00:00
|
|
|
|
2017-09-23 18:59:12 +00:00
|
|
|
function GetAtomicCmpExchangeFunction(wasmExpression, alignment, offset) {
|
2017-08-25 21:30:35 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
2017-09-14 06:14:48 +00:00
|
|
|
builder.addImportedMemory("m", "imported_mem", 0, maxSize, "shared");
|
2017-08-25 21:30:35 +00:00
|
|
|
builder.addFunction("main", kSig_i_iii)
|
|
|
|
.addBody([
|
|
|
|
kExprGetLocal, 0,
|
|
|
|
kExprGetLocal, 1,
|
|
|
|
kExprGetLocal, 2,
|
|
|
|
kAtomicPrefix,
|
2017-09-23 18:59:12 +00:00
|
|
|
wasmExpression, alignment, offset])
|
2017-08-25 21:30:35 +00:00
|
|
|
.exportAs("main");
|
|
|
|
|
|
|
|
// Instantiate module, get function exports
|
|
|
|
let module = new WebAssembly.Module(builder.toBuffer());
|
2017-10-02 05:05:45 +00:00
|
|
|
let instance = new WebAssembly.Instance(module,
|
|
|
|
{m: {imported_mem: memory}});
|
|
|
|
return instance.exports.main;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetAtomicLoadFunction(wasmExpression, alignment, offset) {
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addImportedMemory("m", "imported_mem", 0, maxSize, "shared");
|
|
|
|
builder.addFunction("main", kSig_i_i)
|
|
|
|
.addBody([
|
|
|
|
kExprGetLocal, 0,
|
|
|
|
kAtomicPrefix,
|
|
|
|
wasmExpression, alignment, offset])
|
|
|
|
.exportAs("main");
|
|
|
|
|
|
|
|
// Instantiate module, get function exports
|
|
|
|
let module = new WebAssembly.Module(builder.toBuffer());
|
|
|
|
let instance = new WebAssembly.Instance(module,
|
|
|
|
{m: {imported_mem: memory}});
|
2017-08-25 21:30:35 +00:00
|
|
|
return instance.exports.main;
|
|
|
|
}
|
|
|
|
|
2017-10-02 05:05:45 +00:00
|
|
|
function GetAtomicStoreFunction(wasmExpression, alignment, offset) {
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addImportedMemory("m", "imported_mem", 0, maxSize, "shared");
|
|
|
|
builder.addFunction("main", kSig_v_ii)
|
|
|
|
.addBody([
|
|
|
|
kExprGetLocal, 0,
|
|
|
|
kExprGetLocal, 1,
|
|
|
|
kAtomicPrefix,
|
|
|
|
wasmExpression, alignment, offset])
|
|
|
|
.exportAs("main");
|
|
|
|
|
|
|
|
// Instantiate module, get function exports
|
|
|
|
let module = new WebAssembly.Module(builder.toBuffer());
|
|
|
|
let instance = new WebAssembly.Instance(module,
|
|
|
|
{m: {imported_mem: memory}});
|
|
|
|
return instance.exports.main;
|
|
|
|
}
|
2017-08-25 21:30:35 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
function VerifyBoundsCheck(func, memtype_size) {
|
|
|
|
const kPageSize = 65536;
|
|
|
|
// Test out of bounds at boundary
|
|
|
|
for (let i = memory.buffer.byteLength - memtype_size + 1;
|
|
|
|
i < memory.buffer.byteLength + memtype_size + 4; i++) {
|
2017-08-25 21:30:35 +00:00
|
|
|
assertTraps(kTrapMemOutOfBounds, () => func(i, 5, 10));
|
2017-08-02 21:40:45 +00:00
|
|
|
}
|
2017-08-14 22:31:59 +00:00
|
|
|
// Test out of bounds at maximum + 1
|
2017-08-25 21:30:35 +00:00
|
|
|
assertTraps(kTrapMemOutOfBounds, () => func((maxSize + 1) * kPageSize, 5, 1));
|
2017-08-14 22:31:59 +00:00
|
|
|
}
|
2017-08-02 21:40:45 +00:00
|
|
|
|
2017-10-24 18:57:02 +00:00
|
|
|
// Test many elements in the small range, make bigger steps later. This is still
|
|
|
|
// O(2^n), but takes 213 steps to reach 2^32.
|
|
|
|
const inc = i => i + Math.floor(i/10) + 1;
|
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
function Test32Op(operation, func) {
|
|
|
|
let i32 = new Uint32Array(memory.buffer);
|
2017-10-24 18:57:02 +00:00
|
|
|
for (let i = 0; i < i32.length; i = inc(i)) {
|
2017-08-14 22:31:59 +00:00
|
|
|
let expected = 0x9cedf00d;
|
|
|
|
let value = 0x11111111;
|
|
|
|
i32[i] = expected;
|
|
|
|
assertEquals(expected, func(i * kMemtypeSize32, value) >>> 0);
|
|
|
|
assertEquals(operation(expected, value) >>> 0, i32[i]);
|
|
|
|
}
|
|
|
|
VerifyBoundsCheck(func, kMemtypeSize32);
|
|
|
|
}
|
|
|
|
|
|
|
|
function Test16Op(operation, func) {
|
2017-08-02 21:40:45 +00:00
|
|
|
let i16 = new Uint16Array(memory.buffer);
|
2017-10-24 18:57:02 +00:00
|
|
|
for (let i = 0; i < i16.length; i = inc(i)) {
|
2017-08-14 22:31:59 +00:00
|
|
|
let expected = 0xd00d;
|
|
|
|
let value = 0x1111;
|
|
|
|
i16[i] = expected;
|
|
|
|
assertEquals(expected, func(i * kMemtypeSize16, value));
|
|
|
|
assertEquals(operation(expected, value), i16[i]);
|
|
|
|
}
|
|
|
|
VerifyBoundsCheck(func, kMemtypeSize16);
|
|
|
|
}
|
2017-08-02 21:40:45 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
function Test8Op(operation, func) {
|
2017-08-02 21:40:45 +00:00
|
|
|
let i8 = new Uint8Array(memory.buffer);
|
2017-10-24 18:57:02 +00:00
|
|
|
for (let i = 0; i < i8.length; i = inc(i)) {
|
2017-08-14 22:31:59 +00:00
|
|
|
let expected = 0xbe;
|
|
|
|
let value = 0x12;
|
|
|
|
i8[i] = expected;
|
|
|
|
assertEquals(expected, func(i * kMemtypeSize8, value));
|
|
|
|
assertEquals(operation(expected, value), i8[i]);
|
|
|
|
}
|
|
|
|
VerifyBoundsCheck(func, kMemtypeSize8, 10);
|
|
|
|
}
|
2017-08-02 21:40:45 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
(function TestAtomicAdd() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmAdd = GetAtomicBinOpFunction(kExprI32AtomicAdd, 2, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test32Op(Add, wasmAdd);
|
|
|
|
})();
|
2017-08-02 21:40:45 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
(function TestAtomicAdd16U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmAdd = GetAtomicBinOpFunction(kExprI32AtomicAdd16U, 1, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test16Op(Add, wasmAdd);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicAdd8U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmAdd = GetAtomicBinOpFunction(kExprI32AtomicAdd8U, 0, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test8Op(Add, wasmAdd);
|
2017-08-02 21:40:45 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicSub() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmSub = GetAtomicBinOpFunction(kExprI32AtomicSub, 2, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test32Op(Sub, wasmSub);
|
|
|
|
})();
|
2017-08-02 21:40:45 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
(function TestAtomicSub16U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmSub = GetAtomicBinOpFunction(kExprI32AtomicSub16U, 1, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test16Op(Sub, wasmSub);
|
|
|
|
})();
|
2017-08-02 21:40:45 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
(function TestAtomicSub8U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmSub = GetAtomicBinOpFunction(kExprI32AtomicSub8U, 0, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test8Op(Sub, wasmSub);
|
2017-08-02 21:40:45 +00:00
|
|
|
})();
|
[wasm] Implement atomic logical BinOps
- Implemented ops: I32AtomicAnd, I32AtomicAnd8U, I32AtomicAnd16U, I32AtomicOr,
I32AtomicOr8U, I32AtomicOr16U, I32AtomicXor, I32AtomicXor8U, I32AtomicXor16U
- Refactor wasm-compiler AtomicOp to use macros
- Tests
Bug:V8:6532
R=binji@chromium.org, bbudge@chromium.org, bradnelson@chromium.org
Change-Id: I7e4dc8ad8cf3e211c3aef721a02778f2a4621322
Reviewed-on: https://chromium-review.googlesource.com/600539
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47172}
2017-08-03 19:54:41 +00:00
|
|
|
|
|
|
|
(function TestAtomicAnd() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmAnd = GetAtomicBinOpFunction(kExprI32AtomicAnd, 2, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test32Op(And, wasmAnd);
|
|
|
|
})();
|
[wasm] Implement atomic logical BinOps
- Implemented ops: I32AtomicAnd, I32AtomicAnd8U, I32AtomicAnd16U, I32AtomicOr,
I32AtomicOr8U, I32AtomicOr16U, I32AtomicXor, I32AtomicXor8U, I32AtomicXor16U
- Refactor wasm-compiler AtomicOp to use macros
- Tests
Bug:V8:6532
R=binji@chromium.org, bbudge@chromium.org, bradnelson@chromium.org
Change-Id: I7e4dc8ad8cf3e211c3aef721a02778f2a4621322
Reviewed-on: https://chromium-review.googlesource.com/600539
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47172}
2017-08-03 19:54:41 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
(function TestAtomicAnd16U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmAnd = GetAtomicBinOpFunction(kExprI32AtomicAnd16U, 1, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test16Op(And, wasmAnd);
|
|
|
|
})();
|
[wasm] Implement atomic logical BinOps
- Implemented ops: I32AtomicAnd, I32AtomicAnd8U, I32AtomicAnd16U, I32AtomicOr,
I32AtomicOr8U, I32AtomicOr16U, I32AtomicXor, I32AtomicXor8U, I32AtomicXor16U
- Refactor wasm-compiler AtomicOp to use macros
- Tests
Bug:V8:6532
R=binji@chromium.org, bbudge@chromium.org, bradnelson@chromium.org
Change-Id: I7e4dc8ad8cf3e211c3aef721a02778f2a4621322
Reviewed-on: https://chromium-review.googlesource.com/600539
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47172}
2017-08-03 19:54:41 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
(function TestAtomicAnd8U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmAnd = GetAtomicBinOpFunction(kExprI32AtomicAnd8U, 0, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test8Op(And, wasmAnd);
|
[wasm] Implement atomic logical BinOps
- Implemented ops: I32AtomicAnd, I32AtomicAnd8U, I32AtomicAnd16U, I32AtomicOr,
I32AtomicOr8U, I32AtomicOr16U, I32AtomicXor, I32AtomicXor8U, I32AtomicXor16U
- Refactor wasm-compiler AtomicOp to use macros
- Tests
Bug:V8:6532
R=binji@chromium.org, bbudge@chromium.org, bradnelson@chromium.org
Change-Id: I7e4dc8ad8cf3e211c3aef721a02778f2a4621322
Reviewed-on: https://chromium-review.googlesource.com/600539
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47172}
2017-08-03 19:54:41 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicOr() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmOr = GetAtomicBinOpFunction(kExprI32AtomicOr, 2, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test32Op(Or, wasmOr);
|
|
|
|
})();
|
[wasm] Implement atomic logical BinOps
- Implemented ops: I32AtomicAnd, I32AtomicAnd8U, I32AtomicAnd16U, I32AtomicOr,
I32AtomicOr8U, I32AtomicOr16U, I32AtomicXor, I32AtomicXor8U, I32AtomicXor16U
- Refactor wasm-compiler AtomicOp to use macros
- Tests
Bug:V8:6532
R=binji@chromium.org, bbudge@chromium.org, bradnelson@chromium.org
Change-Id: I7e4dc8ad8cf3e211c3aef721a02778f2a4621322
Reviewed-on: https://chromium-review.googlesource.com/600539
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47172}
2017-08-03 19:54:41 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
(function TestAtomicOr16U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmOr = GetAtomicBinOpFunction(kExprI32AtomicOr16U, 1, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test16Op(Or, wasmOr);
|
|
|
|
})();
|
[wasm] Implement atomic logical BinOps
- Implemented ops: I32AtomicAnd, I32AtomicAnd8U, I32AtomicAnd16U, I32AtomicOr,
I32AtomicOr8U, I32AtomicOr16U, I32AtomicXor, I32AtomicXor8U, I32AtomicXor16U
- Refactor wasm-compiler AtomicOp to use macros
- Tests
Bug:V8:6532
R=binji@chromium.org, bbudge@chromium.org, bradnelson@chromium.org
Change-Id: I7e4dc8ad8cf3e211c3aef721a02778f2a4621322
Reviewed-on: https://chromium-review.googlesource.com/600539
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47172}
2017-08-03 19:54:41 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
(function TestAtomicOr8U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmOr = GetAtomicBinOpFunction(kExprI32AtomicOr8U, 0, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test8Op(Or, wasmOr);
|
[wasm] Implement atomic logical BinOps
- Implemented ops: I32AtomicAnd, I32AtomicAnd8U, I32AtomicAnd16U, I32AtomicOr,
I32AtomicOr8U, I32AtomicOr16U, I32AtomicXor, I32AtomicXor8U, I32AtomicXor16U
- Refactor wasm-compiler AtomicOp to use macros
- Tests
Bug:V8:6532
R=binji@chromium.org, bbudge@chromium.org, bradnelson@chromium.org
Change-Id: I7e4dc8ad8cf3e211c3aef721a02778f2a4621322
Reviewed-on: https://chromium-review.googlesource.com/600539
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47172}
2017-08-03 19:54:41 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicXor() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmXor = GetAtomicBinOpFunction(kExprI32AtomicXor, 2, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test32Op(Xor, wasmXor);
|
|
|
|
})();
|
[wasm] Implement atomic logical BinOps
- Implemented ops: I32AtomicAnd, I32AtomicAnd8U, I32AtomicAnd16U, I32AtomicOr,
I32AtomicOr8U, I32AtomicOr16U, I32AtomicXor, I32AtomicXor8U, I32AtomicXor16U
- Refactor wasm-compiler AtomicOp to use macros
- Tests
Bug:V8:6532
R=binji@chromium.org, bbudge@chromium.org, bradnelson@chromium.org
Change-Id: I7e4dc8ad8cf3e211c3aef721a02778f2a4621322
Reviewed-on: https://chromium-review.googlesource.com/600539
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47172}
2017-08-03 19:54:41 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
(function TestAtomicXor16U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmXor = GetAtomicBinOpFunction(kExprI32AtomicXor16U, 1, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test16Op(Xor, wasmXor);
|
|
|
|
})();
|
[wasm] Implement atomic logical BinOps
- Implemented ops: I32AtomicAnd, I32AtomicAnd8U, I32AtomicAnd16U, I32AtomicOr,
I32AtomicOr8U, I32AtomicOr16U, I32AtomicXor, I32AtomicXor8U, I32AtomicXor16U
- Refactor wasm-compiler AtomicOp to use macros
- Tests
Bug:V8:6532
R=binji@chromium.org, bbudge@chromium.org, bradnelson@chromium.org
Change-Id: I7e4dc8ad8cf3e211c3aef721a02778f2a4621322
Reviewed-on: https://chromium-review.googlesource.com/600539
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47172}
2017-08-03 19:54:41 +00:00
|
|
|
|
2017-08-14 22:31:59 +00:00
|
|
|
(function TestAtomicXor8U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmXor = GetAtomicBinOpFunction(kExprI32AtomicXor8U, 0, 0);
|
2017-08-14 22:31:59 +00:00
|
|
|
Test8Op(Xor, wasmXor);
|
[wasm] Implement atomic logical BinOps
- Implemented ops: I32AtomicAnd, I32AtomicAnd8U, I32AtomicAnd16U, I32AtomicOr,
I32AtomicOr8U, I32AtomicOr16U, I32AtomicXor, I32AtomicXor8U, I32AtomicXor16U
- Refactor wasm-compiler AtomicOp to use macros
- Tests
Bug:V8:6532
R=binji@chromium.org, bbudge@chromium.org, bradnelson@chromium.org
Change-Id: I7e4dc8ad8cf3e211c3aef721a02778f2a4621322
Reviewed-on: https://chromium-review.googlesource.com/600539
Reviewed-by: Bill Budge <bbudge@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47172}
2017-08-03 19:54:41 +00:00
|
|
|
})();
|
2017-08-25 21:30:35 +00:00
|
|
|
|
|
|
|
(function TestAtomicExchange() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmExchange = GetAtomicBinOpFunction(kExprI32AtomicExchange, 2, 0);
|
2017-08-25 21:30:35 +00:00
|
|
|
Test32Op(Exchange, wasmExchange);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicExchange16U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmExchange = GetAtomicBinOpFunction(kExprI32AtomicExchange16U, 1, 0);
|
2017-08-25 21:30:35 +00:00
|
|
|
Test16Op(Exchange, wasmExchange);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicExchange8U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-09-23 18:59:12 +00:00
|
|
|
let wasmExchange = GetAtomicBinOpFunction(kExprI32AtomicExchange8U, 0, 0);
|
2017-08-25 21:30:35 +00:00
|
|
|
Test8Op(Exchange, wasmExchange);
|
|
|
|
})();
|
|
|
|
|
|
|
|
function TestCmpExchange(func, buffer, params, size) {
|
2017-10-24 18:57:02 +00:00
|
|
|
for (let i = 0; i < buffer.length; i = inc(i)) {
|
2017-08-25 21:30:35 +00:00
|
|
|
for (let j = 0; j < params.length; j++) {
|
|
|
|
for (let k = 0; k < params.length; k++) {
|
|
|
|
buffer[i] = params[j];
|
|
|
|
let loaded = func(i * size, params[k], params[j]) >>> 0;
|
|
|
|
let expected = (params[k] == loaded) ? params[j] : loaded;
|
|
|
|
assertEquals(loaded, params[j]);
|
|
|
|
assertEquals(expected, buffer[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VerifyBoundsCheck(func, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
(function TestAtomicCompareExchange() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-08-25 21:30:35 +00:00
|
|
|
let wasmCmpExchange =
|
2017-09-23 18:59:12 +00:00
|
|
|
GetAtomicCmpExchangeFunction(kExprI32AtomicCompareExchange, 2, 0);
|
2017-08-25 21:30:35 +00:00
|
|
|
let i32 = new Uint32Array(memory.buffer);
|
|
|
|
let params = [0x00000001, 0x00000555, 0x00099999, 0xffffffff];
|
|
|
|
TestCmpExchange(wasmCmpExchange, i32, params, kMemtypeSize32);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicCompareExchange16U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-08-25 21:30:35 +00:00
|
|
|
let wasmCmpExchange =
|
2017-09-23 18:59:12 +00:00
|
|
|
GetAtomicCmpExchangeFunction(kExprI32AtomicCompareExchange16U, 1, 0);
|
2017-08-25 21:30:35 +00:00
|
|
|
let i16 = new Uint16Array(memory.buffer);
|
|
|
|
let params = [0x0001, 0x0555, 0x9999];
|
|
|
|
TestCmpExchange(wasmCmpExchange, i16, params, kMemtypeSize16);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicCompareExchange8U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-08-25 21:30:35 +00:00
|
|
|
let wasmCmpExchange =
|
2017-09-23 18:59:12 +00:00
|
|
|
GetAtomicCmpExchangeFunction(kExprI32AtomicCompareExchange8U, 0, 0);
|
2017-08-25 21:30:35 +00:00
|
|
|
let i8 = new Uint8Array(memory.buffer);
|
|
|
|
let params = [0x01, 0x0d, 0xf9];
|
|
|
|
TestCmpExchange(wasmCmpExchange, i8, params, kMemtypeSize8);
|
|
|
|
})();
|
2017-10-02 05:05:45 +00:00
|
|
|
|
|
|
|
function TestLoad(func, buffer, value, size) {
|
2017-10-24 18:57:02 +00:00
|
|
|
for (let i = 0; i < buffer.length; i = inc(i)) {
|
2017-10-02 05:05:45 +00:00
|
|
|
buffer[i] = value;
|
|
|
|
assertEquals(value, func(i * size) >>> 0);
|
|
|
|
}
|
|
|
|
VerifyBoundsCheck(func, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
(function TestAtomicLoad() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-10-02 05:05:45 +00:00
|
|
|
let wasmLoad = GetAtomicLoadFunction(kExprI32AtomicLoad, 2, 0);
|
|
|
|
let i32 = new Uint32Array(memory.buffer);
|
|
|
|
let value = 0xacedaced;
|
|
|
|
TestLoad(wasmLoad, i32, value, kMemtypeSize32);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicLoad16U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-10-02 05:05:45 +00:00
|
|
|
let wasmLoad = GetAtomicLoadFunction(kExprI32AtomicLoad16U, 1, 0);
|
|
|
|
let i16 = new Uint16Array(memory.buffer);
|
|
|
|
let value = 0xaced;
|
|
|
|
TestLoad(wasmLoad, i16, value, kMemtypeSize16);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicLoad8U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-10-02 05:05:45 +00:00
|
|
|
let wasmLoad = GetAtomicLoadFunction(kExprI32AtomicLoad8U, 0, 0);
|
|
|
|
let i8 = new Uint8Array(memory.buffer);
|
|
|
|
let value = 0xac;
|
|
|
|
TestLoad(wasmLoad, i8, value, kMemtypeSize8);
|
|
|
|
})();
|
|
|
|
|
|
|
|
function TestStore(func, buffer, value, size) {
|
2017-10-24 18:57:02 +00:00
|
|
|
for (let i = 0; i < buffer.length; i = inc(i)) {
|
2017-10-02 05:05:45 +00:00
|
|
|
func(i * size, value)
|
|
|
|
assertEquals(value, buffer[i]);
|
|
|
|
}
|
|
|
|
VerifyBoundsCheck(func, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
(function TestAtomicStore() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-10-02 05:05:45 +00:00
|
|
|
let wasmStore = GetAtomicStoreFunction(kExprI32AtomicStore, 2, 0);
|
|
|
|
let i32 = new Uint32Array(memory.buffer);
|
|
|
|
let value = 0xacedaced;
|
|
|
|
TestStore(wasmStore, i32, value, kMemtypeSize32);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicStore16U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-10-02 05:05:45 +00:00
|
|
|
let wasmStore = GetAtomicStoreFunction(kExprI32AtomicStore16U, 1, 0);
|
|
|
|
let i16 = new Uint16Array(memory.buffer);
|
|
|
|
let value = 0xaced;
|
|
|
|
TestStore(wasmStore, i16, value, kMemtypeSize16);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicStore8U() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-10-02 05:05:45 +00:00
|
|
|
let wasmStore = GetAtomicStoreFunction(kExprI32AtomicStore8U, 0, 0);
|
|
|
|
let i8 = new Uint8Array(memory.buffer);
|
|
|
|
let value = 0xac;
|
|
|
|
TestCmpExchange(wasmStore, i8, value, kMemtypeSize8);
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestAtomicLoadStoreOffset() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-10-02 05:05:45 +00:00
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
let memory = new WebAssembly.Memory({
|
|
|
|
initial: 16, maximum: 128, shared: true});
|
|
|
|
builder.addImportedMemory("m", "imported_mem", 16, 128, "shared");
|
|
|
|
builder.addFunction("loadStore", kSig_i_v)
|
|
|
|
.addBody([
|
|
|
|
kExprI32Const, 16,
|
|
|
|
kExprI32Const, 20,
|
|
|
|
kAtomicPrefix,
|
|
|
|
kExprI32AtomicStore, 0, 0xFC, 0xFF, 0x3a,
|
|
|
|
kExprI32Const, 16,
|
|
|
|
kAtomicPrefix,
|
|
|
|
kExprI32AtomicLoad, 0, 0xFC, 0xFF, 0x3a])
|
|
|
|
.exportAs("loadStore");
|
|
|
|
builder.addFunction("storeOob", kSig_v_v)
|
|
|
|
.addBody([
|
|
|
|
kExprI32Const, 16,
|
|
|
|
kExprI32Const, 20,
|
|
|
|
kAtomicPrefix,
|
|
|
|
kExprI32AtomicStore, 0, 0xFC, 0xFF, 0xFF, 0x3a])
|
|
|
|
.exportAs("storeOob");
|
|
|
|
let module = new WebAssembly.Module(builder.toBuffer());
|
|
|
|
let instance = (new WebAssembly.Instance(module,
|
|
|
|
{m: {imported_mem: memory}}));
|
|
|
|
let buf = memory.buffer;
|
|
|
|
assertEquals(20, instance.exports.loadStore());
|
|
|
|
assertTraps(kTrapMemOutOfBounds, instance.exports.storeOob);
|
|
|
|
})();
|
2017-10-04 00:23:55 +00:00
|
|
|
|
|
|
|
(function TestAtomicOpinLoop() {
|
2018-09-05 21:55:41 +00:00
|
|
|
print(arguments.callee.name);
|
2017-10-04 00:23:55 +00:00
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
let memory = new WebAssembly.Memory({
|
|
|
|
initial: 16, maximum: 128, shared: true});
|
|
|
|
builder.addImportedMemory("m", "imported_mem", 16, 128, "shared");
|
|
|
|
builder.addFunction("main", kSig_i_v)
|
|
|
|
.addBody([
|
|
|
|
kExprLoop, kWasmStmt,
|
|
|
|
kExprI32Const, 16,
|
|
|
|
kExprI32Const, 20,
|
|
|
|
kAtomicPrefix,
|
|
|
|
kExprI32AtomicStore, 2, 0,
|
|
|
|
kExprI32Const, 16,
|
|
|
|
kAtomicPrefix,
|
|
|
|
kExprI32AtomicLoad, 2, 0,
|
|
|
|
kExprReturn,
|
|
|
|
kExprEnd,
|
|
|
|
kExprI32Const, 0
|
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
let module = new WebAssembly.Module(builder.toBuffer());
|
|
|
|
let instance = (new WebAssembly.Instance(module,
|
|
|
|
{m: {imported_mem: memory}}));
|
|
|
|
assertEquals(20, instance.exports.main());
|
|
|
|
})();
|
2018-09-05 21:55:41 +00:00
|
|
|
|
|
|
|
(function TestUnalignedAtomicAccesses() {
|
|
|
|
print(arguments.callee.name);
|
|
|
|
let wasmAdd = GetAtomicBinOpFunction(kExprI32AtomicAdd, 2, 17);
|
|
|
|
assertTraps(kTrapUnalignedAccess, () => wasmAdd(4, 1001));
|
|
|
|
let wasmLoad = GetAtomicLoadFunction(kExprI32AtomicLoad16U, 1, 0);
|
|
|
|
assertTraps(kTrapUnalignedAccess, () => wasmLoad(15));
|
|
|
|
let wasmStore = GetAtomicStoreFunction(kExprI32AtomicStore, 2, 0);
|
|
|
|
assertTraps(kTrapUnalignedAccess, () => wasmStore(22, 5));
|
|
|
|
let wasmCmpExchange =
|
|
|
|
GetAtomicCmpExchangeFunction(kExprI32AtomicCompareExchange, 2, 0x16);
|
|
|
|
assertTraps(kTrapUnalignedAccess, () => wasmCmpExchange(11, 6, 5));
|
|
|
|
|
|
|
|
// Building functions with bad alignment should fail to compile
|
|
|
|
assertThrows(() => GetAtomicBinOpFunction(kExprI32AtomicSub16U, 3, 0),
|
|
|
|
WebAssembly.CompileError);
|
|
|
|
})();
|
2018-09-27 07:24:11 +00:00
|
|
|
|
|
|
|
function CmpExchgLoop(opcode, alignment) {
|
|
|
|
print("TestI64AtomicCompareExchangeLoop" + alignment);
|
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addImportedMemory("m", "imported_mem", 0, 2, "shared");
|
|
|
|
builder.addFunction("main", makeSig([kWasmI32], []))
|
|
|
|
.addLocals({i64_count: 2})
|
|
|
|
.addBody([
|
|
|
|
kExprLoop, kWasmStmt,
|
|
|
|
kExprGetLocal, 0,
|
|
|
|
kExprGetLocal, 1,
|
|
|
|
kExprGetLocal, 2,
|
|
|
|
kAtomicPrefix, opcode, alignment, 0,
|
|
|
|
kExprGetLocal, 1,
|
|
|
|
kExprI64Ne,
|
|
|
|
kExprBrIf, 0,
|
|
|
|
kExprEnd
|
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
let mem = new WebAssembly.Memory({initial: 2, maximum: 2, shared: true});
|
|
|
|
let module = new WebAssembly.Module(builder.toBuffer());
|
|
|
|
let instance = new WebAssembly.Instance(module, {m: {imported_mem: mem}});
|
|
|
|
}
|
|
|
|
|
|
|
|
(function TestAtomicCompareExchgLoop() {
|
|
|
|
CmpExchgLoop(kExprI64AtomicCompareExchange, 3);
|
|
|
|
CmpExchgLoop(kExprI64AtomicCompareExchange32U, 2);
|
|
|
|
CmpExchgLoop(kExprI64AtomicCompareExchange16U, 1);
|
|
|
|
CmpExchgLoop(kExprI64AtomicCompareExchange8U, 0);
|
|
|
|
})();
|