Commit 48d508cb authored by Stephan Herhut's avatar Stephan Herhut Committed by Commit Bot

[wasm] Add I32AtomicCompareExchange to interpreter

This adds support for the I32AtomicCompareExchange operations in the
interpreter. Also, the interpreter will now fail if it encounters
an unknown opcode from the atomic prefix.

Bug: chromium:826069
Change-Id: Iec1742271f4fdd83fcaa09ca72c24d1cf8c58835
Reviewed-on: https://chromium-review.googlesource.com/1029867Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Stephan Herhut <herhut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52807}
parent 19896840
......@@ -1467,9 +1467,10 @@ class ThreadImpl {
template <typename type>
bool ExtractAtomicOpParams(Decoder* decoder, InterpreterCode* code,
Address& address, pc_t pc, int& len,
type* val = nullptr) {
type* val = nullptr, type* val2 = nullptr) {
MemoryAccessOperand<Decoder::kNoValidate> operand(decoder, code->at(pc + 1),
sizeof(type));
if (val2) *val2 = Pop().to<uint32_t>();
if (val) *val = Pop().to<uint32_t>();
uint32_t index = Pop().to<uint32_t>();
address = BoundsCheckMem<type>(operand.offset, index);
......@@ -1554,6 +1555,27 @@ class ThreadImpl {
ATOMIC_BINOP_CASE(I32AtomicExchange8U, uint8_t, atomic_exchange);
ATOMIC_BINOP_CASE(I32AtomicExchange16U, uint16_t, atomic_exchange);
#undef ATOMIC_BINOP_CASE
#define ATOMIC_COMPARE_EXCHANGE_CASE(name, type) \
case kExpr##name: { \
type val; \
type val2; \
Address addr; \
if (!ExtractAtomicOpParams<type>(decoder, code, addr, pc, len, &val, \
&val2)) { \
return false; \
} \
static_assert(sizeof(std::atomic<type>) == sizeof(type), \
"Size mismatch for types std::atomic<" #type \
">, and " #type); \
std::atomic_compare_exchange_strong( \
reinterpret_cast<std::atomic<type>*>(addr), &val, val2); \
Push(WasmValue(val)); \
break; \
}
ATOMIC_COMPARE_EXCHANGE_CASE(I32AtomicCompareExchange, uint32_t);
ATOMIC_COMPARE_EXCHANGE_CASE(I32AtomicCompareExchange8U, uint8_t);
ATOMIC_COMPARE_EXCHANGE_CASE(I32AtomicCompareExchange16U, uint16_t);
#undef ATOMIC_COMPARE_EXCHANGE_CASE
#define ATOMIC_LOAD_CASE(name, type, operation) \
case kExpr##name: { \
Address addr; \
......@@ -1590,6 +1612,7 @@ class ThreadImpl {
ATOMIC_STORE_CASE(I32AtomicStore16U, uint16_t, atomic_store);
#undef ATOMIC_STORE_CASE
default:
UNREACHABLE();
return false;
}
return true;
......
......@@ -131,7 +131,7 @@ WASM_EXEC_TEST(I32AtomicExchange8U) {
RunU8BinOp(execution_mode, kExprI32AtomicExchange8U, Exchange);
}
WASM_COMPILED_EXEC_TEST(I32AtomicCompareExchange) {
WASM_EXEC_TEST(I32AtomicCompareExchange) {
EXPERIMENTAL_FLAG_SCOPE(threads);
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
r.builder().SetHasSharedMemory();
......@@ -151,7 +151,7 @@ WASM_COMPILED_EXEC_TEST(I32AtomicCompareExchange) {
}
}
WASM_COMPILED_EXEC_TEST(I32AtomicCompareExchange16U) {
WASM_EXEC_TEST(I32AtomicCompareExchange16U) {
EXPERIMENTAL_FLAG_SCOPE(threads);
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
r.builder().SetHasSharedMemory();
......@@ -172,7 +172,7 @@ WASM_COMPILED_EXEC_TEST(I32AtomicCompareExchange16U) {
}
}
WASM_COMPILED_EXEC_TEST(I32AtomicCompareExchange8U) {
WASM_EXEC_TEST(I32AtomicCompareExchange8U) {
EXPERIMENTAL_FLAG_SCOPE(threads);
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
r.builder().SetHasSharedMemory();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment