From 26ad367b410d1342521ee7d47657930b04497cdc Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Thu, 5 Sep 2024 08:06:43 -0700 Subject: [PATCH] Use native wasm atomic fence instead of calling C for memory barriers --- src/mono/browser/runtime/jiterpreter-trace-generator.ts | 4 ++-- src/mono/browser/runtime/jiterpreter.ts | 6 ------ src/mono/mono/mini/interp/jiterpreter.c | 5 ----- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/mono/browser/runtime/jiterpreter-trace-generator.ts b/src/mono/browser/runtime/jiterpreter-trace-generator.ts index 8b7ae0afeb2fd6..6122678c158a3d 100644 --- a/src/mono/browser/runtime/jiterpreter-trace-generator.ts +++ b/src/mono/browser/runtime/jiterpreter-trace-generator.ts @@ -10,7 +10,7 @@ import { } from "./memory"; import { WasmOpcode, WasmSimdOpcode, WasmValtype, - getOpcodeName, MintOpArgType + getOpcodeName, MintOpArgType, WasmAtomicOpcode } from "./jiterpreter-opcodes"; import { MintOpcode, SimdInfo, @@ -3956,7 +3956,7 @@ function emit_atomics ( ) { if (opcode === MintOpcode.MINT_MONO_MEMORY_BARRIER) { if (WasmEnableThreads) - builder.callImport("membar"); + builder.appendAtomic(WasmAtomicOpcode.atomic_fence); return true; } diff --git a/src/mono/browser/runtime/jiterpreter.ts b/src/mono/browser/runtime/jiterpreter.ts index c4f865e452aa6c..6b934b879c320f 100644 --- a/src/mono/browser/runtime/jiterpreter.ts +++ b/src/mono/browser/runtime/jiterpreter.ts @@ -286,7 +286,6 @@ function getTraceImports () { ["stelemr_tc", "stelemr", getRawCwrap("mono_jiterp_stelem_ref")], importDef("fma", getRawCwrap("fma")), importDef("fmaf", getRawCwrap("fmaf")), - importDef("membar", getRawCwrap("mono_jiterp_memory_barrier")), ]; if (instrumentedMethodNames.length > 0) { @@ -664,11 +663,6 @@ function initialize_builder (builder: WasmBuilder) { }, WasmValtype.void, true ); - builder.defineType( - "membar", - {}, - WasmValtype.void, true - ); const traceImports = getTraceImports(); diff --git a/src/mono/mono/mini/interp/jiterpreter.c b/src/mono/mono/mini/interp/jiterpreter.c index 2bb2204accbf76..fa75f766cec02b 100644 --- a/src/mono/mono/mini/interp/jiterpreter.c +++ b/src/mono/mono/mini/interp/jiterpreter.c @@ -1165,11 +1165,6 @@ mono_jiterp_stelem_ref ( return 1; } -EMSCRIPTEN_KEEPALIVE void -mono_jiterp_memory_barrier () { - mono_memory_barrier (); -} - // keep in sync with jiterpreter-enums.ts JiterpMember enum {