Casts in current SIMD implementation

49 views
Skip to first unread message

Soeren Balko

unread,
Apr 9, 2014, 12:56:28 AM4/9/14
to emscripte...@googlegroups.com

I reviewed the current SIMD implementation (as given by vector.h and in library.js). Unfortunately, the documentation on Javascript's implementation of SIMD is somewhat sparse, so I am using the documentation given in the polyfill implementation (https://github.com/johnmccutchan/ecmascript_simd/blob/master/src/ecmascript_simd.js) as a reference.

Some of the implementations in library.js do a lot of copying/casting, e.g.

emscripten_float32x4_and__inline: function(a, b) {
    return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.and(SIMD.float32x4.bitsToInt32x4(' + a + '), SIMD.float32x4.bitsToInt32x4(' + b + ')))';
},

Given the fact that float32x4 and int32x4 objects are immutable, this has noticable performance penalties. Also, looking at the polyfill implementation of SIMD.float32x4.and(...), I don't think I understand the rationale behind these copies:

/**
  * @param {float32x4} a An instance of float32x4.
  * @param {float32x4} b An instance of float32x4.
  * @return {float32x4} New instance of float32x4 with values of a & b.
  */
SIMD.float32x4.and = function(a, b) {
  var aInt = SIMD.float32x4.bitsToInt32x4(a);
  var bInt = SIMD.float32x4.bitsToInt32x4(b);
  return SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.and(aInt, bInt));
}

In other cases, the emscripten function signature is different from the Javascript SIMD implementation. Like in case of 

emscripten_float32x4_lessThan__inline: function(a, b) {
   return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.lessThan(' + a + ', ' + b + '))';
},

which returns an float32x4 object, whereas the polyfill implementation returns an int32x4:

/**
  * @param {float32x4} t An instance of float32x4.
  * @param {float32x4} other An instance of float32x4.
  * @return {int32x4} 0xFFFFFFFF or 0x0 in each lane depending on
  * the result of t < other.
  */
SIMD.float32x4.lessThan = function(t, other) {
  var cx = t.x < other.x;
  var cy = t.y < other.y;
  var cz = t.z < other.z;
  var cw = t.w < other.w;
  return SIMD.int32x4.bool(cx, cy, cz, cw);
} 

Can someone educate me why that is, please?

Soeren

Alon Zakai

unread,
Apr 9, 2014, 7:50:38 PM4/9/14
to emscripte...@googlegroups.com
Frankly, JS SIMD is still being specced out, so the emscripten polyfill might lag behind the spec, and might well be suboptimal as not much effort has gone into optimizations yet. Currently implementations of the spec are expected to land in firefox and chrome, after that happens I think it will make more sense to spend time on emscripten's SIMD support.

- Alon



--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Soeren Balko

unread,
Apr 10, 2014, 8:17:08 AM4/10/14
to emscripte...@googlegroups.com
I saw the SIMD object existing in Firefox Nightly. I can quickly check if it conforms with the polyfill implementation. Also, I haven’t been able to locate a formal draft of some spec - the documentation of the polyfill implementation is my only reference...

On a different note: the SIMD.int32x4 and SIMD.float32x4 objects aren't asm.js compliant, or are they?

Soeren
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

Alon Zakai

unread,
Apr 10, 2014, 2:29:55 PM4/10/14
to emscripte...@googlegroups.com
Yes, this is not in the asm.js spec yet. I think that might be added soon, but it depends on the SIMD spec being stable.

- Alon



To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages