A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

Abbreviated SIMD variable initializers


Currently, the SIMD.js validation in asm.js requires local variables with SIMD type be declared like this:

var x = SIMD_float32x4(0, 0, 0, 0);

It’s recently been observed that in the non-asm.js SIMD.js API, passing fewer arguments to the SIMD constuctors causes them to use zero values by default, so one can produce an all-zeros vector like this:

var x = SIMD_float32x4();

Since it’s pretty common to initialize variables to zero values in asm.js programs, it’d be neat if asm.js would accept this abbreviated form. Thoughts?


+0.0 or -0.0? Or maybe uninitialized should be NaN. Which NaN though?


And it turns out that I was mistaken. SIMD.float32x4() returns a vector of all NaNs, not all zeros. And for the record, SIMD.js does not canonicalize NaNs in SIMD values, so the payloads of the NaNs are unspecified, as they are everywhere else.

Also, Alon reminded me that asm.js supports a better way to abbreviate variable initializers, which Emscripten isn’t making use of yet:

   "use asm"
   var SIMD_float32x4 = global.SIMD.float32x4;
   const zeros = SIMD_float32x4(0, 0, 0, 0)
   function f() {
       var x = zeros;

this looks nicer than using the zero-argument constructor form that I proposed above, and it’s already in asm.js today, so there’s no need to add anything here.