From 98527c456320c882bcb38b082c0539fd99e86fc6 Mon Sep 17 00:00:00 2001 From: Ruben Leal Mirete Date: Fri, 20 Nov 2026 18:45:50 +0100 Subject: [PATCH] build(wasm): SIMD (-msimd128), on by default Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 +++ CMakeLists.txt | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1724a9f..85ff32a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [Unreleased] +### Changed +- **WebAssembly builds use SIMD** (`-msimd128`), on by default: every browser with WebGPU supports it. The option `VECTOR_MATH_WASM_SIMD` turns it off. It applies to the library and is passed on to consumers (compile and link, so wasm-opt accepts the SIMD instructions). + --- ## [0.6.1] - 2026-11-10 diff --git a/CMakeLists.txt b/CMakeLists.txt index fa77ada..3610e39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,15 @@ option(VECTOR_MATH_BUILD_BENCHMARK "Enable building benchmark" OFF) option(VECTOR_MATH_ENABLE_AVX2 "Enable x86/x64 AVX2+FMA code generation for public headers and library targets" OFF) +# WebAssembly SIMD (-msimd128), on by default: every browser with WebGPU has +# it. Compiles this directory with it (the library and the third-party code it +# builds); the target passes it on to its consumers below. +option(VECTOR_MATH_WASM_SIMD "WebAssembly builds: use SIMD (-msimd128)" ON) +if(EMSCRIPTEN AND VECTOR_MATH_WASM_SIMD) + add_compile_options(-msimd128) + add_link_options(-msimd128) +endif() + include_directories(inc) message(STATUS "Building ${PROJECT_NAME}...") @@ -32,6 +41,12 @@ target_include_directories(vector_math PUBLIC $ ) +# Consumers compile and link with SIMD too (the link tells wasm-opt to accept it). +if(EMSCRIPTEN AND VECTOR_MATH_WASM_SIMD) + target_compile_options(vector_math INTERFACE -msimd128) + target_link_options(vector_math INTERFACE -msimd128) +endif() + # Emscripten reports an x86 processor, but WebAssembly has no AVX2/FMA (and # the sources' x86 paths are off there: common.hpp only defines # __VECTOR_MATH_ARCH_X86_X64 for real x86 targets).