SIMD: should they be returned from / passed to FFI?


#1

Hi everyone,

In exploratory work for SIMD support in Odin, we were wondering if FFI should accept SIMD arguments and return SIMD values.

Returning SIMD values from FFI is quite easy: it will only mean that we need to take an interpreter representation of a SIMD value and spill components into a register.

Passing SIMD value arguments to FFI is more tricky: we need to re-materialize interpreter’s SIMD values, and that means re-constructing objects, which involves garbage collection and has a cost for each SIMD argument.

For Float32, we finally decided to avoid having Float FFI arguments and return values, to keep things simpler. Any opinions about that?


Request For Comments: SIMD.js in asm.js
#2

I could go either way. On the one hand, having SIMD types be <: extern is sortof a performance footgun since it entails a GC allocation when the whole point of SIMD is to stay in registers. If you need to pass out a SIMD vector, you’d be better off passing the components by hand. On the other hand, this could be optimized in the future (with significant work on both the Odin/Ion side). However, asm.js is all about standardizing the “fast path” so maybe we should wait until there is a use case.