forked from bytecodealliance/wasmtime-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIXES bytecodealliance#137: make calling wasm from python 7x faster
- Loading branch information
1 parent
f00d32a
commit 7bee159
Showing
2 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
how to call v128 SMID operations | ||
for more details see https://github.com/WebAssembly/simd/blob/main/proposals/simd/SIMD.md#integer-addition | ||
""" | ||
import ctypes | ||
|
||
from functools import partial | ||
from wasmtime import Store, Module, Instance | ||
|
||
|
||
|
||
store = Store() | ||
module = Module(store.engine, """ | ||
(module | ||
(func $add_v128 (param $a v128) (param $b v128) (result v128) | ||
local.get $a | ||
local.get $b | ||
i8x16.add | ||
) | ||
(export "add_v128" (func $add_v128)) | ||
) | ||
""") | ||
|
||
instance = Instance(store, module, []) | ||
vector_type = ctypes.c_uint8*16 | ||
add_v128 = partial(instance.exports(store)["add_v128"], store) | ||
a=vector_type(*(i for i in range(16))) | ||
b=vector_type(*(40+i for i in range(16))) | ||
c=add_v128(a, b) | ||
print([v for v in c]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters