Skip to content

Commit 20d508b

Browse files
github-actions[bot]radekdouliklewing
authored
[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 <radek.doulik@gmail.com> Co-authored-by: Larry Ewing <lewing@microsoft.com>
1 parent 52f3d10 commit 20d508b

File tree

14 files changed

+88
-11
lines changed

14 files changed

+88
-11
lines changed

src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@
197197
<PlatformManifestFileEntry Include="libmono-profiler-browser.a" IsNative="true" />
198198
<PlatformManifestFileEntry Include="libmono-wasm-eh-js.a" IsNative="true" />
199199
<PlatformManifestFileEntry Include="libmono-wasm-eh-wasm.a" IsNative="true" />
200+
<PlatformManifestFileEntry Include="libmono-wasm-simd.a" IsNative="true" />
201+
<PlatformManifestFileEntry Include="libmono-wasm-nosimd.a" IsNative="true" />
200202
<PlatformManifestFileEntry Include="wasm-bundled-timezones.a" IsNative="true" />
201203
<PlatformManifestFileEntry Include="dotnet.js" IsNative="true" />
202204
<PlatformManifestFileEntry Include="dotnet.js.map" IsNative="true" />

src/mono/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,6 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "emscripten")
242242
add_compile_options(-Wno-strict-prototypes)
243243
add_compile_options(-Wno-unused-but-set-variable)
244244
add_compile_options(-Wno-single-bit-bitfield-constant-conversion)
245-
# Allow using WASM simd intrinsics in the interpreter
246-
add_compile_options(-msimd128)
247-
# Disable autovectorization (it is automatically turned on by msimd128)
248-
add_compile_options(-disable-loop-vectorization)
249-
add_compile_options(-disable-vectorization)
250-
add_compile_options(-fno-vectorize)
251-
add_compile_options(-fno-tree-vectorize)
252-
add_compile_options(-fno-slp-vectorize)
253245
set(DISABLE_EXECUTABLES 1)
254246
# FIXME: Is there a cmake option for this ?
255247
set(DISABLE_SHARED_LIBS 1)

src/mono/mono.proj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,12 @@
10611061
<_MonoRuntimeArtifacts Condition="'$(TargetsBrowser)' == 'true' and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-wasm-eh-wasm.a">
10621062
<Destination>$(RuntimeBinDir)libmono-wasm-eh-wasm.a</Destination>
10631063
</_MonoRuntimeArtifacts>
1064+
<_MonoRuntimeArtifacts Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-wasm-simd.a">
1065+
<Destination>$(RuntimeBinDir)libmono-wasm-simd.a</Destination>
1066+
</_MonoRuntimeArtifacts>
1067+
<_MonoRuntimeArtifacts Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-wasm-nosimd.a">
1068+
<Destination>$(RuntimeBinDir)libmono-wasm-nosimd.a</Destination>
1069+
</_MonoRuntimeArtifacts>
10641070
<_MonoICorDebugArtifacts Condition="'$(MonoMsCorDbi)' == 'true'" Include="$(MonoObjDir)out\lib\$(LibPrefix)mscordbi$(LibSuffix)">
10651071
<Destination>$(RuntimeBinDir)$(LibPrefix)mscordbi$(LibSuffix)</Destination>
10661072
</_MonoICorDebugArtifacts>

src/mono/mono/mini/CMakeLists.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ set(interp_sources
288288
interp/interp.h
289289
interp/interp-internals.h
290290
interp/interp.c
291-
interp/interp-simd.c
292291
interp/interp-intrins.h
293292
interp/interp-intrins.c
294293
interp/mintops.h
@@ -297,11 +296,17 @@ set(interp_sources
297296
interp/tiering.h
298297
interp/tiering.c
299298
interp/jiterpreter.c)
299+
set(interp_simd_sources
300+
interp/interp-simd.c)
300301
set(interp_stub_sources
301302
interp-stubs.c)
302303

303304
if(NOT DISABLE_INTERPRETER)
304-
set(mini_interp_sources ${interp_sources})
305+
if(HOST_WASM)
306+
set(mini_interp_sources ${interp_sources})
307+
else()
308+
set(mini_interp_sources ${interp_sources} ${interp_simd_sources})
309+
endif()
305310
else()
306311
set(mini_interp_sources ${interp_stub_sources})
307312
endif()
@@ -504,6 +509,19 @@ if(HOST_BROWSER)
504509
install(TARGETS mono-wasm-eh-wasm LIBRARY)
505510
endif()
506511

512+
if(HOST_BROWSER OR HOST_WASI)
513+
add_library(mono-wasm-simd STATIC interp/interp-simd.c)
514+
target_link_libraries (mono-wasm-simd PRIVATE monoapi eglib_api)
515+
set_target_properties(mono-wasm-simd PROPERTIES COMPILE_FLAGS "-msimd128")
516+
install(TARGETS mono-wasm-simd LIBRARY)
517+
endif()
518+
519+
if(HOST_BROWSER OR HOST_WASI OR TARGET_WASM)
520+
add_library(mono-wasm-nosimd STATIC interp/interp-nosimd.c)
521+
target_link_libraries (mono-wasm-nosimd PRIVATE monoapi eglib_api)
522+
install(TARGETS mono-wasm-nosimd LIBRARY)
523+
endif()
524+
507525
find_package(Python3 COMPONENTS Interpreter)
508526

509527
add_custom_command(
@@ -576,6 +594,9 @@ if(NOT DISABLE_EXECUTABLES)
576594
endif()
577595
endif()
578596
target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static)
597+
if (HOST_WASM)
598+
target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd)
599+
endif()
579600
if(HAVE_ICU_SHIM)
580601
target_link_libraries(mono-sgen PRIVATE icu_shim_objects)
581602
endif()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
#include "interp-internals.h"
3+
#include "interp-simd.h"
4+
5+
#ifdef INTERP_ENABLE_SIMD
6+
7+
gboolean interp_simd_enabled = FALSE;
8+
9+
#ifdef HOST_BROWSER
10+
11+
int interp_simd_p_p_wasm_opcode_table [] = {
12+
};
13+
14+
int interp_simd_p_pp_wasm_opcode_table [] = {
15+
};
16+
17+
int interp_simd_p_ppp_wasm_opcode_table [] = {
18+
};
19+
20+
#endif // HOST_BROWSER
21+
22+
PP_SIMD_Method interp_simd_p_p_table [] = {
23+
};
24+
25+
PPP_SIMD_Method interp_simd_p_pp_table [] = {
26+
};
27+
28+
PPPP_SIMD_Method interp_simd_p_ppp_table [] = {
29+
};
30+
31+
#endif // INTERP_ENABLE_SIMD

src/mono/mono/mini/interp/interp-simd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#ifdef INTERP_ENABLE_SIMD
1010

11+
gboolean interp_simd_enabled = TRUE;
12+
1113
typedef gint64 v128_i8 __attribute__ ((vector_size (SIZEOF_V128)));
1214
typedef guint64 v128_u8 __attribute__ ((vector_size (SIZEOF_V128)));
1315
typedef gint32 v128_i4 __attribute__ ((vector_size (SIZEOF_V128)));

src/mono/mono/mini/interp/interp-simd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <glib.h>
55

6+
extern gboolean interp_simd_enabled;
7+
68
typedef void (*PP_SIMD_Method) (gpointer, gpointer);
79
typedef void (*PPP_SIMD_Method) (gpointer, gpointer, gpointer);
810
typedef void (*PPPP_SIMD_Method) (gpointer, gpointer, gpointer, gpointer);

src/mono/mono/mini/interp/transform-simd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
#include "config.h"
6+
#include "interp-simd.h"
67
#include <glib.h>
78
#include <mono/utils/bsearch.h>
89
#include <mono/metadata/class-internals.h>
@@ -900,6 +901,9 @@ interp_emit_simd_intrinsics (TransformData *td, MonoMethod *cmethod, MonoMethodS
900901
if (image != mono_get_corlib ())
901902
return FALSE;
902903

904+
if (!interp_simd_enabled)
905+
return FALSE;
906+
903907
class_ns = m_class_get_name_space (cmethod->klass);
904908
class_name = m_class_get_name (cmethod->klass);
905909

src/mono/wasi/build/WasiApp.Native.targets

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@
273273
<!--<_WasmEHLib Condition="'$(WasmEnableExceptionHandling)' != 'true'">libmono-wasm-eh-js.a</_WasmEHLib>-->
274274
<!--<_WasmEHLibToExclude Condition="'$(WasmEnableExceptionHandling)' == 'true'">libmono-wasm-eh-js.a</_WasmEHLibToExclude>-->
275275
<_WasmEHLibToExclude Condition="'$(WasmEnableExceptionHandling)' != 'true'">libmono-wasm-eh-wasm.a</_WasmEHLibToExclude>
276+
<_WasmSIMDLib Condition="'$(WasmEnableSIMD)' == 'true'">libmono-wasm-simd.a</_WasmSIMDLib>
277+
<_WasmSIMDLib Condition="'$(WasmEnableSIMD)' != 'true'">libmono-wasm-nosimd.a</_WasmSIMDLib>
278+
<_WasmSIMDLibToExclude Condition="'$(WasmEnableSIMD)' != 'true'">libmono-wasm-simd.a</_WasmSIMDLibToExclude>
279+
<_WasmSIMDLibToExclude Condition="'$(WasmEnableSIMD)' == 'true'">libmono-wasm-nosimd.a</_WasmSIMDLibToExclude>
276280
</PropertyGroup>
277281

278282
<ItemGroup>
@@ -286,7 +290,9 @@
286290
Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)*.a"
287291
Exclude="@(_MonoRuntimeComponentDontLink->'$(MicrosoftNetCoreAppRuntimePackRidNativeDir)%(Identity)')" />
288292
<_WasmNativeFileForLinking Condition="'$(_WasmEHLib)' != ''" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmEHLib)" />
293+
<_WasmNativeFileForLinking Condition="'$(_WasmSIMDLib)' != ''" Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmSIMDLib)" />
289294
<_WasmNativeFileForLinking Remove="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmEHLibToExclude)" />
295+
<_WasmNativeFileForLinking Remove="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmSIMDLibToExclude)" />
290296

291297
<_WasmNativeFileForLinking Include="$(WasiSysRoot)\lib\wasm32-wasi\libc++.a" />
292298
<_WasmNativeFileForLinking Include="$(WasiSysRoot)\lib\wasm32-wasi\libc++abi.a" />

src/mono/wasi/runtime/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ target_link_libraries(dotnet
2626
${MONO_ARTIFACTS_DIR}/libmono-ee-interp.a
2727
${MONO_ARTIFACTS_DIR}/libmonosgen-2.0.a
2828
${MONO_ARTIFACTS_DIR}/libmono-icall-table.a
29+
${MONO_ARTIFACTS_DIR}/libmono-wasm-${CONFIGURATION_INTERPSIMDTABLES_LIB}.a
2930
${NATIVE_BIN_DIR}/wasm-bundled-timezones.a
3031
${NATIVE_BIN_DIR}/libSystem.Native.a
3132
${NATIVE_BIN_DIR}/libSystem.Globalization.Native.a

0 commit comments

Comments
 (0)