WebAssembly / wasm-c-api

Wasm C API prototype
Apache License 2.0
534 stars 77 forks source link

Get rid of wasm_memory_data, use a copying wasm_(read/write)_memory_data instead #156

Closed SoniEx2 closed 3 years ago

SoniEx2 commented 3 years ago

There are 2 ways to do little-endian VMs on big-endian hosts:

  1. Byteswap every load/store instruction.
    • This is very slow.
  2. Adjust load/store addresses such that the VM sees the memory as little-endian, but no byteswaps are required.
    • This is faster, but requires byteswapping at the C API layer.

The former is faster for IO-bound tasks, whereas the latter is faster for CPU-bound tasks. In practice, nobody uses wasm for IO-bound tasks, because wasm was designed for CPU-bound tasks, as a replacement for asm.js. This means approach 2 is better for wasm.

However, approach 2 is a bit mind-bending, and so maybe not everyone wants to deal with it. Thus, leaving the C API undefined for big-endian hosts might be the best approach to take here.

See also https://github.com/WebAssembly/wabt/pull/1557

So it'd be nice if wasm_memory_data wasn't, and instead the caller had to pass in a buffer for the runtime to copy things into.