Skip to content

Naming wasm32 intrinsics #562

Closed
Closed
@alexcrichton

Description

@alexcrichton

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 instructions

  • 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: 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/discovering
Cons: works badly for i32::atomic::wait (groups badly with atomic::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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions