diff --git a/deps/v8/gypfiles/v8.gyp b/deps/v8/gypfiles/v8.gyp index 566f19a96b3696..8ca0f2d585056f 100644 --- a/deps/v8/gypfiles/v8.gyp +++ b/deps/v8/gypfiles/v8.gyp @@ -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', @@ -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', diff --git a/deps/v8/src/compiler/wasm-compiler.cc b/deps/v8/src/compiler/wasm-compiler.cc index ffc3bba4377d1c..d674f98c5fa105 100644 --- a/deps/v8/src/compiler/wasm-compiler.cc +++ b/deps/v8/src/compiler/wasm-compiler.cc @@ -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); diff --git a/deps/v8/src/external-reference.cc b/deps/v8/src/external-reference.cc index 1b3e9d23a76445..f411cf197066c5 100644 --- a/deps/v8/src/external-reference.cc +++ b/deps/v8/src/external-reference.cc @@ -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) +FUNCTION_REFERENCE(wasm_matrix_multiplication_I32, wasm::matrix_multiplication_wrapper) +FUNCTION_REFERENCE(wasm_matrix_multiplication_I64, wasm::matrix_multiplication_wrapper) +FUNCTION_REFERENCE(wasm_matrix_multiplication_F32, wasm::matrix_multiplication_wrapper) +FUNCTION_REFERENCE(wasm_matrix_multiplication_F64, wasm::matrix_multiplication_wrapper) +FUNCTION_REFERENCE(wasm_print_memory_I32, wasm::print_memory_wrapper) +FUNCTION_REFERENCE(wasm_print_memory_I64, wasm::print_memory_wrapper) +FUNCTION_REFERENCE(wasm_print_memory_F32, wasm::print_memory_wrapper) +FUNCTION_REFERENCE(wasm_print_memory_F64, wasm::print_memory_wrapper) +FUNCTION_REFERENCE(wasm_print_stack_I32, wasm::print_stack_wrapper) +FUNCTION_REFERENCE(wasm_print_stack_I64, wasm::print_stack_wrapper) +FUNCTION_REFERENCE(wasm_print_stack_F32, wasm::print_stack_wrapper) +FUNCTION_REFERENCE(wasm_print_stack_F64, wasm::print_stack_wrapper) static void f64_acos_wrapper(Address data) { double input = ReadUnalignedValue(data); diff --git a/deps/v8/src/external-reference.h b/deps/v8/src/external-reference.h index 70c65d184dbde1..5c8e2a2a238ed0 100644 --- a/deps/v8/src/external-reference.h +++ b/deps/v8/src/external-reference.h @@ -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") \ @@ -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") \ @@ -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) \ diff --git a/deps/v8/src/wasm/module-decoder.cc b/deps/v8/src/wasm/module-decoder.cc index 266b16b1f7df75..c06a601d98d534 100644 --- a/deps/v8/src/wasm/module-decoder.cc +++ b/deps/v8/src/wasm/module-decoder.cc @@ -501,7 +501,7 @@ class ModuleDecoderImpl : public Decoder { const char* func_name = std::string( reinterpret_cast(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)); diff --git a/deps/v8/src/wasm/wasm-external-refs.cc b/deps/v8/src/wasm/wasm-external-refs.cc index b4fac55e3f6ec1..e382f3849e91c9 100644 --- a/deps/v8/src/wasm/wasm-external-refs.cc +++ b/deps/v8/src/wasm/wasm-external-refs.cc @@ -257,10 +257,6 @@ void memory_fill_wrapper(Address dst, uint32_t value, uint32_t size) { memset(reinterpret_cast(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) { diff --git a/deps/v8/src/wasm/wasm-external-refs.h b/deps/v8/src/wasm/wasm-external-refs.h index bf600d0dbbfe15..7bca3f7201de77 100644 --- a/deps/v8/src/wasm/wasm-external-refs.h +++ b/deps/v8/src/wasm/wasm-external-refs.h @@ -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 void matrix_multiplication_wrapper(Address, Address); +template void print_stack_wrapper(Address, Address); +template void print_memory_wrapper(Address, Address); +template void add_wrapper(Address, Address); + } // namespace wasm } // namespace internal } // namespace v8 diff --git a/deps/v8/src/wasm/wasm-module.h b/deps/v8/src/wasm/wasm-module.h index b5a2ff648ad244..a27f39bf7dcc40 100644 --- a/deps/v8/src/wasm/wasm-module.h +++ b/deps/v8/src/wasm/wasm-module.h @@ -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 }; diff --git a/deps/v8/src/wasm/wasm-sable-external-refs.cc b/deps/v8/src/wasm/wasm-sable-external-refs.cc index c39354cde60ab7..732a7286898ec9 100644 --- a/deps/v8/src/wasm/wasm-sable-external-refs.cc +++ b/deps/v8/src/wasm/wasm-sable-external-refs.cc @@ -2,8 +2,8 @@ #include "src/signature.h" #include "src/base/ieee754.h" #include -#include #include +#include namespace v8 { namespace internal { @@ -13,14 +13,14 @@ namespace wasm { * Helper functions ********************/ template -inline T ReadValue(byte* address) { +inline T ReadValue(T* address) { return ReadUnalignedValue(reinterpret_cast
(address)); } template -inline T ReadValueAndAdvance(byte** address) { +inline T ReadValueAndAdvance(T** address) { T val = ReadValue(*address); - *address += sizeof(T); + (*address)++; return val; } @@ -32,124 +32,28 @@ inline void WriteValue(T* address, T val) { template inline void WriteValueAndAdvance(T** address, T val) { WriteValue(*address, val); - *address += sizeof(T); + (*address)++; } -/********************* - * Defines - *********************/ -#define ___ void -#define I32 int32_t -#define I64 int64_t -#define F32 float -#define F64 double - -// all native functions should be declared -// in FOREACH_NATIVE_FUNCTION_[NON_]TEMPLATE -#define FOREACH_NATIVE_FUNCTION_NON_TEMPLATE(V, P, R) \ - V(exp, "f64.exp", ___, P(kWasmF64), R(kWasmF64)) \ - V(time_ms, "i64.time_ms", ___, P(), R(kWasmI64)) - -#define FOREACH_NATIVE_FUNCTION_TEMPLATE(V, P, R) \ - V(matrix_multiplication, "i32.mat_mul", I32, P(kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32), R()) \ - V(matrix_multiplication, "i64.mat_mul", I64, P(kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32), R()) \ - V(matrix_multiplication, "f32.mat_mul", F32, P(kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32), R()) \ - V(matrix_multiplication, "f64.mat_mul", F64, P(kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32), R()) \ - V(print_mem, "i32.print_m", I32, P(kWasmI32, kWasmI32), R()) \ - V(print_mem, "i64.print_m", I64, P(kWasmI32, kWasmI32), R()) \ - V(print_mem, "f32.print_m", F32, P(kWasmI32, kWasmI32), R()) \ - V(print_mem, "f64.print_m", F64, P(kWasmI32, kWasmI32), R()) \ - V(print_stack, "i32.print_s", I32, P(kWasmI32), R()) \ - V(print_stack, "i64.print_s", I64, P(kWasmI64), R()) \ - V(print_stack, "f32.print_s", F32, P(kWasmF32), R()) \ - V(print_stack, "f64.print_s", F64, P(kWasmF64), R()) - -#define FOREACH_NATIVE_FUNCTION(V, P, R) \ - FOREACH_NATIVE_FUNCTION_NON_TEMPLATE(V, P, R) \ - FOREACH_NATIVE_FUNCTION_TEMPLATE(V, P, R) - -// declare functions prototype -#define NATIVE_FUNCTION_PROTOTYPE(function, name, type, param, ret) \ - void f_##function(byte*,byte*); - FOREACH_NATIVE_FUNCTION_NON_TEMPLATE(NATIVE_FUNCTION_PROTOTYPE, ___, ___) -#undef NATIVE_FUNCTION_PROTOTYPE - -#define NATIVE_FUNCTION_PROTOTYPE(function, name, type, param, ret) \ - template \ - void f_##function(byte*,byte*); - FOREACH_NATIVE_FUNCTION_TEMPLATE(NATIVE_FUNCTION_PROTOTYPE, ___, ___) -#undef NATIVE_FUNCTION_PROTOTYPE - -// use an enum to give each function -// a unique index -enum NativeFunction { - FIRST, -#define NATIVE_FUNCTION_ENUM(function, name, type, param, ret) \ - k##function##_##type, -FOREACH_NATIVE_FUNCTION(NATIVE_FUNCTION_ENUM, ___, ___) -#undef NATIVE_FUNCTION_ENUM - LAST -}; - -// structure to hold the definition -// of a native function -typedef void (*native)(byte*, byte*); -struct NativeFunctionDefinition { - native func; - NativeFunction id; - std::vector params; - std::vector rets; - bool sig_match(FunctionSig *sig) { - if(params.size() != sig->parameter_count() || rets.size() != sig->return_count()) { - return false; - } - for(size_t i=0; i < params.size(); i++) { - if(params[i] != sig->GetParam(i)) { - return false; - } - } - for(size_t i=0; i < rets.size(); i++) { - if(rets[i] != sig->GetReturn(i)) { - return false; - } - } - return true; - } -}; - -// store all native functions into -// a global array -NativeFunctionDefinition g_functions[] = { - {}, // NativeFunction::FIRST -#define ARGS_TO_VECTOR(...) {__VA_ARGS__} -#define NATIVE_FUNCTION_ARRAY(function, name, type, param, ret) \ - {f_##function, k##function##_##type, param, ret}, - FOREACH_NATIVE_FUNCTION_NON_TEMPLATE(NATIVE_FUNCTION_ARRAY, ARGS_TO_VECTOR, ARGS_TO_VECTOR) -#undef NATIVE_FUNCTION_ARRAY - -#define NATIVE_FUNCTION_ARRAY(function, name, type, param, ret) \ - {f_##function, k##function##_##type, param, ret}, - FOREACH_NATIVE_FUNCTION_TEMPLATE(NATIVE_FUNCTION_ARRAY, ARGS_TO_VECTOR, ARGS_TO_VECTOR) -#undef NATIVE_FUNCTION_ARRAY -#undef ARGS_TO_VECTOR -}; - /******************* * Native functions ******************/ template -void f_matrix_multiplication(byte* memByte, byte* dataByte) { - I32 mat1Offset = ReadValueAndAdvance(&dataByte); - I32 mat2Offset = ReadValueAndAdvance(&dataByte); - I32 resOffset = ReadValueAndAdvance(&dataByte); - I32 m = ReadValueAndAdvance(&dataByte); - I32 n = ReadValueAndAdvance(&dataByte); - I32 p = ReadValueAndAdvance(&dataByte); - - T* mat1 = reinterpret_cast(memByte + mat1Offset); - T* mat2 = reinterpret_cast(memByte + mat2Offset); - T* res = reinterpret_cast(memByte + resOffset); +void matrix_multiplication_wrapper(Address mem, Address data) { + I32* stack = reinterpret_cast(data); + byte* lmem = reinterpret_cast(mem); + + I32 mat1Offset = *(stack); + I32 mat2Offset = *(stack += 1); + I32 resOffset = *(stack += 1); + I32 m = *(stack += 1); + I32 n = *(stack += 1); + I32 p = *(stack += 1); + + T* mat1 = reinterpret_cast(lmem + mat1Offset); + T* mat2 = reinterpret_cast(lmem + mat2Offset); + T* res = reinterpret_cast(lmem + resOffset); for(int r=0; r < m; ++r) { for(int c=0; c < p; ++c) { @@ -157,55 +61,113 @@ void f_matrix_multiplication(byte* memByte, byte* dataByte) { for(int cr=0; cr < n; ++cr) { resCell += *(mat1 + r * n + cr) * *(mat2 + cr * p + c); } - WriteValue(res + r * p + c, resCell); + *(res + r * p + c) = resCell; } } } +template void matrix_multiplication_wrapper(Address, Address); +template void matrix_multiplication_wrapper(Address, Address); +template void matrix_multiplication_wrapper(Address, Address); +template void matrix_multiplication_wrapper(Address, Address); template -void f_print_mem(byte* memByte, byte* dataByte) { - I32 offset = ReadValueAndAdvance(&dataByte); - I32 size = ReadValueAndAdvance(&dataByte); +void print_memory_wrapper(Address mem, Address data) { + I32* stack = reinterpret_cast(data); + + I32 offset = ReadValueAndAdvance(&stack); + I32 size = ReadValueAndAdvance(&stack); + T* lmem = reinterpret_cast(reinterpret_cast(mem) + offset); for(int i=0; i < size; ++i) { - std::cout << *(reinterpret_cast(memByte + offset + i * sizeof(T))) << " "; + std::cout << ReadValue(lmem + i) << " "; } std::cout << std::endl; } +template void print_memory_wrapper(Address, Address); +template void print_memory_wrapper(Address, Address); +template void print_memory_wrapper(Address, Address); +template void print_memory_wrapper(Address, Address); + +void exp_wrapper(Address mem, Address data) { + F64 x = ReadValueAndAdvance(reinterpret_cast(&data)); + WriteValue(reinterpret_cast(data), base::ieee754::exp(x)); +} -void f_exp(byte* memByte, byte* dataByte) { - F64 x = ReadValueAndAdvance(&dataByte); - WriteValue(reinterpret_cast(dataByte), base::ieee754::exp(x)); +template +void add_wrapper(Address mem, Address data) { + T* stack = reinterpret_cast(data); + T lhs = ReadValueAndAdvance(&stack); + T rhs = ReadValueAndAdvance(&stack); + WriteValue(stack, lhs + rhs); } +template void add_wrapper(Address, Address); -void f_time_ms(byte* memByte, byte* dataByte) { - WriteValue(reinterpret_cast(dataByte), std::chrono::duration_cast( +void time_ms_wrapper(Address mem, Address data) { + WriteValue(reinterpret_cast(data), std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count()); } template -void f_print_stack(byte* memByte, byte* dataByte) { - std::cout << *(reinterpret_cast(dataByte)) << std::endl; +void print_stack_wrapper(Address mem, Address data) { + std::cout << ReadValue(reinterpret_cast(data)) << std::endl; } +template void print_stack_wrapper(Address, Address); +template void print_stack_wrapper(Address, Address); +template void print_stack_wrapper(Address, Address); +template void print_stack_wrapper(Address, Address); /******************************* * External reference functions *******************************/ -bool find_native_function(const char* find_name, FunctionSig* sig, int *index) { -#define FIND_NATIVE_FUNCTION(function, name, type, param, ret) \ +bool find_native_function(const char* find_name, FunctionSig* sig, ExternalReference(**ref)()) { +#define ARGS_TO_VECTOR(...) {__VA_ARGS__} +#define FIND_NATIVE_FUNCTION(function, name, type, p, r) \ if(strcmp(name, find_name) == 0) { \ - *index = k##function##_##type; \ - return g_functions[*index].sig_match(sig);\ + std::vector params = p; \ + std::vector rets = r; \ + *ref = ExternalReference::wasm_##function; \ + if(params.size() != sig->parameter_count() || rets.size() != sig->return_count()) { \ + return false; \ + } \ + for(size_t i=0; i < params.size(); i++) { \ + if(params[i] != sig->GetParam(i)) { \ + return false; \ + } \ + } \ + for(size_t i=0; i < rets.size(); i++) { \ + if(rets[i] != sig->GetReturn(i)) { \ + return false; \ + } \ + } \ + return true; \ } - FOREACH_NATIVE_FUNCTION(FIND_NATIVE_FUNCTION, ___, ___) +FOREACH_NATIVE_FUNCTION_NON_TEMPLATE(FIND_NATIVE_FUNCTION, ARGS_TO_VECTOR, ARGS_TO_VECTOR) #undef FIND_NATIVE_FUNCTION - return false; -} -int native_function_gateway(int funcId, Address mem, Address data) { - DCHECK_GT(funcId, NativeFunction::FIRST); - DCHECK_LT(funcId, NativeFunction::LAST); - (*g_functions[funcId].func)(reinterpret_cast(mem), reinterpret_cast(data)); +#define FIND_NATIVE_FUNCTION(function, name, type, p, r) \ + if(strcmp(name, find_name) == 0) { \ + std::vector params = p; \ + std::vector rets = r; \ + *ref = ExternalReference::wasm_##function##_##type; \ + if(params.size() != sig->parameter_count() || rets.size() != sig->return_count()) { \ + return false; \ + } \ + for(size_t i=0; i < params.size(); i++) { \ + if(params[i] != sig->GetParam(i)) { \ + return false; \ + } \ + } \ + for(size_t i=0; i < rets.size(); i++) { \ + if(rets[i] != sig->GetReturn(i)) { \ + return false; \ + } \ + } \ + return true; \ + } +FOREACH_NATIVE_FUNCTION_TEMPLATE(FIND_NATIVE_FUNCTION, ARGS_TO_VECTOR, ARGS_TO_VECTOR) +#undef FIND_NATIVE_FUNCTION +#undef ARGS_TO_VECTOR + return false; } } // namespace wasm diff --git a/deps/v8/src/wasm/wasm-sable-external-refs.h b/deps/v8/src/wasm/wasm-sable-external-refs.h index 434855eed7bd56..1a61fca0233a47 100644 --- a/deps/v8/src/wasm/wasm-sable-external-refs.h +++ b/deps/v8/src/wasm/wasm-sable-external-refs.h @@ -5,6 +5,7 @@ #ifndef V8_WASM_WASM_SABLE_EXTERNAL_REFS_H_ #define V8_WASM_WASM_SABLE_EXTERNAL_REFS_H_ +#include "src/external-reference.h" #include "src/wasm/value-type.h" #include "src/v8memory.h" @@ -12,13 +13,53 @@ namespace v8 { namespace internal { namespace wasm { +typedef void (*native_t)(Address, Address); + // find native function and set its index -bool find_native_function(const char* find_name, FunctionSig* sig, int *index); +bool find_native_function(const char* find_name, FunctionSig* sig, ExternalReference (**ref)()); + +#ifdef ___ +#error "___ already defined" +#endif +#ifdef I32 +#error "I32 already defined" +#endif +#ifdef I64 +#error "I64 already defined" +#endif +#ifdef F32 +#error "F32 already defined" +#endif +#ifdef F64 +#error "F64 already defined" +#endif + +#define ___ void +#define I32 int32_t +#define I64 int64_t +#define F32 float +#define F64 double + +// all native functions should be declared +// in FOREACH_NATIVE_FUNCTION_[NON_]TEMPLATE +#define FOREACH_NATIVE_FUNCTION_NON_TEMPLATE(V, P, R) \ + V(time_ms, "i64.time_ms", ___, P(), R(kWasmI64)) \ + V(exp, "f64.exp", ___, P(kWasmF64), R(kWasmF64)) \ -// entry point to calling a native function -// this gateway function will call the appropriate -// function based on the given function id -int native_function_gateway(int funcId, Address mem, Address data); +#define FOREACH_NATIVE_FUNCTION_TEMPLATE(V, P, R) \ + V(add, "i32.add", I32, P(kWasmI32, kWasmI32), R(kWasmI32)) \ + V(matrix_multiplication, "i32.mat_mul", I32, P(kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32), R()) \ + V(matrix_multiplication, "i64.mat_mul", I64, P(kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32), R()) \ + V(matrix_multiplication, "f32.mat_mul", F32, P(kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32), R()) \ + V(matrix_multiplication, "f64.mat_mul", F64, P(kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32, kWasmI32), R()) \ + V(print_stack, "i32.print_s", I32, P(kWasmI32), R()) \ + V(print_stack, "i64.print_s", I64, P(kWasmI64), R()) \ + V(print_stack, "f32.print_s", F32, P(kWasmF32), R()) \ + V(print_stack, "f64.print_s", F64, P(kWasmF64), R()) \ + V(print_memory, "i32.print_m", I32, P(kWasmI32, kWasmI32), R()) \ + V(print_memory, "i64.print_m", I64, P(kWasmI32, kWasmI32), R()) \ + V(print_memory, "f32.print_m", F32, P(kWasmI32, kWasmI32), R()) \ + V(print_memory, "f64.print_m", F64, P(kWasmI32, kWasmI32), R()) \ } // namespace wasm } // namespace internal