According to the emscripten documentation, there are five different ways to leverage WebAssembly SIMD in your C/C++ programs:
- Enable LLVM/Clang SIMD autovectorizer to automatically target WebAssembly SIMD, without requiring changes to C/C++ source code.
- Write SIMD code using the GCC/Clang SIMD Vector Extensions (
__attribute__((vector_size(16))))
- Write SIMD code using the WebAssembly SIMD intrinsics (
#include <wasm_simd128.h>)
- Compile existing SIMD code that uses the x86 SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2 or 128-bit subset of the AVX intrinsics (
#include <*mmintrin.h>)
- Compile existing SIMD code that uses the ARM NEON intrinsics (
#include <arm_neon.h>)
x86intrin.h header file is usually used in C\C++ codebase, which contains the support of multiple instruction sets, commonly covering the one or several of MMX, SEE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, etc, but it is related to the what compiler you use. For the clang inside of the emsdk, it contains ia32intrin.h & mmintrin.h, which will not handled by emscripten during the building, so the better ways to port your project with SIMD support are:
- if there is no SIMD code used in the codebase and you want to enable SIMD option to let compiler autovector to target wasm-simd, add
-msimd128 is enough.
- if your current codebase exists SIMD code,
include <wasm_simd128.h> and then use the wasm SIMD intrinsics to replace your current code.
- if your current codebase include SIMD code targeting x86 SSE* instruction sets, add
-msimd128 and additionally corresponding flag.
- For example,
SSE: pass -msse and #include <xmmintrin.h>. Use #ifdef __SSE__ to gate code.
According to the emscripten documentation, there are five different ways to leverage WebAssembly SIMD in your C/C++ programs:
__attribute__((vector_size(16))))#include <wasm_simd128.h>)#include <*mmintrin.h>)#include <arm_neon.h>)x86intrin.hheader file is usually used in C\C++ codebase, which contains the support of multiple instruction sets, commonly covering the one or several of MMX, SEE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, etc, but it is related to the what compiler you use. For theclanginside of theemsdk, it containsia32intrin.h&mmintrin.h, which will not handled by emscripten during the building, so the better ways to port your project with SIMD support are:-msimd128is enough.include <wasm_simd128.h>and then use thewasm SIMD intrinsicsto replace your current code.-msimd128and additionally corresponding flag.SSE: pass-msseand#include <xmmintrin.h>. Use#ifdef __SSE__to gate code.