WebAssembly / flexible-vectors

Vector operations for WebAssembly
https://webassembly.github.io/flexible-vectors/
Other
48 stars 6 forks source link

Why lanes? #53

Closed pannous closed 2 years ago

pannous commented 2 years ago

Why is the lanes approach preferable to direct vector operations like a hypothetical

i32.vector_add ( source_address_x::i32 , source_address_y::i32, target_address::i32, vector_length::i32 )
penzn commented 2 years ago

i32.vector_add ( source_address_x::i32 , source_address_y::i32, target_address::i32, vector_length::i32 )

It is hard to optimize when multiple operations like this follow each other. For example, if there is a mul followed by an add it would be hard to combine them into a larger operation that does both in one go (think about how you would write a dot product uing SIMD intrinsics). Also pointer arguments make reasoning about dependencies difficult. Current approach uses 'vector values' which can be stored in SIMD registers, allowing for writing vector loops at a lower level (note that this is still targeting CPUs).

What a couple of well-known managed runtimes do is define operations on garbage collected vector objects. That can still leave some performance behind, but is easier to optimize than operations taking raw pointers. This might be hard to do from languages such as C.

pannous commented 2 years ago

got it, thanks