Commit 44efb500c9 for aom
commit 44efb500c9e742871bc42f6bfb93892bd8ca68c1
Author: Steven Robertson <strobe@google.com>
Date: Mon Oct 19 23:04:28 2026 +0000
Add wasm32 target with a SIMD128 RTCD flavor
Emscripten builds now detect AOM_TARGET_CPU=wasm32 and, unless
-DENABLE_SIMD128=0, enable HAVE_SIMD128 (-msimd128). WebAssembly has no
run-time CPU detection, so dispatch is resolved at compile time.
No kernels yet; this only adds the build and rtcd.pl plumbing,
following the RVV precedent.
Change-Id: Ie798d215d125879df0552d0e204aa196a6b2d24f
diff --git a/CMakeLists.txt b/CMakeLists.txt
index aa17f68a90..84dfab3086 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,13 +30,11 @@ if(POLICY CMP0118)
cmake_policy(SET CMP0118 NEW)
endif()
-if(NOT EMSCRIPTEN)
- if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
- set(CMAKE_BUILD_TYPE
- "Release"
- CACHE STRING "Build type: Debug, Release, RelWithDebInfo or MinSizeRel"
- FORCE)
- endif()
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+ set(CMAKE_BUILD_TYPE
+ "Release"
+ CACHE STRING "Build type: Debug, Release, RelWithDebInfo or MinSizeRel"
+ FORCE)
endif()
if(MSVC AND MSVC_VERSION LESS 1920)
diff --git a/cmake/aom_config_defaults.cmake b/cmake/aom_config_defaults.cmake
index d029c73572..8bb02590fe 100644
--- a/cmake/aom_config_defaults.cmake
+++ b/cmake/aom_config_defaults.cmake
@@ -34,6 +34,7 @@ set_aom_detect_var(AOM_ARCH_PPC 0 "Enables PPC architecture.")
set_aom_detect_var(AOM_ARCH_X86 0 "Enables X86 architecture.")
set_aom_detect_var(AOM_ARCH_X86_64 0 "Enables X86_64 architecture.")
set_aom_detect_var(AOM_ARCH_RISCV 0 "Enables RISC-V architecture.")
+set_aom_detect_var(AOM_ARCH_WASM 0 "Enables WebAssembly architecture.")
# Arm/AArch64 feature flags.
set_aom_detect_var(HAVE_NEON 0 "Enables Neon intrinsics optimizations.")
@@ -63,6 +64,9 @@ set_aom_detect_var(HAVE_AVX512 0 "Enables AVX512 optimizations.")
# RISC-V64 feature flags.
set_aom_detect_var(HAVE_RVV 0 "Enables RVV optimizations.")
+# WebAssembly feature flags.
+set_aom_detect_var(HAVE_SIMD128 0 "Enables WebAssembly SIMD128 optimizations.")
+
# Flags describing the build environment.
set_aom_detect_var(HAVE_FEXCEPT 0
"Internal flag, GNU fenv.h present for target.")
@@ -263,3 +267,7 @@ set_aom_option_var(ENABLE_AVX512
# RVV intrinsics flags.
set_aom_option_var(ENABLE_RVV "Enables RVV optimizations on RISC-V targets." ON)
+
+# WebAssembly SIMD128 intrinsics flags.
+set_aom_option_var(ENABLE_SIMD128
+ "Enables SIMD128 optimizations on wasm32 targets." ON)
diff --git a/cmake/aom_configure.cmake b/cmake/aom_configure.cmake
index 57417efaff..1367034b3d 100644
--- a/cmake/aom_configure.cmake
+++ b/cmake/aom_configure.cmake
@@ -56,7 +56,11 @@ string(STRIP "${AOM_CMAKE_CONFIG}" AOM_CMAKE_CONFIG)
# Detect target CPU.
if(NOT AOM_TARGET_CPU)
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" cpu_lowercase)
- if(cpu_lowercase STREQUAL "amd64" OR cpu_lowercase STREQUAL "x86_64")
+ if(EMSCRIPTEN)
+ # Emscripten's toolchain reports a host-like processor; the target is always
+ # wasm32.
+ set(AOM_TARGET_CPU "wasm32")
+ elseif(cpu_lowercase STREQUAL "amd64" OR cpu_lowercase STREQUAL "x86_64")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(AOM_TARGET_CPU "x86")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
diff --git a/cmake/cpu.cmake b/cmake/cpu.cmake
index daa597689a..314e04582c 100644
--- a/cmake/cpu.cmake
+++ b/cmake/cpu.cmake
@@ -130,6 +130,18 @@ elseif("${AOM_TARGET_CPU}" MATCHES "^x86")
set(AOM_RTCD_FLAGS ${AOM_RTCD_FLAGS} --disable-${flavor})
endif()
endforeach()
+elseif("${AOM_TARGET_CPU}" STREQUAL "wasm32")
+ set(AOM_ARCH_WASM 1)
+
+ # WebAssembly has no run-time CPU detection: SIMD128 is a compile-time
+ # property of the module, so dispatch is resolved statically.
+ if(ENABLE_SIMD128)
+ set(HAVE_SIMD128 1)
+ set(AOM_SIMD128_FLAG "-msimd128")
+ else()
+ set(HAVE_SIMD128 0)
+ set(AOM_RTCD_FLAGS ${AOM_RTCD_FLAGS} --disable-simd128)
+ endif()
elseif("${AOM_TARGET_CPU}" MATCHES "riscv")
set(AOM_ARCH_RISCV64 1)
diff --git a/cmake/rtcd.pl b/cmake/rtcd.pl
index 10f65971bf..c2319588c6 100755
--- a/cmake/rtcd.pl
+++ b/cmake/rtcd.pl
@@ -398,6 +398,39 @@ EOF
common_bottom;
}
+sub wasm() {
+ determine_indirection("c", @ALL_ARCHS);
+
+ # Assign the helper variable for each enabled extension
+ foreach my $opt (@ALL_ARCHS) {
+ my $opt_uc = uc $opt;
+ eval "\$have_${opt}=\"flags & HAS_${opt_uc}\"";
+ }
+
+ common_top;
+ print <<EOF;
+#include "config/aom_config.h"
+
+#ifdef RTCD_C
+#define HAS_SIMD128 0x01
+static void setup_rtcd_internal(void)
+{
+ // SIMD128 support is fixed when the module is compiled.
+ int flags = HAVE_SIMD128 ? HAS_SIMD128 : 0;
+
+ (void)flags;
+
+EOF
+
+ set_function_pointers("c", @ALL_ARCHS);
+
+ print <<EOF;
+}
+#endif
+EOF
+ common_bottom;
+}
+
sub unoptimized() {
determine_indirection "c";
common_top;
@@ -424,6 +457,7 @@ my @PRIORITY_ARCH = qw/
mmx sse sse2 sse3 ssse3 sse4_1 sse4_2 avx avx2
arm_crc32 neon neon_dotprod neon_i8mm sve sve2
rvv
+ simd128
vsx
dspr2 msa
/;
@@ -465,6 +499,15 @@ if ($opts{arch} eq 'x86') {
} elsif ($opts{arch} eq 'riscv') {
@ALL_ARCHS = filter(qw/rvv/);
riscv;
+} elsif ($opts{arch} eq 'wasm32') {
+ @ALL_ARCHS = filter(qw/simd128/);
+ # SIMD128 is a compile-time property of a Wasm module, so when enabled it is
+ # always available: resolve dispatch statically, as for neon on arm64.
+ if (keys %required == 0) {
+ @REQUIRES = filter(qw/simd128/);
+ &require(@REQUIRES);
+ }
+ wasm;
} else {
unoptimized;
}
diff --git a/test/test.cmake b/test/test.cmake
index dc72cbea29..16622260ae 100644
--- a/test/test.cmake
+++ b/test/test.cmake
@@ -491,6 +491,19 @@ function(setup_aom_test_targets)
set_property(TARGET test_libaom PROPERTY FOLDER ${AOM_IDE_TEST_FOLDER})
list(APPEND AOM_APP_TARGETS test_libaom)
+ if(EMSCRIPTEN)
+ # Some tests need more than Emscripten's default stack (64 KiB since 3.1.27)
+ # and a fixed-size heap. TOTAL_STACK was renamed to STACK_SIZE in 3.1.27;
+ # the old name was kept for compatibility, but prefer the new one in case it
+ # is removed in the future.
+ if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "3.1.27")
+ append_link_flag_to_target("test_libaom" "-sSTACK_SIZE=5MB")
+ else()
+ append_link_flag_to_target("test_libaom" "-sTOTAL_STACK=5MB")
+ endif()
+ append_link_flag_to_target("test_libaom" "-sALLOW_MEMORY_GROWTH=1")
+ endif()
+
if(CONFIG_AV1_DECODER)
target_sources(test_libaom PRIVATE $<TARGET_OBJECTS:aom_decoder_app_util>
$<TARGET_OBJECTS:test_aom_decoder>)