Commit 4cfa97f6 authored by Deepti Gandluri's avatar Deepti Gandluri Committed by Commit Bot

[wasm] Add atomics wait/notify to the interpreter, enable tests.

Bug: chromium:1027441
Change-Id: Ieac67e06aebf57a11327cbd34dd31f62cbe540b1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1957847
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65415}
parent 38b4b671
......@@ -1743,6 +1743,39 @@ class ThreadImpl {
return true;
}
template <typename type>
bool ExtractAtomicWaitNotifyParams(Decoder* decoder, InterpreterCode* code,
pc_t pc, int* const len,
uint32_t* buffer_offset, type* val,
double* timeout = nullptr) {
MemoryAccessImmediate<Decoder::kValidate> imm(decoder, code->at(pc + 1),
sizeof(type));
if (timeout) {
double timeout_ns = Pop().to<int64_t>();
*timeout = (timeout_ns < 0)
? V8_INFINITY
: timeout_ns / (base::Time::kNanosecondsPerMicrosecond *
base::Time::kMicrosecondsPerMillisecond);
}
*val = Pop().to<type>();
auto index = Pop().to<uint32_t>();
// Check bounds.
Address address = BoundsCheckMem<uint32_t>(imm.offset, index);
*buffer_offset = index + imm.offset;
if (!address) {
DoTrap(kTrapMemOutOfBounds, pc);
return false;
}
// Check alignment.
const uint32_t align_mask = sizeof(type) - 1;
if ((*buffer_offset & align_mask) != 0) {
DoTrap(kTrapUnalignedAccess, pc);
return false;
}
*len = 2 + imm.length;
return true;
}
bool ExecuteNumericOp(WasmOpcode opcode, Decoder* decoder,
InterpreterCode* code, pc_t pc, int* const len) {
switch (opcode) {
......@@ -2129,6 +2162,52 @@ class ThreadImpl {
std::atomic_thread_fence(std::memory_order_seq_cst);
*len += 2;
break;
case kExprI32AtomicWait: {
int32_t val;
double timeout;
uint32_t buffer_offset;
if (!ExtractAtomicWaitNotifyParams<int32_t>(
decoder, code, pc, len, &buffer_offset, &val, &timeout)) {
return false;
}
HandleScope handle_scope(isolate_);
Handle<JSArrayBuffer> array_buffer(
instance_object_->memory_object().array_buffer(), isolate_);
auto result = FutexEmulation::Wait32(isolate_, array_buffer,
buffer_offset, val, timeout);
Push(WasmValue(result.ToSmi().value()));
break;
}
case kExprI64AtomicWait: {
int64_t val;
double timeout;
uint32_t buffer_offset;
if (!ExtractAtomicWaitNotifyParams<int64_t>(
decoder, code, pc, len, &buffer_offset, &val, &timeout)) {
return false;
}
HandleScope handle_scope(isolate_);
Handle<JSArrayBuffer> array_buffer(
instance_object_->memory_object().array_buffer(), isolate_);
auto result = FutexEmulation::Wait64(isolate_, array_buffer,
buffer_offset, val, timeout);
Push(WasmValue(result.ToSmi().value()));
break;
}
case kExprAtomicNotify: {
int32_t val;
uint32_t buffer_offset;
if (!ExtractAtomicWaitNotifyParams<int32_t>(decoder, code, pc, len,
&buffer_offset, &val)) {
return false;
}
HandleScope handle_scope(isolate_);
Handle<JSArrayBuffer> array_buffer(
instance_object_->memory_object().array_buffer(), isolate_);
auto result = FutexEmulation::Wake(array_buffer, buffer_offset, val);
Push(WasmValue(result.ToSmi().value()));
break;
}
default:
UNREACHABLE();
return false;
......
// Copyright 2019 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 --allow-natives-syntax
// Flags: --wasm-interpret-all
// This is a wrapper for existing futex tests with the --wasm-interpret-all
// flag added. If we ever decide to add a test variant for this, this file can
// be removed.
load("test/mjsunit/wasm/futex.js");
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