Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
08ae03b
Add a skeleton updated README/Overview
alexcrichton Aug 14, 2024
f9f9c18
Merge pull request #1 from WebAssembly/skeleton
alexcrichton Aug 14, 2024
607364a
Fill out an initial Overview.md
alexcrichton Aug 14, 2024
095d760
Merge pull request #8 from WebAssembly/add-overfiew
alexcrichton Aug 19, 2024
19b1a55
Replace hard tabs with spaces in overview
alexcrichton Aug 19, 2024
d8b3ba3
Merge pull request #9 from WebAssembly/no-tabs
alexcrichton Aug 19, 2024
22c0eba
Fill out the alternatives section for overflow flags
alexcrichton Aug 20, 2024
5186192
chore: fix README typo
IceTDrinker Aug 23, 2024
1e9f538
Merge pull request #12 from IceTDrinker/chore/fix-readme-typo
alexcrichton Aug 23, 2024
350e0d2
Merge pull request #10 from WebAssembly/overflow-flag-alternative
alexcrichton Aug 26, 2024
2f60102
Remove `i64.mul128`, add `i64.mul_wide_{s,u}`
alexcrichton Sep 5, 2024
1951115
Document leaving out comparison-related instructions
alexcrichton Sep 5, 2024
75f891a
Add some links to issue discussion from the overview
alexcrichton Sep 5, 2024
21a4319
Merge pull request #16 from WebAssembly/add-some-links
alexcrichton Sep 5, 2024
07f8593
Add a link to an issue
alexcrichton Sep 5, 2024
5d13483
Add an explicit note pointing to the issue
alexcrichton Sep 5, 2024
9650d9b
Merge pull request #14 from WebAssembly/document-no-compares
alexcrichton Sep 10, 2024
91e8f31
Merge pull request #13 from WebAssembly/remove-mul128
alexcrichton Sep 10, 2024
b89c0ce
Summarize discussion of shifting operators in Overview
alexcrichton Sep 20, 2024
3f6f479
Fill out some more rationale on overflow flags
alexcrichton Sep 20, 2024
228c9ed
Introduce some more subsections, reword and reorder
alexcrichton Sep 23, 2024
4eec709
Small clarification
alexcrichton Sep 23, 2024
e69f359
Merge pull request #17 from WebAssembly/summarize-shifts
alexcrichton Sep 23, 2024
c48f62d
Merge pull request #18 from WebAssembly/more-words-about-overflow-flags
alexcrichton Sep 23, 2024
aa3f5c4
Rename repository to "wide-arithmetic"
alexcrichton Oct 8, 2024
33a6662
Merge pull request #20 from WebAssembly/rename-proposal
alexcrichton Oct 8, 2024
7336c7a
Update implementation status
alexcrichton Oct 9, 2024
d455e74
Merge pull request #21 from WebAssembly/update-implementation-status
alexcrichton Oct 9, 2024
260c687
Merge remote-tracking branch 'spec/main'
alexcrichton Oct 16, 2024
bbf4e37
Merge pull request #23 from WebAssembly/merge
alexcrichton Oct 16, 2024
f292896
Add initial tests and interpreter support
alexcrichton Oct 16, 2024
ac04d8d
Update reference interpreter status in overview
alexcrichton Oct 16, 2024
bf99b7c
Try fixing CI
alexcrichton Oct 16, 2024
7ca1328
Disable node tests
alexcrichton Oct 16, 2024
6270ae8
Update tests ticky box in overview
alexcrichton Oct 16, 2024
d2b3d04
Merge pull request #22 from WebAssembly/update-interpreter
alexcrichton Oct 17, 2024
fcb020b
Add Rust toolchain under implementation status
alexcrichton Oct 23, 2024
fb00860
Merge pull request #24 from WebAssembly/update-toolchain-listings
alexcrichton Oct 23, 2024
3672bdb
Fill out spec text for new instructions
alexcrichton Oct 24, 2024
a59154f
Link to spec from implementation status
alexcrichton Oct 24, 2024
a364ecc
Merge pull request #25 from WebAssembly/spec
alexcrichton Oct 26, 2024
d02f4ec
Add links to new parts of spec
alexcrichton Oct 26, 2024
49a77e2
Merge pull request #26 from WebAssembly/new-spec
alexcrichton Oct 26, 2024
fb4d10f
Indicate the phase of the proposal in the README
alexcrichton Nov 3, 2024
1cebf1c
Merge pull request #27 from WebAssembly/readme-phase
alexcrichton Nov 3, 2024
8b545f5
Fix typo in Overview.md
ranma42 Dec 30, 2024
59d37ba
Merge pull request #30 from ranma42/fix-typo
alexcrichton Dec 30, 2024
357f8a2
Merge remote-tracking branch 'spec/main'
alexcrichton Jan 30, 2025
5450f67
Merge pull request #31 from WebAssembly/merge-with-upsteram-spec
alexcrichton Jan 30, 2025
7c4026f
Fix typo in overview
alexcrichton Jan 31, 2025
8b97e12
Merge pull request #32 from WebAssembly/fix-typo
alexcrichton Feb 25, 2025
e34e59b
mention Wasmi in the list of engines supporting the proposal
Robbepop Mar 12, 2025
228cce3
Merge pull request #35 from Robbepop/rf-mention-wasmi-engine
alexcrichton Mar 12, 2025
32a50d6
Summarize the conclusion of `i64.add_wide3`
alexcrichton Mar 21, 2025
47940f9
Merge pull request #36 from WebAssembly/add-wide3
alexcrichton Mar 28, 2025
d6ab6ba
Update phase listing of this proposal in README
alexcrichton Apr 8, 2025
5b38d8f
Merge pull request #37 from WebAssembly/bump-phase
alexcrichton Apr 8, 2025
d8a2142
Merge remote-tracking branch 'spec/main'
alexcrichton Sep 18, 2025
6cc9e9b
Reimplement interpreter support for wide-arithmetic
alexcrichton Sep 18, 2025
6cc1b23
Attempt to update spec/spectec for wide arithmetic
alexcrichton Sep 18, 2025
a35c7fa
Install stdint
alexcrichton Sep 18, 2025
ede598a
Update `TEST.md` files
alexcrichton Sep 18, 2025
12e3362
Refactoring and attempting to make progress
alexcrichton Sep 19, 2025
1e3e6ea
A small bit more progress
alexcrichton Sep 19, 2025
3f4e3eb
More updates
alexcrichton Sep 19, 2025
ad392a5
Attempt a fix
alexcrichton Sep 19, 2025
f92513b
Merge pull request #38 from WebAssembly/rebase-with-main
alexcrichton Sep 19, 2025
72e2faa
Merge remote-tracking branch 'spec/main'
alexcrichton Sep 19, 2025
c1289dc
Merge pull request #39 from WebAssembly/merge
alexcrichton Sep 19, 2025
15035be
Merge commit 'e01ace5eb7c88ce58e444f1700c1bf4175e47e28'
alexcrichton Sep 21, 2025
4c77955
Merge pull request #40 from WebAssembly/another-merge
alexcrichton Sep 21, 2025
b88f61c
Update README links
alexcrichton Sep 21, 2025
8969208
Merge pull request #41 from WebAssembly/update-link
alexcrichton Sep 21, 2025
5f7f6de
Add a diff-to-main link
alexcrichton Sep 21, 2025
0224336
Merge pull request #42 from WebAssembly/diff-to-main
alexcrichton Sep 21, 2025
cd00377
add chasm to supported engine list
CharlieTap Sep 25, 2025
51cee32
Merge pull request #43 from CharlieTap/wide-arith-main
alexcrichton Sep 25, 2025
00acf2a
Add wasm-language-tools to list of implementations
g-plane Jan 8, 2026
fb8db19
Merge pull request #44 from g-plane/patch-1
alexcrichton Jan 8, 2026
a0d5f91
Add JavaScriptCore to implementations
kmiller68 Apr 16, 2026
5d5f2c8
Merge pull request #45 from kmiller68/add-jsc-wide-arithmetic-support
alexcrichton Apr 16, 2026
fc7cc90
Add SpiderMonkey implementation
alexcrichton Apr 21, 2026
d69dfd6
Merge pull request #46 from WebAssembly/add-sm
alexcrichton Apr 21, 2026
7089799
include Wasmer implementation link
marxin Apr 24, 2026
429bda3
Merge pull request #48 from marxin/wasmer-impl
alexcrichton Apr 24, 2026
11659e0
Merge remote-tracking branch 'spec/main'
alexcrichton Aug 10, 2026
ced7773
Reduce some diff with the upstream spec
alexcrichton Aug 10, 2026
67f93aa
Re-bless output
alexcrichton Aug 10, 2026
0abadfc
Merge pull request #51 from WebAssembly/merge-upstream-spec
alexcrichton Aug 10, 2026
a11c8e7
Undo mixup in `TEST.md` blessed files
alexcrichton Aug 10, 2026
c2de27d
Restore README to what it is on `main`
alexcrichton Aug 10, 2026
aa21c75
Use spectec for text syntax
alexcrichton Aug 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci-interpreter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: 5.04.x
- name: Setup OCaml tools
run: opam install --yes stdint.0.7.2
- name: Build interpreter
run: cd interpreter && opam exec make jsdeps wasm
# Neither V8 nor SpiderMonkey can currently handle all 3.0 tests, so we disable checking JS translation for now.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
with:
ocaml-compiler: 5.04.x
- name: Setup Dune
run: opam install --yes dune menhir mdx zarith && opam exec dune --version
run: opam install --yes dune menhir mdx zarith stdint.0.7.2 && opam exec dune --version
- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-spectec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
ocaml-compiler: 5.04.x
- name: Setup Dune
run: opam install --yes dune menhir mdx zarith
run: opam install --yes dune menhir mdx zarith stdint.0.7.2
- name: Setup Latex
run: sudo apt-get update -y && sudo apt-get install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended
- name: Setup Sphinx
Expand Down
7 changes: 7 additions & 0 deletions document/core/binary/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ whereas the actual opcode is encoded by a variable-length :ref:`unsigned integer

$${grammar: Binstr/num-cvt-sat}

.. _binary-num-wide:

wide-arithmetic instructions have a 1-byte prefix and the actual opcode is
encoded by a variable-length :ref:`unsigned integer <binary-uint>`.

$${grammar: Binstr/num-wide}


.. index:: vector instruction
pair: binary format; instruction
Expand Down
14 changes: 14 additions & 0 deletions document/core/exec/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,20 @@ $${rule-prose: Step_pure/cvtop}
$${rule: {Step_pure/cvtop-*}}


.. _exec-wideop:

$${rule-prose: Step_pure/wideop}

$${rule: {Step_pure/wideop}}


.. _exec-extwideop:

$${rule-prose: Step_pure/extwideop}

$${rule: {Step_pure/extwideop}}


.. index:: vector instruction
pair: execution; instruction
single: abstract syntax; instruction
Expand Down
31 changes: 31 additions & 0 deletions document/core/exec/numerics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,37 @@ The integer result of predicates -- i.e., :ref:`tests <syntax-testop>` and :ref:
\iq15mulrsats_N(i_1, i_2) &=& \signed_N^{-1}(\sats_N(\ishrs_N(i_1 \cdot i_2 + 2^{14}, 15)))
\end{array}

.. _op-iconcat:

:math:`\iconcat_{M,N}(i_1, i_2)`
.................................

* Let :math:`h` be the result of :math:`\ishl_N(\extend^u_{M,N}(i_2), M)`

* Return the result of :math:`\ior_N(\extend^u_{M,N}(i_1), h)`

.. math::
\begin{array}{lll@{\qquad}l}
\iconcat_{M,N}(i_1, i_2) &=& \ior_N(\extend^u_{M,N}(i_1), \ishl_N(\extend^u_{M,N}(i_2), M))
\end{array}


.. _op-isplit:

:math:`\isplit_{M,N}(i)`
.................................

* Let :math:`l` be the result of :math:`\wrap_{M,N}(i)`

* Let :math:`h` be the result of :math:`\wrap_{M,N}(\ishru_M(i, N))`

* Return :math:`l, h`

.. math::
\begin{array}{lll@{\qquad}l}
\isplit_{M,N}(i) &=& \wrap_{M,N}(i), \wrap_{M,N}(\ishru_M(i, N))
\end{array}


.. index:: floating-point, IEEE 754
.. _float-ops:
Expand Down
4 changes: 3 additions & 1 deletion document/core/syntax/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,16 @@ The instructions ${:ANY.CONVERT_EXTERN} and ${:EXTERN.CONVERT_ANY} allow lossles
.. _syntax-relop:
.. _syntax-cvtop:
.. _syntax-instr-numeric:
.. _syntax-wideop:
.. _syntax-extwideop:

Numeric Instructions
~~~~~~~~~~~~~~~~~~~~

Numeric instructions provide basic operations over numeric :ref:`values <syntax-value>` of specific :ref:`type <syntax-numtype>`.
These operations closely match respective operations available in hardware.

$${syntax: {sz sx} num_ instr/num unop_ binop_ testop_ relop_ cvtop__}
$${syntax: {sz sx} num_ instr/num unop_ binop_ testop_ relop_ cvtop__ wideop_ extwideop_}

Numeric instructions are divided by :ref:`number type <syntax-numtype>`.
For each type, several subcategories can be distinguished:
Expand Down
6 changes: 6 additions & 0 deletions document/core/text/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ $${grammar: {
Tplaininstr_/num-cvt-reinterpret
}}

.. _text-wideop:

$${grammar: {
Tplaininstr_/num-wide
}}


.. index:: vector instruction
pair: text format; instruction
Expand Down
8 changes: 8 additions & 0 deletions document/core/util/macros.def
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@
.. |DEMOTE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{demote}}
.. |REINTERPRET| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{reinterpret}}

.. |ADD128| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{add128}}
.. |SUB128| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{sub128}}
.. |MULWIDE| mathdef:: \xref{syntax/instructions}{syntax-instr-numeric}{\K{mul\_wide}}

.. |VCONST| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{const}}
.. |VSHUFFLE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{shuffle}}
.. |VSWIZZLE| mathdef:: \xref{syntax/instructions}{syntax-instr-vec}{\K{swizzle}}
Expand Down Expand Up @@ -694,6 +698,8 @@
.. |testop| mathdef:: \xref{syntax/instructions}{syntax-testop}{\X{testop}}
.. |relop| mathdef:: \xref{syntax/instructions}{syntax-relop}{\X{relop}}
.. |cvtop| mathdef:: \xref{syntax/instructions}{syntax-cvtop}{\X{cvtop}}
.. |wideop| mathdef:: \xref{syntax/instructions}{syntax-wideop}{\X{wideop}}
.. |extwideop| mathdef:: \xref{syntax/instructions}{syntax-extwideop}{\X{extwideop}}

.. |unopF| mathdef:: \xref{exec/instructions}{exec-instr-numeric}{\X{unop}}
.. |binopF| mathdef:: \xref{exec/instructions}{exec-instr-numeric}{\X{binop}}
Expand Down Expand Up @@ -1637,6 +1643,8 @@
.. |iavgru| mathdef:: \xref{exec/numerics}{op-iavgr}{\F{iavgr\_u}}
.. |iq15mulrsat| mathdef:: \xref{exec/numerics}{op-iq15mulrsat}{\F{iq15mulrsat}}
.. |iq15mulrsats| mathdef:: \xref{exec/numerics}{op-iq15mulrsat}{\F{iq15mulrsat\_s}}
.. |isplit| mathdef:: \xref{exec/numerics}{op-isplit}{\F{isplit}}
.. |iconcat| mathdef:: \xref{exec/numerics}{op-iconcat}{\F{iconcat}}

.. |fadd| mathdef:: \xref{exec/numerics}{op-fadd}{\F{fadd}}
.. |fsub| mathdef:: \xref{exec/numerics}{op-fsub}{\F{fsub}}
Expand Down
20 changes: 20 additions & 0 deletions document/core/valid/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,26 @@ $${rule-prose: Instr_ok/cvtop}
$${rule: Instr_ok/cvtop}


.. _valid-wideop:

:math:`t_1\K{.}\wideop`
..........................................

$${rule-prose: Instr_ok/wideop}

$${rule: Instr_ok/wideop}


.. _valid-extwideop:

:math:`t_1\K{.}\extwideop`
..........................................

$${rule-prose: Instr_ok/extwideop}

$${rule: Instr_ok/extwideop}


.. index:: vector instruction
pair: validation; instruction
single: abstract syntax; instruction
Expand Down
4 changes: 4 additions & 0 deletions interpreter/binary/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ let rec instr s =
| 0x0fl -> let x = at idx s in table_grow x
| 0x10l -> let x = at idx s in table_size x
| 0x11l -> let x = at idx s in table_fill x
| 0x13l -> i64_add128
| 0x14l -> i64_sub128
| 0x15l -> i64_mul_wide_s
| 0x16l -> i64_mul_wide_u

| n -> illegal2 s pos b n
)
Expand Down
11 changes: 11 additions & 0 deletions interpreter/binary/encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,17 @@ struct
| VecReplace (V128 (F32x4 V128Op.(Replace i))) -> vecop 0x20l; u8 i
| VecReplace (V128 (F64x2 V128Op.(Replace i))) -> vecop 0x22l; u8 i

| Wide (I64 I64Op.Add128) -> op 0xfc; u32 0x13l
| Wide (I64 I64Op.Sub128) -> op 0xfc; u32 0x14l
| Wide (I32 _) -> .
| Wide (F32 _) -> .
| Wide (F64 _) -> .
| Extwide (I64 (I64Op.MulWide S)) -> op 0xfc; u32 0x15l
| Extwide (I64 (I64Op.MulWide U)) -> op 0xfc; u32 0x16l
| Extwide (I32 _) -> .
| Extwide (F32 _) -> .
| Extwide (F64 _) -> .

and catch c =
match c.it with
| Catch (x1, x2) -> byte 0x00; idx x1; idx x2
Expand Down
1 change: 1 addition & 0 deletions interpreter/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(library
(public_name wasm)
(modules :standard \ main wasm wast smallint)
(libraries stdint)
)

(executable
Expand Down
1 change: 1 addition & 0 deletions interpreter/dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
(depends
(ocaml (>= 4.14))
(menhir (>= 20220210))
(stdint (>= 0.7.2))
)
)
8 changes: 8 additions & 0 deletions interpreter/exec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,14 @@ let rec step (c : config) : config =
(try Vec (Eval_vec.eval_vreplaceop replaceop v r) :: vs', []
with exn -> vs', [Trapping (numeric_error e.at exn) @@ e.at])

| Wide op, Num rhs_hi :: Num rhs_lo :: Num lhs_hi :: Num lhs_lo :: vs' ->
let (lo, hi) = Eval_num.eval_wideop op lhs_lo lhs_hi rhs_lo rhs_hi
in Num hi :: Num lo :: vs', []

| Extwide op, Num rhs :: Num lhs :: vs' ->
let (lo, hi) = Eval_num.eval_extwideop op lhs rhs
in Num hi :: Num lo :: vs', []

| _ ->
let s1 = string_of_values (List.rev vs) in
let s2 = string_of_resulttype (List.map type_of_value (List.rev vs)) in
Expand Down
36 changes: 34 additions & 2 deletions interpreter/exec/eval_num.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,35 @@ struct
in fun v1 v2 -> f (of_num 1 v1) (of_num 2 v2)
end

module I32Op = IntOp (I32) (I32Num)
module I64Op = IntOp (I64) (I64Num)
module I32Op = struct
include IntOp (I32) (I32Num)

let wideop (op: Ast.I32Op.wideop) = match op with _ -> .
let extwideop (op: Ast.I32Op.extwideop) = match op with _ -> .
end
module I64Op = struct
include IntOp (I64) (I64Num)

open Ast.IntOp
open I64Num

let wideop op =
let f = match op with
| Ast.I64Op.Add128 -> I64.add128
| Ast.I64Op.Sub128 -> I64.sub128
in fun v1 v2 v3 v4 ->
let (a, b) = f (of_num 1 v1) (of_num 2 v2) (of_num 3 v3) (of_num 4 v4)
in (to_num a, to_num b)

let extwideop op =
let f = match op with
| Ast.I64Op.MulWide S -> I64.mul_wide_s
| Ast.I64Op.MulWide U -> I64.mul_wide_u
in fun v1 v2 ->
let (a, b) = f (of_num 1 v1) (of_num 2 v2)
in (to_num a, to_num b)
end



(* Float operators *)
Expand Down Expand Up @@ -100,6 +127,9 @@ struct
| Gt -> FXX.gt
| Ge -> FXX.ge
in fun v1 v2 -> f (of_num 1 v1) (of_num 2 v2)

let wideop (op: Ast.FloatOp.wideop) = match op with _ -> .
let extwideop (op: Ast.FloatOp.extwideop) = match op with _ -> .
end

module F32Op = FloatOp (F32) (F32Num)
Expand Down Expand Up @@ -194,3 +224,5 @@ let eval_binop = op I32Op.binop I64Op.binop F32Op.binop F64Op.binop
let eval_testop = op I32Op.testop I64Op.testop F32Op.testop F64Op.testop
let eval_relop = op I32Op.relop I64Op.relop F32Op.relop F64Op.relop
let eval_cvtop = op I32CvtOp.cvtop I64CvtOp.cvtop F32CvtOp.cvtop F64CvtOp.cvtop
let eval_wideop = op I32Op.wideop I64Op.wideop F32Op.wideop F64Op.wideop
let eval_extwideop = op I32Op.extwideop I64Op.extwideop F32Op.extwideop F64Op.extwideop
2 changes: 2 additions & 0 deletions interpreter/exec/eval_num.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ val eval_binop : Ast.binop -> num -> num -> num
val eval_testop : Ast.testop -> num -> bool
val eval_relop : Ast.relop -> num -> num -> bool
val eval_cvtop : Ast.cvtop -> num -> num
val eval_wideop : Ast.wideop -> num -> num -> num -> num -> num * num
val eval_extwideop : Ast.extwideop -> num -> num -> num * num
22 changes: 22 additions & 0 deletions interpreter/exec/i64.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,25 @@ include Ixx.Make
let to_int64 = Fun.id
let to_hex_string = Printf.sprintf "%Lx"
end)

open Stdint

let to_i128 lo hi =
let lo = Int128.of_uint64 (Uint64.of_int64 lo) in
let hi = Int128.of_uint64 (Uint64.of_int64 hi) in
Int128.logor lo (Int128.shift_left hi 64)

let split_i128 v =
let lo = Int64.of_int128 v in
let hi = Int64.of_int128 (Int128.shift_right v 64) in
(lo, hi)

let add128 a b c d = split_i128 (Int128.add (to_i128 a b) (to_i128 c d))
let sub128 a b c d = split_i128 (Int128.sub (to_i128 a b) (to_i128 c d))

let mul_wide_s a b = split_i128 (Int128.mul (Int128.of_int64 a) (Int128.of_int64 b))
let mul_wide_u a b =
let a = Uint64.of_int64 a in
let b = Uint64.of_int64 b in
let c = Uint128.mul (Uint128.of_uint64 a) (Uint128.of_uint64 b) in
split_i128 (Int128.of_uint128 c)
18 changes: 16 additions & 2 deletions interpreter/syntax/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@ struct
type cvtop = ConvertI32 of sx | ConvertI64 of sx
| PromoteF32 | DemoteF64
| ReinterpretInt
type wideop = |
type extwideop = |
end

module I32Op = IntOp
module I64Op = IntOp
module I32Op = struct
include IntOp
type wideop = |
type extwideop = |
end
module I64Op = struct
include IntOp
type wideop = Add128 | Sub128
type extwideop = MulWide of sx
end
module F32Op = FloatOp
module F64Op = FloatOp

Expand Down Expand Up @@ -114,6 +124,8 @@ type unop = (I32Op.unop, I64Op.unop, F32Op.unop, F64Op.unop) Value.op
type binop = (I32Op.binop, I64Op.binop, F32Op.binop, F64Op.binop) Value.op
type relop = (I32Op.relop, I64Op.relop, F32Op.relop, F64Op.relop) Value.op
type cvtop = (I32Op.cvtop, I64Op.cvtop, F32Op.cvtop, F64Op.cvtop) Value.op
type wideop = (I32Op.wideop, I64Op.wideop, F32Op.wideop, F64Op.wideop) Value.op
type extwideop = (I32Op.extwideop, I64Op.extwideop, F32Op.extwideop, F64Op.extwideop) Value.op

type vtestop = (V128Op.testop) Value.vecop
type vrelop = (V128Op.relop) Value.vecop
Expand Down Expand Up @@ -245,6 +257,8 @@ and instr' =
| Compare of relop (* numeric comparison *)
| Unary of unop (* unary numeric operator *)
| Binary of binop (* binary numeric operator *)
| Wide of wideop (* binop producing wide result *)
| Extwide of extwideop (* binop producing wide result, extending args *)
| Convert of cvtop (* conversion *)
| VecConst of vec (* constant *)
| VecTest of vtestop (* vector test *)
Expand Down
1 change: 1 addition & 0 deletions interpreter/syntax/free.ml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ let rec instr (e : instr) =
| ArrayInitElem (x, y) -> types (idx x) ++ elems (idx y)
| ExternConvert _ -> empty
| Const _ | Test _ | Compare _ | Unary _ | Binary _ | Convert _ -> empty
| Wide _ | Extwide _ -> empty
| VecConst _ | VecTest _
| VecUnary _ | VecBinary _ | VecTernary _ | VecCompare _
| VecConvert _ | VecShift _ | VecBitmask _
Expand Down
5 changes: 5 additions & 0 deletions interpreter/syntax/mnemonics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,8 @@ let f64x2_relaxed_min = VecBinary (V128 (F64x2 V128Op.RelaxedMin))
let f64x2_relaxed_max = VecBinary (V128 (F64x2 V128Op.RelaxedMax))
let i16x8_relaxed_dot_i8x16_i7x16_s = VecBinary (V128 (I16x8 V128Op.RelaxedDot))
let i32x4_relaxed_dot_i8x16_i7x16_add_s = VecTernary (V128 (I32x4 V128Op.RelaxedDotAddS))

let i64_add128 = Wide (I64 I64Op.Add128)
let i64_sub128 = Wide (I64 I64Op.Sub128)
let i64_mul_wide_s = Extwide (I64 (I64Op.MulWide S))
let i64_mul_wide_u = Extwide (I64 (I64Op.MulWide U))
Loading
Loading