-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add a test case for using host functions #320
Conversation
{ | ||
auto engine = engine_create_fn(); | ||
ASSERT_TRUE(engine->parse(wasm)); | ||
ASSERT_TRUE(engine->instantiate(wasm)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this will help in the case were we have only single host function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this PR it would not make any difference, however if the interface would be flexible, we could add more functions in fizzy-bench or have external tools use it, such as ewasm-bench, with a multitude of functions.
@@ -35,6 +36,17 @@ std::unique_ptr<WasmEngine> create_wabt_engine() | |||
bool WabtEngine::parse(bytes_view input) const | |||
{ | |||
wabt::interp::Environment env; | |||
|
|||
wabt::interp::HostModule* hostModule = env.AppendHostModule("env"); | |||
assert(hostModule != nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should return false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine as it is. Would fail on memory allocation only.
Will also add a micro-benchmark which calls |
3cce710
to
7746d7f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see two problem:
- Big maintenance burden. Is it number of host function times number of engines?
- This predates "call" rework/optimization so it will be another part of code to update.
Only plan to have this single host function for unit testing and benchmarking. |
a0632b6
to
d5b916a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only plan to have this single host function for unit testing and benchmarking.
Then it is fine.
7637f21
to
182e4ed
Compare
945103e
to
a9f790a
Compare
832d58d
to
13af1cb
Compare
test/utils/wasm3_engine.cpp
Outdated
const void* env_adler32(IM3Runtime /*runtime*/, uint64_t* stack, void* mem) | ||
{ | ||
uint64_t* ret = stack; | ||
uint32_t offset = *(uint32_t*)stack++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint32_t offset = *(uint32_t*)stack++; | |
const auto offset = *static_cast<uint32_t*>(stack++); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do, it was copy paste from wasm3 :)
assert(hostModule != nullptr); | ||
|
||
hostModule->AppendFuncExport("adler32", {{wabt::Type::I32, wabt::Type::I32}, {wabt::Type::I32}}, | ||
[=](const wabt::interp::HostFunc*, const wabt::interp::FuncSignature*, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite big for a lambda, can you make the code inside a separate private method?
Also why not use the same function in parse
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parse doesn't need it, it only wants the signature.
I had a different version using a unique_ptr
but something wasn't working. The problem is GetMemory
will only return correctly after instantiation, so it can't be captured prior. Also wabt has no context argument, so we'll need a lambda in any case, but could extract out into a helper.
I would prefer however not to do any of that here, but someone else could optimize these in subsequent PRs.
test/utils/wasm3_engine.cpp
Outdated
const void* env_adler32(IM3Runtime /*runtime*/, uint64_t* stack, void* mem) | ||
{ | ||
uint64_t* ret = stack; | ||
uint32_t offset = *(uint32_t*)stack++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ((uint32_t*)stack)++
or (uint32_t*)(stack++)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the intention is *(uint32_t*)(stack++)
. It is a copy paste from wasm3.
e90cf0e
to
a0f952b
Compare
test/utils/fizzy_engine.cpp
Outdated
fizzy::execution_result env_adler32(fizzy::Instance& instance, std::vector<uint64_t> args, int) | ||
{ | ||
assert(instance.memory != nullptr); | ||
// Since memory is a bytes_view, substr produces another bytes_view and no copy is performed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment is kinda outdated now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
assert(m_env.GetMemoryCount() > 0); | ||
auto memory = m_env.GetMemory(0); | ||
assert(memory != nullptr); | ||
auto memory_data = memory->data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the type of memory_data
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's vector<char>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some wabt memory type. Apparently std::vector<char> data
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With single outdated comment to be fixed.
{ | ||
auto engine = engine_create_fn(); | ||
ASSERT_TRUE(engine->parse(wasm)); | ||
ASSERT_TRUE(engine->instantiate(wasm)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this will help in the case were we have only single host function.
test/utils/fizzy_engine.cpp
Outdated
fizzy::execution_result env_adler32(fizzy::Instance& instance, std::vector<uint64_t> args, int) | ||
{ | ||
assert(instance.memory != nullptr); | ||
// Since memory is a bytes_view, substr produces another bytes_view and no copy is performed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Depends on #318.