mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-24 03:52:58 +00:00
LibWasm: Remove type information from Value
Gets fib(30) from 380ms to 340ms.
This commit is contained in:
parent
a2448308fd
commit
a58704296c
Notes:
github-actions[bot]
2024-08-06 23:11:13 +00:00
Author: https://github.com/dzfrias
Commit: a58704296c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/960
Reviewed-by: https://github.com/alimpfard
12 changed files with 349 additions and 287 deletions
|
@ -193,8 +193,11 @@ JS::ThrowCompletionOr<NonnullOwnPtr<Wasm::ModuleInstance>> instantiate_module(JS
|
|||
Wasm::HostFunction host_function {
|
||||
[&](auto&, auto& arguments) -> Wasm::Result {
|
||||
JS::MarkedVector<JS::Value> argument_values { vm.heap() };
|
||||
for (auto& entry : arguments)
|
||||
argument_values.append(to_js_value(vm, entry));
|
||||
size_t index = 0;
|
||||
for (auto& entry : arguments) {
|
||||
argument_values.append(to_js_value(vm, entry, type.parameters()[index]));
|
||||
++index;
|
||||
}
|
||||
|
||||
auto result = TRY(JS::call(vm, function, JS::js_undefined(), argument_values.span()));
|
||||
if (type.results().is_empty())
|
||||
|
@ -378,11 +381,13 @@ JS::NativeFunction* create_native_function(JS::VM& vm, Wasm::FunctionAddress add
|
|||
return JS::js_undefined();
|
||||
|
||||
if (result.values().size() == 1)
|
||||
return to_js_value(vm, result.values().first());
|
||||
return to_js_value(vm, result.values().first(), type.results().first());
|
||||
|
||||
return JS::Value(JS::Array::create_from<Wasm::Value>(realm, result.values(), [&](Wasm::Value value) {
|
||||
return to_js_value(vm, value);
|
||||
}));
|
||||
VERIFY_NOT_REACHED();
|
||||
// TODO
|
||||
/*return JS::Value(JS::Array::create_from<Wasm::Value>(realm, result.values(), [&](Wasm::Value value) {*/
|
||||
/* return to_js_value(vm, value);*/
|
||||
/*}));*/
|
||||
});
|
||||
|
||||
cache.add_function_instance(address, function);
|
||||
|
@ -417,7 +422,7 @@ JS::ThrowCompletionOr<Wasm::Value> to_webassembly_value(JS::VM& vm, JS::Value va
|
|||
}
|
||||
case Wasm::ValueType::FunctionReference: {
|
||||
if (value.is_null())
|
||||
return Wasm::Value { Wasm::ValueType(Wasm::ValueType::FunctionReference), 0ull };
|
||||
return Wasm::Value();
|
||||
|
||||
if (value.is_function()) {
|
||||
auto& function = value.as_function();
|
||||
|
@ -439,20 +444,20 @@ JS::ThrowCompletionOr<Wasm::Value> to_webassembly_value(JS::VM& vm, JS::Value va
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
JS::Value to_js_value(JS::VM& vm, Wasm::Value& wasm_value)
|
||||
JS::Value to_js_value(JS::VM& vm, Wasm::Value& wasm_value, Wasm::ValueType type)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
switch (wasm_value.type().kind()) {
|
||||
switch (type.kind()) {
|
||||
case Wasm::ValueType::I64:
|
||||
return realm.heap().allocate<JS::BigInt>(realm, ::Crypto::SignedBigInteger { wasm_value.to<i64>().value() });
|
||||
return realm.heap().allocate<JS::BigInt>(realm, ::Crypto::SignedBigInteger { wasm_value.to<i64>() });
|
||||
case Wasm::ValueType::I32:
|
||||
return JS::Value(wasm_value.to<i32>().value());
|
||||
return JS::Value(wasm_value.to<i32>());
|
||||
case Wasm::ValueType::F64:
|
||||
return JS::Value(wasm_value.to<double>().value());
|
||||
return JS::Value(wasm_value.to<double>());
|
||||
case Wasm::ValueType::F32:
|
||||
return JS::Value(static_cast<double>(wasm_value.to<float>().value()));
|
||||
return JS::Value(static_cast<double>(wasm_value.to<float>()));
|
||||
case Wasm::ValueType::FunctionReference: {
|
||||
auto ref_ = *wasm_value.to<Wasm::Reference>();
|
||||
auto ref_ = wasm_value.to<Wasm::Reference>();
|
||||
if (ref_.ref().has<Wasm::Reference::Null>())
|
||||
return JS::js_null();
|
||||
auto address = ref_.ref().get<Wasm::Reference::Func>().address;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue