Skip to content

Add builtins for LLVM Wasm intrinsics #5507

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

Closed
wants to merge 10 commits into from

Conversation

kubkon
Copy link
Member

@kubkon kubkon commented Jun 2, 2020

This PR proposes adding builtins for LLVM’s Wasm intrinsics llvm.wasm.memory.size and llvm.wasm.memory.grow called @wasmMemorySize and @wasmMemoryGrow respectively. Typical example usage:

var prev = @wasmMemorySize(0);
assert(prev == @wasmMemoryGrow(0, 1);
assert(prev + 1 == @wasmMemorySize(0));

This PR essentially closes #2291, however, it favors the simpler approach of adding target-specific builtins rather than adjusting asm for Wasm. I reckon this is a good enough initial solution until we figure out the design for supporting Wasm in asm. Oh and FWIW, LLVM doesn’t expose any set of instructions for inlining Wasm.

cc @andrewrk what do you think about this approach?

kubkon added 7 commits June 1, 2020 12:44
This will allow the developer to poll the runtime for currently
allocated memory in the number of Wasm pages. Typical usage:

```zig
var wasm_pages = @wasmMemorySize();
@import("std").debug.assert(wasm_pages > 0);
```
This will allow the developer to request additional memory pages
from the runtime to be allocated for the Wasm app. Typical usage:

```zig
var wasm_pages = @wasmMemorySize();
@wasmMemoryGrow(1);
@import("std").debug.assert((wasm_pages + 1) == @wasmMemorySize());
```
@daurnimator daurnimator added the arch-wasm 32-bit and 64-bit WebAssembly label Jun 4, 2020
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @andrewrk what do you think about this approach?

Thanks for your patch and your patience. I agree with your reasoning.

@andrewrk andrewrk closed this in 4302f27 Jun 9, 2020
@kubkon kubkon deleted the wasm-instrinsics branch December 9, 2020 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm 32-bit and 64-bit WebAssembly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@"identifier" syntax accidentally exposes all LLVM intrinsics
3 participants