Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements for SIMD advisor #56

Closed
Tracked by #55
NingW101 opened this issue Dec 26, 2023 · 2 comments · Fixed by #61
Closed
Tracked by #55

Enhancements for SIMD advisor #56

NingW101 opened this issue Dec 26, 2023 · 2 comments · Fixed by #61
Labels
enhancement New feature or request

Comments

@NingW101
Copy link
Contributor

NingW101 commented Dec 26, 2023

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.
@NingW101 NingW101 added the enhancement New feature or request label Dec 26, 2023
@NingW101 NingW101 mentioned this issue Dec 26, 2023
3 tasks
@NingW101
Copy link
Contributor Author

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>)

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.

Maybe we can scan if these SIMD intrinsics header files exist in the codebase, and add corresponding compiler flags when user enable SIMD option from UI.

@NingW101
Copy link
Contributor Author

NingW101 commented Jan 31, 2024

Enhancements finalized:

  1. scan the codebase to check if following header files are included:

    SIMD set Header file Action
    SSE #include <xmmintrin.h> -msse
    SSE2 #include <emmintrin.h> -msse2
    SSE3 #include <pmmintrin.h> -msse3
    SSSE3 #include <tmmintrin.h> -mssse3
    SSE4.1 #include <smmintrin.h> -msse4.1
    SSE4.2 #include <nmmintrin.h> -msse4.2
    AVX #include <immintrin.h> -mavx

    implement action to add corresponding -mxxx flag into the compiler flags.

  2. scan the error content to match if it contains the x86intrin.h, prompt developers that the emscripten does not support this intrinsic header, consider to rewrite the code with the apis provided by wasm_simd128.h or just remove it if the codebase does not use the SIMD code. Tag the link of Using SIMD with emscripten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant