From 20d508bf9597c73a063eec535bcb2fd5cabc7837 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 18 Aug 2023 12:50:30 -0700 Subject: [PATCH] [release/8.0-rc1] [wasm] Do not build mono libs with `-msimd128` (#90750) * [wasm] Do not build mono libs with `-msimd128` Make it optional, build only minimal set of code witch required `-msimd128` to separate library. Also provide "stub" nosimd version of this library. Choose the appropriate library during linking. * Fix build * Fix build of non-wasm platforms * Add simd options for wasi * Fix wasi build --------- Co-authored-by: Radek Doulik Co-authored-by: Larry Ewing --- .../Microsoft.NETCore.App/Directory.Build.props | 2 ++ src/mono/CMakeLists.txt | 8 ------ src/mono/mono.proj | 6 +++++ src/mono/mono/mini/CMakeLists.txt | 25 +++++++++++++++-- src/mono/mono/mini/interp/interp-nosimd.c | 31 ++++++++++++++++++++++ src/mono/mono/mini/interp/interp-simd.c | 2 ++ src/mono/mono/mini/interp/interp-simd.h | 2 ++ src/mono/mono/mini/interp/transform-simd.c | 4 +++ src/mono/wasi/build/WasiApp.Native.targets | 6 +++++ src/mono/wasi/runtime/CMakeLists.txt | 1 + src/mono/wasi/wasi.proj | 2 ++ src/mono/wasm/build/WasmApp.Native.targets | 6 +++++ src/mono/wasm/runtime/CMakeLists.txt | 1 + src/mono/wasm/wasm.proj | 3 ++- 14 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 src/mono/mono/mini/interp/interp-nosimd.c diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 13cf1fc..5a96f57 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -197,6 +197,8 @@ + + diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 66e92d8..a57cc52 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -242,14 +242,6 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "emscripten") add_compile_options(-Wno-strict-prototypes) add_compile_options(-Wno-unused-but-set-variable) add_compile_options(-Wno-single-bit-bitfield-constant-conversion) - # Allow using WASM simd intrinsics in the interpreter - add_compile_options(-msimd128) - # Disable autovectorization (it is automatically turned on by msimd128) - add_compile_options(-disable-loop-vectorization) - add_compile_options(-disable-vectorization) - add_compile_options(-fno-vectorize) - add_compile_options(-fno-tree-vectorize) - add_compile_options(-fno-slp-vectorize) set(DISABLE_EXECUTABLES 1) # FIXME: Is there a cmake option for this ? set(DISABLE_SHARED_LIBS 1) diff --git a/src/mono/mono.proj b/src/mono/mono.proj index cf99f32..6be683f 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -1061,6 +1061,12 @@ <_MonoRuntimeArtifacts Condition="'$(TargetsBrowser)' == 'true' and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-wasm-eh-wasm.a"> $(RuntimeBinDir)libmono-wasm-eh-wasm.a + <_MonoRuntimeArtifacts Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-wasm-simd.a"> + $(RuntimeBinDir)libmono-wasm-simd.a + + <_MonoRuntimeArtifacts Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-wasm-nosimd.a"> + $(RuntimeBinDir)libmono-wasm-nosimd.a + <_MonoICorDebugArtifacts Condition="'$(MonoMsCorDbi)' == 'true'" Include="$(MonoObjDir)out\lib\$(LibPrefix)mscordbi$(LibSuffix)"> $(RuntimeBinDir)$(LibPrefix)mscordbi$(LibSuffix) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 884b43c..5d6ef3d 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -288,7 +288,6 @@ set(interp_sources interp/interp.h interp/interp-internals.h interp/interp.c - interp/interp-simd.c interp/interp-intrins.h interp/interp-intrins.c interp/mintops.h @@ -297,11 +296,17 @@ set(interp_sources interp/tiering.h interp/tiering.c interp/jiterpreter.c) +set(interp_simd_sources + interp/interp-simd.c) set(interp_stub_sources interp-stubs.c) if(NOT DISABLE_INTERPRETER) -set(mini_interp_sources ${interp_sources}) + if(HOST_WASM) + set(mini_interp_sources ${interp_sources}) + else() + set(mini_interp_sources ${interp_sources} ${interp_simd_sources}) + endif() else() set(mini_interp_sources ${interp_stub_sources}) endif() @@ -504,6 +509,19 @@ if(HOST_BROWSER) install(TARGETS mono-wasm-eh-wasm LIBRARY) endif() +if(HOST_BROWSER OR HOST_WASI) + add_library(mono-wasm-simd STATIC interp/interp-simd.c) + target_link_libraries (mono-wasm-simd PRIVATE monoapi eglib_api) + set_target_properties(mono-wasm-simd PROPERTIES COMPILE_FLAGS "-msimd128") + install(TARGETS mono-wasm-simd LIBRARY) +endif() + +if(HOST_BROWSER OR HOST_WASI OR TARGET_WASM) + add_library(mono-wasm-nosimd STATIC interp/interp-nosimd.c) + target_link_libraries (mono-wasm-nosimd PRIVATE monoapi eglib_api) + install(TARGETS mono-wasm-nosimd LIBRARY) +endif() + find_package(Python3 COMPONENTS Interpreter) add_custom_command( @@ -576,6 +594,9 @@ if(NOT DISABLE_EXECUTABLES) endif() endif() target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static) + if (HOST_WASM) + target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd) + endif() if(HAVE_ICU_SHIM) target_link_libraries(mono-sgen PRIVATE icu_shim_objects) endif() diff --git a/src/mono/mono/mini/interp/interp-nosimd.c b/src/mono/mono/mini/interp/interp-nosimd.c new file mode 100644 index 0000000..63bcf27 --- /dev/null +++ b/src/mono/mono/mini/interp/interp-nosimd.c @@ -0,0 +1,31 @@ + +#include "interp-internals.h" +#include "interp-simd.h" + +#ifdef INTERP_ENABLE_SIMD + +gboolean interp_simd_enabled = FALSE; + +#ifdef HOST_BROWSER + +int interp_simd_p_p_wasm_opcode_table [] = { +}; + +int interp_simd_p_pp_wasm_opcode_table [] = { +}; + +int interp_simd_p_ppp_wasm_opcode_table [] = { +}; + +#endif // HOST_BROWSER + +PP_SIMD_Method interp_simd_p_p_table [] = { +}; + +PPP_SIMD_Method interp_simd_p_pp_table [] = { +}; + +PPPP_SIMD_Method interp_simd_p_ppp_table [] = { +}; + +#endif // INTERP_ENABLE_SIMD diff --git a/src/mono/mono/mini/interp/interp-simd.c b/src/mono/mono/mini/interp/interp-simd.c index 65e60b4..5031c87 100644 --- a/src/mono/mono/mini/interp/interp-simd.c +++ b/src/mono/mono/mini/interp/interp-simd.c @@ -8,6 +8,8 @@ #ifdef INTERP_ENABLE_SIMD +gboolean interp_simd_enabled = TRUE; + typedef gint64 v128_i8 __attribute__ ((vector_size (SIZEOF_V128))); typedef guint64 v128_u8 __attribute__ ((vector_size (SIZEOF_V128))); typedef gint32 v128_i4 __attribute__ ((vector_size (SIZEOF_V128))); diff --git a/src/mono/mono/mini/interp/interp-simd.h b/src/mono/mono/mini/interp/interp-simd.h index e3306a2..8e022261 100644 --- a/src/mono/mono/mini/interp/interp-simd.h +++ b/src/mono/mono/mini/interp/interp-simd.h @@ -3,6 +3,8 @@ #include +extern gboolean interp_simd_enabled; + typedef void (*PP_SIMD_Method) (gpointer, gpointer); typedef void (*PPP_SIMD_Method) (gpointer, gpointer, gpointer); typedef void (*PPPP_SIMD_Method) (gpointer, gpointer, gpointer, gpointer); diff --git a/src/mono/mono/mini/interp/transform-simd.c b/src/mono/mono/mini/interp/transform-simd.c index 255a2ab..7df7f92 100644 --- a/src/mono/mono/mini/interp/transform-simd.c +++ b/src/mono/mono/mini/interp/transform-simd.c @@ -3,6 +3,7 @@ */ #include "config.h" +#include "interp-simd.h" #include #include #include @@ -900,6 +901,9 @@ interp_emit_simd_intrinsics (TransformData *td, MonoMethod *cmethod, MonoMethodS if (image != mono_get_corlib ()) return FALSE; + if (!interp_simd_enabled) + return FALSE; + class_ns = m_class_get_name_space (cmethod->klass); class_name = m_class_get_name (cmethod->klass); diff --git a/src/mono/wasi/build/WasiApp.Native.targets b/src/mono/wasi/build/WasiApp.Native.targets index 36c6658..ba9c085 100644 --- a/src/mono/wasi/build/WasiApp.Native.targets +++ b/src/mono/wasi/build/WasiApp.Native.targets @@ -273,6 +273,10 @@ <_WasmEHLibToExclude Condition="'$(WasmEnableExceptionHandling)' != 'true'">libmono-wasm-eh-wasm.a + <_WasmSIMDLib Condition="'$(WasmEnableSIMD)' == 'true'">libmono-wasm-simd.a + <_WasmSIMDLib Condition="'$(WasmEnableSIMD)' != 'true'">libmono-wasm-nosimd.a + <_WasmSIMDLibToExclude Condition="'$(WasmEnableSIMD)' != 'true'">libmono-wasm-simd.a + <_WasmSIMDLibToExclude Condition="'$(WasmEnableSIMD)' == 'true'">libmono-wasm-nosimd.a @@ -286,7 +290,9 @@ Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)*.a" Exclude="@(_MonoRuntimeComponentDontLink->'$(MicrosoftNetCoreAppRuntimePackRidNativeDir)%(Identity)')" /> <_WasmNativeFileForLinking Condition="'$(_WasmEHLib)' != ''" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmEHLib)" /> + <_WasmNativeFileForLinking Condition="'$(_WasmSIMDLib)' != ''" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmSIMDLib)" /> <_WasmNativeFileForLinking Remove="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmEHLibToExclude)" /> + <_WasmNativeFileForLinking Remove="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmSIMDLibToExclude)" /> <_WasmNativeFileForLinking Include="$(WasiSysRoot)\lib\wasm32-wasi\libc++.a" /> <_WasmNativeFileForLinking Include="$(WasiSysRoot)\lib\wasm32-wasi\libc++abi.a" /> diff --git a/src/mono/wasi/runtime/CMakeLists.txt b/src/mono/wasi/runtime/CMakeLists.txt index ede21d7..912132b 100644 --- a/src/mono/wasi/runtime/CMakeLists.txt +++ b/src/mono/wasi/runtime/CMakeLists.txt @@ -26,6 +26,7 @@ target_link_libraries(dotnet ${MONO_ARTIFACTS_DIR}/libmono-ee-interp.a ${MONO_ARTIFACTS_DIR}/libmonosgen-2.0.a ${MONO_ARTIFACTS_DIR}/libmono-icall-table.a + ${MONO_ARTIFACTS_DIR}/libmono-wasm-${CONFIGURATION_INTERPSIMDTABLES_LIB}.a ${NATIVE_BIN_DIR}/wasm-bundled-timezones.a ${NATIVE_BIN_DIR}/libSystem.Native.a ${NATIVE_BIN_DIR}/libSystem.Globalization.Native.a diff --git a/src/mono/wasi/wasi.proj b/src/mono/wasi/wasi.proj index 611d796..b942b6f 100644 --- a/src/mono/wasi/wasi.proj +++ b/src/mono/wasi/wasi.proj @@ -218,6 +218,8 @@ $(CMakeBuildRuntimeConfigureCmd) -DICU_LIB_DIR="$(ICULibDir.TrimEnd('\/'))" $(CMakeBuildRuntimeConfigureCmd) -DMONO_ARTIFACTS_DIR="$(MonoArtifactsPath.TrimEnd('\/'))" $(CMakeBuildRuntimeConfigureCmd) -DNATIVE_BIN_DIR="$(NativeBinDir.TrimEnd('\/'))" + $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_COMPILE_OPTIONS="-msimd128" -DCONFIGURATION_INTERPSIMDTABLES_LIB="simd" + $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_INTERPSIMDTABLES_LIB="nosimd" $(CMakeBuildRuntimeConfigureCmd) -DDISABLE_THREADS=0 call "$(RepositoryEngineeringDir)native\init-vs-env.cmd" wasm && $(CMakeBuildRuntimeConfigureCmd) diff --git a/src/mono/wasm/build/WasmApp.Native.targets b/src/mono/wasm/build/WasmApp.Native.targets index 52125a8..7060397 100644 --- a/src/mono/wasm/build/WasmApp.Native.targets +++ b/src/mono/wasm/build/WasmApp.Native.targets @@ -440,6 +440,10 @@ <_WasmEHLib Condition="'$(WasmEnableExceptionHandling)' != 'true'">libmono-wasm-eh-js.a <_WasmEHLibToExclude Condition="'$(WasmEnableExceptionHandling)' == 'true'">libmono-wasm-eh-js.a <_WasmEHLibToExclude Condition="'$(WasmEnableExceptionHandling)' != 'true'">libmono-wasm-eh-wasm.a + <_WasmSIMDLib Condition="'$(WasmEnableSIMD)' == 'true'">libmono-wasm-simd.a + <_WasmSIMDLib Condition="'$(WasmEnableSIMD)' != 'true'">libmono-wasm-nosimd.a + <_WasmSIMDLibToExclude Condition="'$(WasmEnableSIMD)' != 'true'">libmono-wasm-simd.a + <_WasmSIMDLibToExclude Condition="'$(WasmEnableSIMD)' == 'true'">libmono-wasm-nosimd.a <_EmccExportedLibraryFunction>"[@(EmccExportedLibraryFunction -> '%27%(Identity)%27', ',')]" <_EmccExportedRuntimeMethods>"[@(EmccExportedRuntimeMethod -> '%27%(Identity)%27', ',')]" <_EmccExportedFunctions>@(EmccExportedFunction -> '%(Identity)',',') @@ -460,7 +464,9 @@ Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)*.a" Exclude="@(_MonoRuntimeComponentDontLink->'$(MicrosoftNetCoreAppRuntimePackRidNativeDir)%(Identity)')" /> <_WasmNativeFileForLinking Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmEHLib)" /> + <_WasmNativeFileForLinking Condition="'$(_WasmSIMDLib)' != ''" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmSIMDLib)" /> <_WasmNativeFileForLinking Remove="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmEHLibToExclude)" /> + <_WasmNativeFileForLinking Remove="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmSIMDLibToExclude)" /> <_WasmExtraJSFile Include="@(Content)" Condition="'%(Content.Extension)' == '.js'" /> diff --git a/src/mono/wasm/runtime/CMakeLists.txt b/src/mono/wasm/runtime/CMakeLists.txt index 6b8ef87..6d93908 100644 --- a/src/mono/wasm/runtime/CMakeLists.txt +++ b/src/mono/wasm/runtime/CMakeLists.txt @@ -25,6 +25,7 @@ target_link_libraries(dotnet.native ${MONO_ARTIFACTS_DIR}/libmonosgen-2.0.a ${MONO_ARTIFACTS_DIR}/libmono-icall-table.a ${MONO_ARTIFACTS_DIR}/libmono-wasm-eh-js.a + ${MONO_ARTIFACTS_DIR}/libmono-wasm-${CONFIGURATION_INTERPSIMDTABLES_LIB}.a ${MONO_ARTIFACTS_DIR}/libmono-profiler-aot.a ${MONO_ARTIFACTS_DIR}/libmono-profiler-browser.a ${NATIVE_BIN_DIR}/wasm-bundled-timezones.a diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index c46c92a..66bc509 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -388,7 +388,8 @@ $(CMakeBuildRuntimeConfigureCmd) -DICU_LIB_DIR="$(ICULibDir.TrimEnd('\/').Replace('\','/'))" $(CMakeBuildRuntimeConfigureCmd) -DMONO_ARTIFACTS_DIR="$(MonoArtifactsPath.TrimEnd('\/').Replace('\','/'))" $(CMakeBuildRuntimeConfigureCmd) -DNATIVE_BIN_DIR="$(NativeBinDir.TrimEnd('\/').Replace('\','/'))" - $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_COMPILE_OPTIONS="-msimd128" + $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_COMPILE_OPTIONS="-msimd128" -DCONFIGURATION_INTERPSIMDTABLES_LIB="simd" + $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_INTERPSIMDTABLES_LIB="nosimd" $(CMakeBuildRuntimeConfigureCmd) -DDISABLE_THREADS=0 $(CMakeBuildRuntimeConfigureCmd) -DDISABLE_LEGACY_JS_INTEROP=1 $(CMakeBuildRuntimeConfigureCmd) $(CMakeConfigurationEmsdkPath) -- 2.7.4