-
Notifications
You must be signed in to change notification settings - Fork 43
JS API for SIMD: WA.Global<v128>, lane accessors, coercions at calls #502
Comments
I'm no expert on the design of the JS API, but this all sounds reasonable to me 👍 Would the path forward for this be as a small new proposal or do you imagine we could slip it into this SIMD proposal before official standardization? |
Sounds useful to be able to talk about v128 from JS. Does having lane accessors on WA.Global mean that we define new methods on |
Given that JS not being able to talk to V128 values was by design, i.e. we expect that most JS developers won't need to interact with SIMD code, would this change be geared towards making testing infrastructure simpler, or do you see other uses for exposing this to JS? To be clear, I have no objection to the approach proposed if we decide this is the way to go - but trying to make sure that we expect this to be useful for cases other than test code. For the path forward, I would advocate for this to be a part of the proposal because (1) Very low likelihood of breaking anything because. (2) This doesn't introduce any spec changes, and only touches the JS API. I think this is allowed as a part of Phase 4 under cosmetic changes to the proposal. |
@ngzhian, indeed I think the easiest thing solution be new methods on the Global interface, though it could be phrased in terms of attributes. Not intending this as more than a suggestion, but if
and an attribute API might be:
with the additional constraint that these methods/getters/setters all throw if the type is not v128. @dtig, regarding use cases: testing will be simpler, for sure. For real uses, programs using JS glue code in a wasm application may be simpler since that glue code may be able to avoid being tied to the wasm heap (the alternative to putting SIMD values into boxes is to expose the linear heap and pass addresses around). I'm actually not sure how strong these non-testing use cases are and we may need more time to evaluate that. I would expect the accessors to be fairly uncontroversial and something we could slip into the current spec. The more general idea about using WA.Global as a value box with coercion at the call boundary could be something we take through the CG as a separate proposal if we can come up with compelling use cases. Edit: added the following: Right now, JS can create a v128 global but only with the implicit default value (zero). If we add attributes that can be assigned from arrays, we should probably also allow the constructor to take an array for the value, with the same interpretation. |
I'll provide a little bit more background here. The referenced bug is for running the SIMD spec tests in our JS-shell. To do this, we're converting the The major issues are:
There are multiple options for solving these issues. The one we're moving forward with is to add test-only extensions to the JS-API to workaround these issues. The basic idea is to re-use WebAssembly.Global as a lossless container for tagged values. This is the set of extensions we're using:
Anything less than these operations wasn't sufficient for our purposes. If we wanted to move some of these operations into the standard, I'd recommend the following:
The rationale behind WA.Value is to seperate out the 'tagged-value' aspect of WA.Global into it's own concept that isn't tied to WA.Global specific issues, like mutability. The rationale behind WA.invoke is to opt-in to the new coercion behavior, especially w.r.t. results which will always be WA.Value's. Now should this all be done? I don't know if there's a use-case for this besides ours (strict wasm engine testing). If there's not, then this might be more work than it's worth? |
Hm, it doesn't strike me as great API design to conflate the interface for globals with SIMD-specific stuff. If we want to provide SIMD accessors in JS, then let's introduce a WA.SIMD class. |
(Yeah, I know we're done but I figured it was more natural to file the issue here than in relaxed-simd. Looking for feedback.)
Generally JS does not have a representation for v128 so things become a little awkward; JS can't easily talk about v128 values. But JS can talk about WA.Global objects of type v128, and it can talk about the individual lanes in such an object if accessors were provided. There are a couple of things we could do to make life easier for the JS programmer who interacts with wasm SIMD code:
(This is based on some work @eqrion is doing for our testing infrastructure, where we rely on a variant of this system, see https://bugzilla.mozilla.org/show_bug.cgi?id=1703105.)
The text was updated successfully, but these errors were encountered: