-
Notifications
You must be signed in to change notification settings - Fork 271
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
Naming wasm32 intrinsics #562
Comments
Work on defining the intrinsics in Clang is ongoing. I'll check in on its status and try to get what progress we have so far posted somewhere ASAP. In the meantime, I would recommend not getting too fancy with name translations. There are a few edge cases in the naming conventions that may be awkward under some naming schemes. For example, consider v8x16.shuffle, which is the only instruction with the "v8x16" prefix. For discoverability, I recommend grouping instructions by operation rather than by type at the highest level, but I don't have strong opinions on what it should look like beyond that. |
There are also the
I would prefer this as well, e.g., Using underscores, I see two schemas: In any case, independently of what we do here, somebody can write a crate that provides different syntax to call these in stable Rust once these are stabilized, so as long as the naming scheme is consistent I'd be fine with it. |
@tlively oh good to know! This may also be a better issue for the tool-conventions repo as I suspect we all want to agree on what to name these intrinsics! |
FYI The current plan for Clang builtins can be found here: A lot of functionality including almost all arithmetic is already built in to Clang in a target-independent manner, so we won't have separate builtin functions for that. Other things like shuffles are also already covered by target-independent builtins. There are also a couple strange edge cases when it comes to typing. For example, |
Ah it looks like that's not a public document (I can't access it myself at least) |
Sorry about that! This one should work: |
Ah that does indeed work, thanks! We've been experimenting with sealed traits on powerpc for intrinsics and those may be applicable here too! We strive to model everything at compile time to ensure we don't get LLVM errors or codegen errors, so it may be the case that these intrinsics end up looking slightly different in Rust than they do in C |
So what @tlively shows for clang is pretty much what I expected these to look like in clang too. Here, we could do something similar, but we don't have to. Also, it would be interesting to figure out what GCC does here (is it the same as clang?).
I just expected bitselect to work on |
I've been picking this up again today to see how far we can get with it using an updated LLVM, and it reminded me that I should mention @tlively using |
@alexcrichton that makes sense. Even in C, I think most end users are going to use some header file with a less verbose interface rather than the raw |
Sounds like a great idea to me! I wasn't sure if a dedicated header was planned, but that matches intrinsics on x86 exactly I believe (or at least close enough) |
I've made a formal proposal now to stabilize memory-related intrinsics, which would also establish an underscore convention for naming here |
Decided to use underscores now! |
Right now for the wasm32-unknown-unknown target the naming of intrinsics is a bit up in the air. We don't have a document like Intel's providing a specification of all the intrinsics, nor do we really have intrinsic function signature at all! What we've been doing so far is taking instructions that aren't natively supported by LLVM (like growing memory but not an atomic cmpxchg) and making a Rust function with inputs/outputs that look the same as the instruction itself (or similar at least).
This then begs the question, though, how do we actually name these functions? Again, unlike Intel, we don't have a specification from wasm itself about what to name these functions. Also, unlike x86_64, we don't have much prior art in Clang (I think they're still using
__builtin_wasm32_$name
?). To that end, we have a few options of how to name these intrinsics:Replace
.
with_
in the instructionsmemory.size
=>memory_size
memory.grow
=>memory_grow
atomic.wake
=>atomic_wake
i32.atomic.wait
=>i32_atomic_wait
i8x16.extract_lane_s
=>i8x16_extract_lane_s
Pros: easy to remember, clear translation from the spec, clear how to handle future instructions
Cons: can't group intrinsics together, maybe more difficult to discover
Replace
.
with::
in all instructions(and use internal modules for a hierarchy
memory.size
=>memory::size
memory.grow
=>memory::grow
atomic.wake
=>atomic::wake
i32.atomic.wait
=>i32::atomic::wait
i8x16.extract_lane_s
=>i8x16::extract_lane_s
Pros: works well for
atomic::wake
and one-.
intrinsics, can group everything nicely for docs/discoveringCons: works badly for
i32::atomic::wait
(groups badly withatomic::wake
), lots of odules for some (i32::atomic::wait
)Group in modules semi-arbitrarily
memory.size
=>memory::size
memory.grow
=>memory::grow
atomic.wake
=>atomic::wake
i32.atomic.wait
=>atomic::i32_wait
i8x16.extract_lane_s
=>i8x16::extract_lane_s
Pros: definitely good for grouping, documenting, and discovery
Cons: unclear if it will work well for all future instructions, we're making up names in a few cases
That's at least what I can think of now, I'm curious to hear what others think!
The text was updated successfully, but these errors were encountered: