Exploring SIMD performance improvements in WebAssembly (2021)
1–10 of 25 posts
Re: Exploring SIMD performance improvements in WebAssembly (2021)
#2Re: Exploring SIMD performance improvements in WebAssembly (2021)
#3It looks promising! But fixed-width lanes don't seem too cross-platform? I don't just mean the v256 and v512 types that may become ubiquitous in a few years, but also things like optimizing for different L1 cache sizes, doing some operation macro-fusion on the SIMD unit, or directly supporting leading/trailing elements to reduce code size?
But it seems that WebAssembly doesn't have length-agnostic SIMD instructions yet. There is an open proposal to add this though: https://github.com/WebAssembly/flexible-vectors
Re: Exploring SIMD performance improvements in WebAssembly (2021)
#4It looks promising! But fixed-width lanes don't seem too cross-platform? I don't just mean the v256 and v512 types that may become ubiquitous in a few years, but also things like optimizing for different L1 cache sizes, doing some operation macro-fusion on the SIMD unit, or directly supporting leading/trailing elements to reduce code size?
Re: Exploring SIMD performance improvements in WebAssembly (2021)
#5Re: Exploring SIMD performance improvements in WebAssembly (2021)
#6It looks promising! But fixed-width lanes don't seem too cross-platform? I don't just mean the v256 and v512 types that may become ubiquitous in a few years, but also things like optimizing for different L1 cache sizes, doing some operation macro-fusion on the SIMD unit, or directly supporting leading/trailing elements to reduce code size?
In practice it's not possible to optimize "generally" for all possible target architectures your wasm will run on. You're going to optimize for x86-64 or ARM, and probably going to specifically optimize for modern intel, modern amd, or apple's m1. If you try to optimize for everything you're going to run into really painful tradeoffs and probably have mediocre performance on a bunch of architectures after a lot of ha…
Re: Exploring SIMD performance improvements in WebAssembly (2021)
#7Re: Exploring SIMD performance improvements in WebAssembly (2021)
#8 #define ITERATIONS 1000
int main()
{
const size_t BUFFER_SIZE = 64ul \* 1024 \* 1024;
__m128i\* data_buffer = (__m128i *)memalign(64, BUFFER_SIZE);
const __m128i all_ones = _mm_set1_epi8(0xFF);
for (size_t i = 0; i
I had to fixup the WAT because set_local and get_local don't exist anymore. They are called local.get and local.set now.At higher number of iterations the C version converges on about 1.7 seconds per 1000, while the WASM version seems to remain the same at 4.2 secs per 1000. This leaves native 2.5x faster for this particular operation, on my machine.
Re: Exploring SIMD performance improvements in WebAssembly (2021)
#9I wonder if the 4x performance boost of 128-bit SIMD over 32-bit would drop to 2x if WebAssembly added 64-bit registers/instructions.
Re: Exploring SIMD performance improvements in WebAssembly (2021)
#10Earlier quoted context omitted.
In practice it's not possible to optimize "generally" for all possible target architectures your wasm will run on. You're going to optimize for x86-64 or ARM, and probably going to specifically optimize for modern intel, modern amd, or apple's m1. If you try to optimize for everything you're going to run into really painful tradeoffs and probably have mediocre performance on a bunch of architectures after a lot of ha…
Why not? Fixed-size SIMD architectures use mostly the same operations, so if you target SSE2 initially, the code should run just fine on NEON. A runtime that ships a JIT compiler also has the unique opportunity to further optimize SIMD code by using more lanes or limiting the working set to the host platform's L1 cache size. Even the AOT compilers like GCC or clang emulate platform-specific intrinsics using generic v…