Commit 0ae14a49 authored by Junliang Yan's avatar Junliang Yan Committed by Commit Bot

[wasm] Add BE support for atomic operations for wasm interpreter

This fixes RunWasmInterpreter_* tests on big endian mips/ppc/s390.

Change-Id: I4b9b767d0de45004ee1195ac225c6d1027c17a05
Reviewed-on: https://chromium-review.googlesource.com/c/1439517
Commit-Queue: Junliang Yan <jyan@ca.ibm.com>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59174}
parent 14054ad9
......@@ -1065,34 +1065,30 @@ bool StringToArrayIndex(Stream* stream, uint32_t* index);
// return an address significantly above the actual current stack position.
V8_NOINLINE uintptr_t GetCurrentStackPosition();
template <typename V>
static inline V ByteReverse(V value) {
size_t size_of_v = sizeof(value);
switch (size_of_v) {
case 2:
static inline uint16_t ByteReverse16(uint16_t value) {
#if V8_HAS_BUILTIN_BSWAP16
return static_cast<V>(__builtin_bswap16(static_cast<uint16_t>(value)));
return __builtin_bswap16(value);
#else
return value << 8 | (value >> 8 & 0x00FF);
#endif
case 4:
}
static inline uint32_t ByteReverse32(uint32_t value) {
#if V8_HAS_BUILTIN_BSWAP32
return static_cast<V>(__builtin_bswap32(static_cast<uint32_t>(value)));
return __builtin_bswap32(value);
#else
{
size_t bits_of_v = size_of_v * kBitsPerByte;
return value << (bits_of_v - 8) |
((value << (bits_of_v - 24)) & 0x00FF0000) |
((value >> (bits_of_v - 24)) & 0x0000FF00) |
((value >> (bits_of_v - 8)) & 0x00000FF);
}
return value << 24 |
((value << 8) & 0x00FF0000) |
((value >> 8) & 0x0000FF00) |
((value >> 24) & 0x00000FF);
#endif
case 8:
}
static inline uint64_t ByteReverse64(uint64_t value) {
#if V8_HAS_BUILTIN_BSWAP64
return static_cast<V>(__builtin_bswap64(static_cast<uint64_t>(value)));
return __builtin_bswap64(value);
#else
{
size_t bits_of_v = size_of_v * kBitsPerByte;
size_t bits_of_v = sizeof(value) * kBitsPerByte;
return value << (bits_of_v - 8) |
((value << (bits_of_v - 24)) & 0x00FF000000000000) |
((value << (bits_of_v - 40)) & 0x0000FF0000000000) |
......@@ -1101,8 +1097,21 @@ static inline V ByteReverse(V value) {
((value >> (bits_of_v - 40)) & 0x0000000000FF0000) |
((value >> (bits_of_v - 24)) & 0x000000000000FF00) |
((value >> (bits_of_v - 8)) & 0x00000000000000FF);
}
#endif
}
template <typename V>
static inline V ByteReverse(V value) {
size_t size_of_v = sizeof(value);
switch (size_of_v) {
case 1:
return value;
case 2:
return static_cast<V>(ByteReverse16(static_cast<uint16_t>(value)));
case 4:
return static_cast<V>(ByteReverse32(static_cast<uint32_t>(value)));
case 8:
return static_cast<V>(ByteReverse64(static_cast<uint64_t>(value)));
default:
UNREACHABLE();
}
......
This diff is collapsed.
......@@ -160,6 +160,28 @@ WASM_EXEC_TEST(I32AtomicCompareExchange8U) {
}
}
WASM_EXEC_TEST(I32AtomicCompareExchange_fail) {
EXPERIMENTAL_FLAG_SCOPE(threads);
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_tier);
r.builder().SetHasSharedMemory();
uint32_t* memory =
r.builder().AddMemoryElems<uint32_t>(kWasmPageSize / sizeof(uint32_t));
BUILD(r, WASM_ATOMICS_TERNARY_OP(
kExprI32AtomicCompareExchange, WASM_I32V_1(0), WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1), MachineRepresentation::kWord32));
// The original value at the memory location.
uint32_t old_val = 4;
// The value we use as the expected value for the compare-exchange so that it
// fails.
uint32_t expected = 6;
// The new value for the compare-exchange.
uint32_t new_val = 5;
r.builder().WriteMemory(&memory[0], old_val);
CHECK_EQ(old_val, r.Call(expected, new_val));
}
WASM_EXEC_TEST(I32AtomicLoad) {
EXPERIMENTAL_FLAG_SCOPE(threads);
WasmRunner<uint32_t> r(execution_tier);
......
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