Skip to content

Enhancements for SIMD advisor #56

Description

@NingW101

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions