From b47aa5f5213073acbcef01043bb1dfa35bfa4360 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Fri, 6 Sep 2024 12:10:41 +0200 Subject: [PATCH 1/2] fix https://github.com/dotnet/runtime/issues/107443 --- .../runtime/jiterpreter-trace-generator.ts | 17 ++--------------- src/mono/browser/runtime/startup.ts | 3 +++ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/mono/browser/runtime/jiterpreter-trace-generator.ts b/src/mono/browser/runtime/jiterpreter-trace-generator.ts index 4efa63328eac9..ebc96db45806b 100644 --- a/src/mono/browser/runtime/jiterpreter-trace-generator.ts +++ b/src/mono/browser/runtime/jiterpreter-trace-generator.ts @@ -3459,19 +3459,6 @@ function emit_arrayop (builder: WasmBuilder, frame: NativePointer, ip: MintOpcod return true; } -let wasmSimdSupported: boolean | undefined; - -function getIsWasmSimdSupported (): boolean { - if (wasmSimdSupported !== undefined) - return wasmSimdSupported; - - wasmSimdSupported = runtimeHelpers.featureWasmSimd === true; - if (!wasmSimdSupported) - mono_log_info("Disabling Jiterpreter SIMD"); - - return wasmSimdSupported; -} - function get_import_name ( builder: WasmBuilder, typeName: string, functionPtr: number @@ -3490,7 +3477,7 @@ function emit_simd ( ): boolean { // First, if compiling an intrinsic attempt to emit the special vectorized implementation // We only do this if SIMD is enabled since we'll be using the v128 opcodes. - if (builder.options.enableSimd && getIsWasmSimdSupported()) { + if (builder.options.enableSimd && runtimeHelpers.featureWasmSimd) { switch (argCount) { case 2: if (emit_simd_2(builder, ip, index)) @@ -3510,7 +3497,7 @@ function emit_simd ( // Fall back to a mix of non-vectorized wasm and the interpreter's implementation of the opcodes switch (opcode) { case MintOpcode.MINT_SIMD_V128_LDC: { - if (builder.options.enableSimd && getIsWasmSimdSupported()) { + if (builder.options.enableSimd && runtimeHelpers.featureWasmSimd) { builder.local("pLocals"); const view = localHeapViewU8().slice(ip + 4, ip + 4 + sizeOfV128); builder.v128_const(view); diff --git a/src/mono/browser/runtime/startup.ts b/src/mono/browser/runtime/startup.ts index 4d07e712358b0..834ceb81f2f7b 100644 --- a/src/mono/browser/runtime/startup.ts +++ b/src/mono/browser/runtime/startup.ts @@ -128,6 +128,9 @@ async function instantiateWasmWorker ( successCallback: InstantiateWasmSuccessCallback ): Promise { if (!WasmEnableThreads) return; + + await ensureUsedWasmFeatures(); + // wait for the config to arrive by message from the main thread await loaderHelpers.afterConfigLoaded.promise; From 03a9c6981e5744cce6772c242c62de376b43c694 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Fri, 6 Sep 2024 12:17:49 +0200 Subject: [PATCH 2/2] same for EH --- src/mono/browser/runtime/jiterpreter-jit-call.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/mono/browser/runtime/jiterpreter-jit-call.ts b/src/mono/browser/runtime/jiterpreter-jit-call.ts index f9ee806540c60..48e9797cb29e8 100644 --- a/src/mono/browser/runtime/jiterpreter-jit-call.ts +++ b/src/mono/browser/runtime/jiterpreter-jit-call.ts @@ -61,7 +61,6 @@ const maxJitQueueLength = 6, let trampBuilder: WasmBuilder; let fnTable: WebAssembly.Table; -let wasmEhSupported: boolean | undefined = undefined; let nextDisambiguateIndex = 0; const fnCache: Array = []; const targetCache: { [target: number]: TrampolineInfo } = {}; @@ -276,18 +275,6 @@ export function mono_interp_jit_wasm_jit_call_trampoline ( mono_interp_flush_jitcall_queue(); } -function getIsWasmEhSupported (): boolean { - if (wasmEhSupported !== undefined) - return wasmEhSupported; - - // Probe whether the current environment can handle wasm exceptions - wasmEhSupported = runtimeHelpers.featureWasmEh === true; - if (!wasmEhSupported) - mono_log_info("Disabling Jiterpreter Exception Handling"); - - return wasmEhSupported; -} - export function mono_interp_flush_jitcall_queue (): void { const jitQueue: TrampolineInfo[] = []; let methodPtr = 0; @@ -336,7 +323,7 @@ export function mono_interp_flush_jitcall_queue (): void { } if (builder.options.enableWasmEh) { - if (!getIsWasmEhSupported()) { + if (!runtimeHelpers.featureWasmEh) { // The user requested to enable wasm EH but it's not supported, so turn the option back off applyOptions({ enableWasmEh: false }); builder.options.enableWasmEh = false;