Skip to content

Origin/v12.x staging sable native api 2 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: origin/v12.x-staging-sable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deps/v8/gypfiles/v8.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,8 +1699,6 @@
'../src/wasm/wasm-engine.h',
'../src/wasm/wasm-external-refs.cc',
'../src/wasm/wasm-external-refs.h',
'../src/wasm/wasm-sable-external-refs.cc',
'../src/wasm/wasm-sable-external-refs.h',
'../src/wasm/wasm-feature-flags.h',
'../src/wasm/wasm-features.cc',
'../src/wasm/wasm-features.h',
Expand All @@ -1724,6 +1722,8 @@
'../src/wasm/wasm-opcodes.h',
'../src/wasm/wasm-result.cc',
'../src/wasm/wasm-result.h',
'../src/wasm/wasm-sable-external-refs.cc',
'../src/wasm/wasm-sable-external-refs.h',
'../src/wasm/wasm-serialization.cc',
'../src/wasm/wasm-serialization.h',
'../src/wasm/wasm-text.cc',
Expand Down
19 changes: 9 additions & 10 deletions deps/v8/src/compiler/wasm-compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2782,20 +2782,19 @@ Node* WasmGraphBuilder::CallNative(uint32_t index, Node** args, Node** rets,
paramStackSlotIndex += wasm::ValueTypes::ElementSizeInBytes(type);
}

// TODO benchmark bound checking (check generated assembly)
Node* linearMemory = BoundsCheckMemRange(mcgraph()->Int32Constant(0),
// TODO input another size value (maybe page size?)
mcgraph()->Int32Constant(0), position);

Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant(ExternalReference::wasm_native_call()));
Node* linearMemory = instance_cache_->mem_start;
Node* linearMemorySize = instance_cache_->mem_size;
Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant((*native.func)()));
MachineType sig_types[] = {
MachineType::Int32(), // wasm_native_call return type
MachineType::Int32(), // Native function id value
// MachineType::Int32(), // wasm_native_call return type
// MachineType::Int32(), // Native function id value
MachineType::Pointer(), // Linear memory address
// MachineType::Uint32(), // Linear memory size
MachineType::Pointer() // Stack slot address (parameter slots followed by return slots)
};
MachineSignature sig(1, 3, sig_types);
Node* call = BuildCCall(&sig, function, mcgraph()->Int32Constant(native.native_index), linearMemory, stack_slot);
MachineSignature sig(0, 2, sig_types);
Node* call = BuildCCall(&sig, function, /*mcgraph()->Int32Constant(native.native_index),*/ linearMemory,
/*linearMemorySize,*/ stack_slot);
// Check if return value is zero (currently not used)
// ZeroCheck32(wasm::kTrapFuncInvalid, call, position);

Expand Down
17 changes: 16 additions & 1 deletion deps/v8/src/external-reference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,22 @@ FUNCTION_REFERENCE(wasm_word32_rol, wasm::word32_rol_wrapper)
FUNCTION_REFERENCE(wasm_word32_ror, wasm::word32_ror_wrapper)
FUNCTION_REFERENCE(wasm_memory_copy, wasm::memory_copy_wrapper)
FUNCTION_REFERENCE(wasm_memory_fill, wasm::memory_fill_wrapper)
FUNCTION_REFERENCE(wasm_native_call, wasm::native_call_wrapper)

FUNCTION_REFERENCE(wasm_time_ms, wasm::time_ms_wrapper)
FUNCTION_REFERENCE(wasm_exp, wasm::exp_wrapper)
FUNCTION_REFERENCE(wasm_add_I32, wasm::add_wrapper<int32_t>)
FUNCTION_REFERENCE(wasm_matrix_multiplication_I32, wasm::matrix_multiplication_wrapper<int32_t>)
FUNCTION_REFERENCE(wasm_matrix_multiplication_I64, wasm::matrix_multiplication_wrapper<int64_t>)
FUNCTION_REFERENCE(wasm_matrix_multiplication_F32, wasm::matrix_multiplication_wrapper<float>)
FUNCTION_REFERENCE(wasm_matrix_multiplication_F64, wasm::matrix_multiplication_wrapper<double>)
FUNCTION_REFERENCE(wasm_print_memory_I32, wasm::print_memory_wrapper<int32_t>)
FUNCTION_REFERENCE(wasm_print_memory_I64, wasm::print_memory_wrapper<int64_t>)
FUNCTION_REFERENCE(wasm_print_memory_F32, wasm::print_memory_wrapper<float>)
FUNCTION_REFERENCE(wasm_print_memory_F64, wasm::print_memory_wrapper<double>)
FUNCTION_REFERENCE(wasm_print_stack_I32, wasm::print_stack_wrapper<int32_t>)
FUNCTION_REFERENCE(wasm_print_stack_I64, wasm::print_stack_wrapper<int64_t>)
FUNCTION_REFERENCE(wasm_print_stack_F32, wasm::print_stack_wrapper<float>)
FUNCTION_REFERENCE(wasm_print_stack_F64, wasm::print_stack_wrapper<double>)

static void f64_acos_wrapper(Address data) {
double input = ReadUnalignedValue<double>(data);
Expand Down
21 changes: 19 additions & 2 deletions deps/v8/src/external-reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ class StatsCounter;
"IsolateData::fast_c_call_caller_pc_address") \
EXTERNAL_REFERENCE_LIST_NON_INTERPRETED_REGEXP(V)

#define EXTERNAL_REFERENCE_LIST_WASM(V) \
V(wasm_time_ms, "wasm::time_ms") \
V(wasm_exp, "wasm::exp") \
V(wasm_add_I32, "wasm::add_I32") \
V(wasm_matrix_multiplication_I32, "wasm::matrix_multiplication_I32") \
V(wasm_matrix_multiplication_I64, "wasm::matrix_multiplication_I64") \
V(wasm_matrix_multiplication_F32, "wasm::matrix_multiplication_F32") \
V(wasm_matrix_multiplication_F64, "wasm::matrix_multiplication_F64") \
V(wasm_print_memory_I32, "wasm::print_memory_I32") \
V(wasm_print_memory_I64, "wasm::print_memory_I64") \
V(wasm_print_memory_F32, "wasm::print_memory_F32") \
V(wasm_print_memory_F64, "wasm::print_memory_F64") \
V(wasm_print_stack_I32, "wasm::print_stack_I32") \
V(wasm_print_stack_I64, "wasm::print_stack_I64") \
V(wasm_print_stack_F32, "wasm::print_stack_F32") \
V(wasm_print_stack_F64, "wasm::print_stack_F64") \

#define EXTERNAL_REFERENCE_LIST(V) \
V(abort_with_reason, "abort_with_reason") \
V(address_of_double_abs_constant, "double_absolute_constant") \
Expand Down Expand Up @@ -183,7 +200,6 @@ class StatsCounter;
V(wasm_word64_popcnt, "wasm::word64_popcnt") \
V(wasm_memory_copy, "wasm::memory_copy") \
V(wasm_memory_fill, "wasm::memory_fill") \
V(wasm_native_call, "wasm::native_call") \
V(call_enqueue_microtask_function, "MicrotaskQueue::CallEnqueueMicrotask") \
V(call_enter_context_function, "call_enter_context_function") \
V(atomic_pair_load_function, "atomic_pair_load_function") \
Expand All @@ -196,7 +212,8 @@ class StatsCounter;
V(atomic_pair_exchange_function, "atomic_pair_exchange_function") \
V(atomic_pair_compare_exchange_function, \
"atomic_pair_compare_exchange_function") \
EXTERNAL_REFERENCE_LIST_INTL(V)
EXTERNAL_REFERENCE_LIST_INTL(V) \
EXTERNAL_REFERENCE_LIST_WASM(V)

#ifndef V8_INTERPRETED_REGEXP
#define EXTERNAL_REFERENCE_LIST_NON_INTERPRETED_REGEXP(V) \
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/wasm/module-decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ class ModuleDecoderImpl : public Decoder {
const char* func_name = std::string(
reinterpret_cast<const char*>(start() + GetBufferRelativeOffset(native.func_name.offset())),
native.func_name.length()).c_str();
if(!find_native_function(func_name, native.sig, &native.native_index)) {
if(!find_native_function(func_name, native.sig, &native.func)) {
errorf(pc_, "native function %s not found", func_name);
}
module_->natives.push_back(std::move(native));
Expand Down
4 changes: 0 additions & 4 deletions deps/v8/src/wasm/wasm-external-refs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ void memory_fill_wrapper(Address dst, uint32_t value, uint32_t size) {
memset(reinterpret_cast<void*>(dst), value, size);
}

int32_t native_call_wrapper(uint32_t functionId, Address mem, Address data) {
return native_function_gateway(functionId, mem, data);
}

static WasmTrapCallbackForTesting wasm_trap_callback_for_testing = nullptr;

void set_trap_callback_for_testing(WasmTrapCallbackForTesting callback) {
Expand Down
10 changes: 8 additions & 2 deletions deps/v8/src/wasm/wasm-external-refs.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,20 @@ void memory_copy_wrapper(Address dst, Address src, uint32_t size);

void memory_fill_wrapper(Address dst, uint32_t value, uint32_t size);

int32_t native_call_wrapper(uint32_t functionIndex, Address mem, Address data);

typedef void (*WasmTrapCallbackForTesting)();

void set_trap_callback_for_testing(WasmTrapCallbackForTesting callback);

void call_trap_callback_for_testing();

// wasm sable external reference
void time_ms_wrapper(Address, Address);
void exp_wrapper(Address, Address);
template <class T> void matrix_multiplication_wrapper(Address, Address);
template <class T> void print_stack_wrapper(Address, Address);
template <class T> void print_memory_wrapper(Address, Address);
template <class T> void add_wrapper(Address, Address);

} // namespace wasm
} // namespace internal
} // namespace v8
Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/wasm/wasm-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ struct WasmNative {
WireBytesRef func_name; // native function name.
FunctionSig* sig; // native function signature.
int native_index; // native function enum value.
ExternalReference (*func)(); // native function enum value.
};

enum ModuleOrigin : uint8_t { kWasmOrigin, kAsmJsOrigin };
Expand Down
Loading