-
Notifications
You must be signed in to change notification settings - Fork 59
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
Expose wasm instrinsics for grow_memory and current_memory instructions #23
Comments
Actually you can access some intrinsics, see for example |
Will that |
@fitzgen nah that's an unstable (permanently) feature, we'd want to look to exposing these intrinsics elsewhere rather than using the example there. That's just what's needed to implement it in libstd today. |
If you want to use it on stable Rust right now and be sure your code won't break in the future you could add an Of course having this actually exposed by Rust as an intrinsic would be a lot better. |
Yeah. Or if we had a working linker, I could define out-of-line functions in WAT, compile them to Neither seems ideal, although linking doesn't seem too terrible. I think we should have proper intrinsics, though. How would we go about adding and stabilizing them? |
I bet that this is far away from stable, instrinsics could get new immediate(s) and I think there is a high chance that the code will break after the transition. (oops, seems im loo late) |
FYI, I'm expecting to introduce new intrinsics in LLVM (and new builtins in clang) with the new names soon (and they'll probably have an operand for the wasm immediate too). |
Thanks for the heads up @sunfishcode! My thinking for how we'd expose this in Rust is probably to add it to the stdsimd crate. That crate's moreso "vendor intrinsics" rather than just SIMD stuff. Currently it's not integrated into libcore but hopefully that'll happen in the somewhat near future! |
The wasm CG is moving forward with the rename, though the decision is not fully final yet. I've tentatively added intrinsics with the proposed names in LLVM, along with immediate operands, here. |
@sunfishcode so right now libstd in Rust isn't great about exposing vendor-specific (platform-specific) intrinsics like SIMD on x86, but that's hopefully changing soon! For things on x86 we've been using Intel's intrinsic guide as a reference point for what the signatures should look like in Rust. In essence we're hoping there's vendor definitions of what we should be doing so there's an obvious path to stabilization for us. With that in mind, is there something similar for wasm? In other words, is there an 'official definition' of sorts for how these intrinsics should be exposed with a C-like signature? If not no worries, we can always tweak it as it's a nightly target anyway :) |
In clang, they now look like this: size_t __builtin_wasm_mem_size(int32_t imm);
size_t __builtin_wasm_mem_grow(int32_t imm, size_t delta); where the There's no official documentation for these yet, but I expect that these are what will eventually be documented. Provided that the CG doesn't reverse course on the rename. |
Ok thanks! We unfortunately don't have a great way of specifying "this argument must be constant" in Rust right now... |
You could use an intrinsic with an attribute on I guess, but really you want const generics. |
@sunfishcode, why do these return
This seems unfortunate. Are we supposed to call this intrinsic in a loop until we have grown memory to its desired dynamic size? What is the motivation for this restriction? |
@fitzgen isn't And yes, you can't shrink memory with I guess, |
Oh, woops I misunderstood the
Why not use |
The
|
Ah, I see, i misunderstood you too : ) I believe we can just check against |
What about the return value?
This will work, but it really seems less elegant than accurately expressing that |
Yeah, that's a good point about the return value. I think it's meant to conceptually be something like |
I guess we are getting into the weeds here. I understand not wanting to cut in half the range of the success values (since they become negative with a signed integer), so maybe the spec should change to use |
You can write |
@alexcrichton are the |
@fitzgen perhaps yeah but that's just an implementation for an eventual stable version of these intrinsics, I don't think we'll ever expose that implementation detail on stable. |
At this time, the WebAssembly CG is still considering the rename, and the new names are not yet final. |
Ok thanks for the update @sunfishcode! In the meantime I've taken the current instruction names and proposed adding them to stdsimd, the current house for platform-specific intrinsics -- rust-lang/stdarch#361 |
While stdsimd seems okay for memory intrinsics, I wonder whether it is still a good place for possible future DOM or GC intrinsics. Because those might not be provided in the non-web use case. |
I'm gonna close this as these will soon (hopefully) be merged into rust-lang/rust under |
I've wanted to use these instructions, but no way to access it, and can't write WAT by hand either because of #22
The text was updated successfully, but these errors were encountered: