aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/test/cctest/wasm/test-run-wasm-atomics64.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/cctest/wasm/test-run-wasm-atomics64.cc')
-rw-r--r--deps/v8/test/cctest/wasm/test-run-wasm-atomics64.cc262
1 files changed, 190 insertions, 72 deletions
diff --git a/deps/v8/test/cctest/wasm/test-run-wasm-atomics64.cc b/deps/v8/test/cctest/wasm/test-run-wasm-atomics64.cc
index 21b943595a..570c48d240 100644
--- a/deps/v8/test/cctest/wasm/test-run-wasm-atomics64.cc
+++ b/deps/v8/test/cctest/wasm/test-run-wasm-atomics64.cc
@@ -32,24 +32,12 @@ void RunU64BinOp(ExecutionTier execution_tier, WasmOpcode wasm_op,
}
}
-WASM_EXEC_TEST(I64AtomicAdd) {
- RunU64BinOp(execution_tier, kExprI64AtomicAdd, Add);
-}
-WASM_EXEC_TEST(I64AtomicSub) {
- RunU64BinOp(execution_tier, kExprI64AtomicSub, Sub);
-}
-WASM_EXEC_TEST(I64AtomicAnd) {
- RunU64BinOp(execution_tier, kExprI64AtomicAnd, And);
-}
-WASM_EXEC_TEST(I64AtomicOr) {
- RunU64BinOp(execution_tier, kExprI64AtomicOr, Or);
-}
-WASM_EXEC_TEST(I64AtomicXor) {
- RunU64BinOp(execution_tier, kExprI64AtomicXor, Xor);
-}
-WASM_EXEC_TEST(I64AtomicExchange) {
- RunU64BinOp(execution_tier, kExprI64AtomicExchange, Exchange);
-}
+#define TEST_OPERATION(Name) \
+ WASM_EXEC_TEST(I64Atomic##Name) { \
+ RunU64BinOp(execution_tier, kExprI64Atomic##Name, Name); \
+ }
+OPERATION_LIST(TEST_OPERATION)
+#undef TEST_OPERATION
void RunU32BinOp(ExecutionTier execution_tier, WasmOpcode wasm_op,
Uint32BinOp expected_op) {
@@ -73,24 +61,12 @@ void RunU32BinOp(ExecutionTier execution_tier, WasmOpcode wasm_op,
}
}
-WASM_EXEC_TEST(I64AtomicAdd32U) {
- RunU32BinOp(execution_tier, kExprI64AtomicAdd32U, Add);
-}
-WASM_EXEC_TEST(I64AtomicSub32U) {
- RunU32BinOp(execution_tier, kExprI64AtomicSub32U, Sub);
-}
-WASM_EXEC_TEST(I64AtomicAnd32U) {
- RunU32BinOp(execution_tier, kExprI64AtomicAnd32U, And);
-}
-WASM_EXEC_TEST(I64AtomicOr32U) {
- RunU32BinOp(execution_tier, kExprI64AtomicOr32U, Or);
-}
-WASM_EXEC_TEST(I64AtomicXor32U) {
- RunU32BinOp(execution_tier, kExprI64AtomicXor32U, Xor);
-}
-WASM_EXEC_TEST(I64AtomicExchange32U) {
- RunU32BinOp(execution_tier, kExprI64AtomicExchange32U, Exchange);
-}
+#define TEST_OPERATION(Name) \
+ WASM_EXEC_TEST(I64Atomic##Name##32U) { \
+ RunU32BinOp(execution_tier, kExprI64Atomic##Name##32U, Name); \
+ }
+OPERATION_LIST(TEST_OPERATION)
+#undef TEST_OPERATION
void RunU16BinOp(ExecutionTier tier, WasmOpcode wasm_op,
Uint16BinOp expected_op) {
@@ -114,24 +90,12 @@ void RunU16BinOp(ExecutionTier tier, WasmOpcode wasm_op,
}
}
-WASM_EXEC_TEST(I64AtomicAdd16U) {
- RunU16BinOp(execution_tier, kExprI64AtomicAdd16U, Add);
-}
-WASM_EXEC_TEST(I64AtomicSub16U) {
- RunU16BinOp(execution_tier, kExprI64AtomicSub16U, Sub);
-}
-WASM_EXEC_TEST(I64AtomicAnd16U) {
- RunU16BinOp(execution_tier, kExprI64AtomicAnd16U, And);
-}
-WASM_EXEC_TEST(I64AtomicOr16U) {
- RunU16BinOp(execution_tier, kExprI64AtomicOr16U, Or);
-}
-WASM_EXEC_TEST(I64AtomicXor16U) {
- RunU16BinOp(execution_tier, kExprI64AtomicXor16U, Xor);
-}
-WASM_EXEC_TEST(I64AtomicExchange16U) {
- RunU16BinOp(execution_tier, kExprI64AtomicExchange16U, Exchange);
-}
+#define TEST_OPERATION(Name) \
+ WASM_EXEC_TEST(I64Atomic##Name##16U) { \
+ RunU16BinOp(execution_tier, kExprI64Atomic##Name##16U, Name); \
+ }
+OPERATION_LIST(TEST_OPERATION)
+#undef TEST_OPERATION
void RunU8BinOp(ExecutionTier execution_tier, WasmOpcode wasm_op,
Uint8BinOp expected_op) {
@@ -154,24 +118,12 @@ void RunU8BinOp(ExecutionTier execution_tier, WasmOpcode wasm_op,
}
}
-WASM_EXEC_TEST(I64AtomicAdd8U) {
- RunU8BinOp(execution_tier, kExprI64AtomicAdd8U, Add);
-}
-WASM_EXEC_TEST(I64AtomicSub8U) {
- RunU8BinOp(execution_tier, kExprI64AtomicSub8U, Sub);
-}
-WASM_EXEC_TEST(I64AtomicAnd8U) {
- RunU8BinOp(execution_tier, kExprI64AtomicAnd8U, And);
-}
-WASM_EXEC_TEST(I64AtomicOr8U) {
- RunU8BinOp(execution_tier, kExprI64AtomicOr8U, Or);
-}
-WASM_EXEC_TEST(I64AtomicXor8U) {
- RunU8BinOp(execution_tier, kExprI64AtomicXor8U, Xor);
-}
-WASM_EXEC_TEST(I64AtomicExchange8U) {
- RunU8BinOp(execution_tier, kExprI64AtomicExchange8U, Exchange);
-}
+#define TEST_OPERATION(Name) \
+ WASM_EXEC_TEST(I64Atomic##Name##8U) { \
+ RunU8BinOp(execution_tier, kExprI64Atomic##Name##8U, Name); \
+ }
+OPERATION_LIST(TEST_OPERATION)
+#undef TEST_OPERATION
WASM_EXEC_TEST(I64AtomicCompareExchange) {
EXPERIMENTAL_FLAG_SCOPE(threads);
@@ -402,6 +354,172 @@ WASM_EXEC_TEST(I64AtomicStoreLoad8U) {
}
}
+// Drop tests verify atomic operations are run correctly when the
+// entire 64-bit output is optimized out
+void RunDropTest(ExecutionTier execution_tier, WasmOpcode wasm_op,
+ Uint64BinOp op) {
+ EXPERIMENTAL_FLAG_SCOPE(threads);
+ WasmRunner<uint64_t, uint64_t> r(execution_tier);
+ uint64_t* memory =
+ r.builder().AddMemoryElems<uint64_t>(kWasmPageSize / sizeof(uint64_t));
+ r.builder().SetHasSharedMemory();
+
+ BUILD(r,
+ WASM_ATOMICS_BINOP(wasm_op, WASM_I32V_1(0), WASM_GET_LOCAL(0),
+ MachineRepresentation::kWord64),
+ WASM_DROP, WASM_GET_LOCAL(0));
+
+ uint64_t initial = 0x1111222233334444, local = 0x1111111111111111;
+ r.builder().WriteMemory(&memory[0], initial);
+ CHECK_EQ(local, r.Call(local));
+ uint64_t expected = op(initial, local);
+ CHECK_EQ(expected, r.builder().ReadMemory(&memory[0]));
+}
+
+#define TEST_OPERATION(Name) \
+ WASM_EXEC_TEST(I64Atomic##Name##Drop) { \
+ RunDropTest(execution_tier, kExprI64Atomic##Name, Name); \
+ }
+OPERATION_LIST(TEST_OPERATION)
+#undef TEST_OPERATION
+
+WASM_EXEC_TEST(I64AtomicSub16UDrop) {
+ EXPERIMENTAL_FLAG_SCOPE(threads);
+ WasmRunner<uint64_t, uint64_t> r(execution_tier);
+ uint16_t* memory =
+ r.builder().AddMemoryElems<uint16_t>(kWasmPageSize / sizeof(uint16_t));
+ r.builder().SetHasSharedMemory();
+
+ BUILD(r,
+ WASM_ATOMICS_BINOP(kExprI64AtomicSub16U, WASM_I32V_1(0),
+ WASM_GET_LOCAL(0), MachineRepresentation::kWord16),
+ WASM_DROP, WASM_GET_LOCAL(0));
+
+ uint16_t initial = 0x7, local = 0xffe0;
+ r.builder().WriteMemory(&memory[0], initial);
+ CHECK_EQ(local, r.Call(local));
+ uint16_t expected = Sub(initial, local);
+ CHECK_EQ(expected, r.builder().ReadMemory(&memory[0]));
+}
+
+WASM_EXEC_TEST(I64AtomicCompareExchangeDrop) {
+ EXPERIMENTAL_FLAG_SCOPE(threads);
+ WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_tier);
+ r.builder().SetHasSharedMemory();
+ uint64_t* memory =
+ r.builder().AddMemoryElems<uint64_t>(kWasmPageSize / sizeof(uint64_t));
+ BUILD(r,
+ WASM_ATOMICS_TERNARY_OP(kExprI64AtomicCompareExchange, WASM_I32V_1(0),
+ WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
+ MachineRepresentation::kWord64),
+ WASM_DROP, WASM_GET_LOCAL(1));
+
+ uint64_t initial = 0x1111222233334444, local = 0x1111111111111111;
+ r.builder().WriteMemory(&memory[0], initial);
+ CHECK_EQ(local, r.Call(initial, local));
+ uint64_t expected = CompareExchange(initial, initial, local);
+ CHECK_EQ(expected, r.builder().ReadMemory(&memory[0]));
+}
+
+WASM_EXEC_TEST(I64AtomicStoreLoadDrop) {
+ EXPERIMENTAL_FLAG_SCOPE(threads);
+ WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_tier);
+ r.builder().SetHasSharedMemory();
+ uint64_t* memory =
+ r.builder().AddMemoryElems<uint64_t>(kWasmPageSize / sizeof(uint64_t));
+
+ BUILD(r,
+ WASM_ATOMICS_STORE_OP(kExprI64AtomicStore, WASM_ZERO, WASM_GET_LOCAL(0),
+ MachineRepresentation::kWord64),
+ WASM_ATOMICS_LOAD_OP(kExprI64AtomicLoad, WASM_ZERO,
+ MachineRepresentation::kWord64),
+ WASM_DROP, WASM_GET_LOCAL(1));
+
+ uint64_t store_value = 0x1111111111111111, expected = 0xC0DE;
+ CHECK_EQ(expected, r.Call(store_value, expected));
+ CHECK_EQ(store_value, r.builder().ReadMemory(&memory[0]));
+}
+
+WASM_EXEC_TEST(I64AtomicAddConvertDrop) {
+ EXPERIMENTAL_FLAG_SCOPE(threads);
+ WasmRunner<uint64_t, uint64_t> r(execution_tier);
+ uint64_t* memory =
+ r.builder().AddMemoryElems<uint64_t>(kWasmPageSize / sizeof(uint64_t));
+ r.builder().SetHasSharedMemory();
+
+ BUILD(r,
+ WASM_ATOMICS_BINOP(kExprI64AtomicAdd, WASM_I32V_1(0), WASM_GET_LOCAL(0),
+ MachineRepresentation::kWord64),
+ kExprI32ConvertI64, WASM_DROP, WASM_GET_LOCAL(0));
+
+ uint64_t initial = 0x1111222233334444, local = 0x1111111111111111;
+ r.builder().WriteMemory(&memory[0], initial);
+ CHECK_EQ(local, r.Call(local));
+ uint64_t expected = Add(initial, local);
+ CHECK_EQ(expected, r.builder().ReadMemory(&memory[0]));
+}
+
+WASM_EXEC_TEST(I64AtomicLoadConvertDrop) {
+ EXPERIMENTAL_FLAG_SCOPE(threads);
+ WasmRunner<uint32_t, uint64_t> r(execution_tier);
+ uint64_t* memory =
+ r.builder().AddMemoryElems<uint64_t>(kWasmPageSize / sizeof(uint64_t));
+ r.builder().SetHasSharedMemory();
+
+ BUILD(r, WASM_I32_CONVERT_I64(WASM_ATOMICS_LOAD_OP(
+ kExprI64AtomicLoad, WASM_ZERO, MachineRepresentation::kWord64)));
+
+ uint64_t initial = 0x1111222233334444;
+ r.builder().WriteMemory(&memory[0], initial);
+ CHECK_EQ(static_cast<uint32_t>(initial), r.Call(initial));
+}
+
+// Convert tests verify atomic operations are run correctly when the
+// upper half of the 64-bit output is optimized out
+void RunConvertTest(ExecutionTier execution_tier, WasmOpcode wasm_op,
+ Uint64BinOp op) {
+ EXPERIMENTAL_FLAG_SCOPE(threads);
+ WasmRunner<uint32_t, uint64_t> r(execution_tier);
+ uint64_t* memory =
+ r.builder().AddMemoryElems<uint64_t>(kWasmPageSize / sizeof(uint64_t));
+ r.builder().SetHasSharedMemory();
+
+ BUILD(r, WASM_I32_CONVERT_I64(WASM_ATOMICS_BINOP(
+ kExprI64AtomicAdd, WASM_ZERO, WASM_GET_LOCAL(0),
+ MachineRepresentation::kWord64)));
+
+ uint64_t initial = 0x1111222233334444, local = 0x1111111111111111;
+ r.builder().WriteMemory(&memory[0], initial);
+ CHECK_EQ(static_cast<uint32_t>(initial), r.Call(local));
+ uint64_t expected = Add(initial, local);
+ CHECK_EQ(expected, r.builder().ReadMemory(&memory[0]));
+}
+
+#define TEST_OPERATION(Name) \
+ WASM_EXEC_TEST(I64AtomicConvert##Name) { \
+ RunConvertTest(execution_tier, kExprI64Atomic##Name, Name); \
+ }
+OPERATION_LIST(TEST_OPERATION)
+#undef TEST_OPERATION
+
+WASM_EXEC_TEST(I64AtomicConvertCompareExchange) {
+ EXPERIMENTAL_FLAG_SCOPE(threads);
+ WasmRunner<uint32_t, uint64_t, uint64_t> r(execution_tier);
+ uint64_t* memory =
+ r.builder().AddMemoryElems<uint64_t>(kWasmPageSize / sizeof(uint64_t));
+ r.builder().SetHasSharedMemory();
+
+ BUILD(r, WASM_I32_CONVERT_I64(WASM_ATOMICS_TERNARY_OP(
+ kExprI64AtomicCompareExchange, WASM_I32V_1(0), WASM_GET_LOCAL(0),
+ WASM_GET_LOCAL(1), MachineRepresentation::kWord64)));
+
+ uint64_t initial = 0x1111222233334444, local = 0x1111111111111111;
+ r.builder().WriteMemory(&memory[0], initial);
+ CHECK_EQ(static_cast<uint32_t>(initial), r.Call(initial, local));
+ uint64_t expected = CompareExchange(initial, initial, local);
+ CHECK_EQ(expected, r.builder().ReadMemory(&memory[0]));
+}
+
} // namespace test_run_wasm_atomics_64
} // namespace wasm
} // namespace internal