Skip to content

Commit 1498899

Browse files
Added Relaxed SIMD (#256)
* Added config options for relaxed SIMD * Update src/Config.cs Co-authored-by: Peter Huene <[email protected]> --------- Co-authored-by: Peter Huene <[email protected]>
1 parent dde8a4c commit 1498899

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/Config.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ public Config WithSIMD(bool enable)
156156
return this;
157157
}
158158

159+
/// <summary>
160+
/// Sets whether or not to enable WebAssembly Relaxed SIMD support. New SIMD instructions that may be non-deterministic across different hosts unless deterministic mode is enabled.
161+
/// </summary>
162+
/// <param name="enable">True to enable WebAssembly Relaxed SIMD support or false to disable.</param>
163+
/// <param name="deterministic">True to enable deterministic mode for WebAssembly Relaxed SIMD or false to allow non-deterministic execution.</param>
164+
/// <returns>Returns the current config.</returns>
165+
public Config WithRelaxedSIMD(bool enable, bool deterministic)
166+
{
167+
Native.wasmtime_config_wasm_relaxed_simd_set(handle, enable);
168+
Native.wasmtime_config_wasm_relaxed_simd_deterministic_set(handle, deterministic);
169+
return this;
170+
}
171+
159172
/// <summary>
160173
/// Sets whether or not enable WebAssembly bulk memory support.
161174
/// </summary>
@@ -393,6 +406,12 @@ private static class Native
393406
[DllImport(Engine.LibraryName)]
394407
public static extern void wasmtime_config_wasm_simd_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);
395408

409+
[DllImport(Engine.LibraryName)]
410+
public static extern void wasmtime_config_wasm_relaxed_simd_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);
411+
412+
[DllImport(Engine.LibraryName)]
413+
public static extern void wasmtime_config_wasm_relaxed_simd_deterministic_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);
414+
396415
[DllImport(Engine.LibraryName)]
397416
public static extern void wasmtime_config_wasm_bulk_memory_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);
398417

tests/ConfigTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ public void ItSetsSIMD()
119119
act.Should().Throw<WasmtimeException>();
120120
}
121121

122+
[Fact]
123+
public void ItSetsRelaxedSIMD()
124+
{
125+
var config = new Config();
126+
config.WithRelaxedSIMD(true, true);
127+
128+
using var engine = new Engine(config);
129+
using var module = Module.FromTextFile(engine, Path.Combine("Modules", "RelaxedSIMD.wat"));
130+
}
131+
122132
[Fact]
123133
public void ItSetsBulkMemory()
124134
{

tests/Modules/RelaxedSIMD.wat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module
2+
(func $madd_v128 (param v128) (result v128)
3+
local.get 0
4+
local.get 0
5+
local.get 0
6+
f32x4.relaxed_madd
7+
)
8+
(export "$madd_v128" (func $madd_v128))
9+
)

0 commit comments

Comments
 (0)