Skip to content

Initial support for wide arithmetic#2697

Merged
sbc100 merged 1 commit into
mainfrom
wide_arith
Feb 26, 2026
Merged

Initial support for wide arithmetic#2697
sbc100 merged 1 commit into
mainfrom
wide_arith

Conversation

@sbc100

@sbc100 sbc100 commented Feb 25, 2026

Copy link
Copy Markdown
Member

No interpreter support here so not enough execute the tests yet.

See https://github.com/WebAssembly/wide-arithmetic/blob/main/proposals/wide-arithmetic/Overview.md

@sbc100 sbc100 requested a review from alexcrichton February 25, 2026 01:57
@sbc100

sbc100 commented Feb 25, 2026

Copy link
Copy Markdown
Member Author

@alexcrichton did the other places you implemented this end up being this invasive (i.e. all the new plumbing needed for quaternary opcodes), or is there some way to avoid it maybe?

@sbc100 sbc100 requested a review from keithw February 25, 2026 01:59
@sbc100 sbc100 force-pushed the wide_arith branch 2 times, most recently from 88157cf to 66c3580 Compare February 25, 2026 02:09
@alexcrichton

Copy link
Copy Markdown
Contributor

Skimming over the diff here this doesn't seem entirely out of the ordinary too me (although I'm not expert in wabt's internal architecture). I've found that wide-arithmetic can land anywhere on the spectrum of easy-to-add to requires-large-refactors depending on how the wasm AST was represented previously. Not all designs lends themselves well to the addition of a new shape of instruction (many fixed inputs, multiple fixed outputs) and I think wabt is landing on the middle-end of this spectrum given its AST design.

As for avoiding it, that would either require adding a new type to the wasm type system for wide-arithmetic (e.g. i128) or more domain-specific knowledge of wabt than I have. Personally I still feel that i128 is the wrong way to go in terms of effort-vs-gain tradeoff, however.

@sbc100

sbc100 commented Feb 25, 2026

Copy link
Copy Markdown
Member Author

Skimming over the diff here this doesn't seem entirely out of the ordinary too me (although I'm not expert in wabt's internal architecture). I've found that wide-arithmetic can land anywhere on the spectrum of easy-to-add to requires-large-refactors depending on how the wasm AST was represented previously. Not all designs lends themselves well to the addition of a new shape of instruction (many fixed inputs, multiple fixed outputs) and I think wabt is landing on the middle-end of this spectrum given its AST design.

As for avoiding it, that would either require adding a new type to the wasm type system for wide-arithmetic (e.g. i128) or more domain-specific knowledge of wabt than I have. Personally I still feel that i128 is the wrong way to go in terms of effort-vs-gain tradeoff, however.

Good to hear.

This change wasn't actually too complex I think, considering that it includes the first instruction to return more than once thing and the fist to take 4 arguments.

@zherczeg

Copy link
Copy Markdown
Collaborator

It is true that the double result can be challenging for some implementations. But from wabt perspective (mostly parsing) this seems not that hard. Is there a large gain for doing BigInt arithmetic with this method instead of 32x32->64?

@alexcrichton

Copy link
Copy Markdown
Contributor

There's some more info from the last update I gave to the CG (slides here) as well as the overview, but in general, yes, bigint arithmetic is more efficient with these instructions, measurably so relative to exclusively using 32-bit instructions.

@sbc100 sbc100 force-pushed the wide_arith branch 3 times, most recently from b42d714 to 8c229b3 Compare February 25, 2026 19:09
@sbc100

sbc100 commented Feb 25, 2026

Copy link
Copy Markdown
Member Author

CC @ryandiazG

@sbc100

sbc100 commented Feb 26, 2026

Copy link
Copy Markdown
Member Author

@dschuff PTAL, I'd like to land this as-is, without the interpreter support initially.

@dschuff dschuff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops sorry I made a comment and didn't submit.

Comment thread src/ir-util.cc
return {2, 1};

case ExprType::Quaternary:
return {4, 2};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this is technically a little weird since there could eventually be one that takes 4 and returns 1, and that would be the "real" Quaternary (making this one "Quaternery-binary" or something like that? Not sure if it matters right now though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for now Quaternary means exactly the signature we use for these new op-codes. They take 4 inputs and produce 2 outputs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as long as if that happens we don't mind either just renaming this one or creating the new one with a slightly weird name, then this is fine with me.

@sbc100 sbc100 enabled auto-merge (squash) February 26, 2026 23:35
@sbc100 sbc100 disabled auto-merge February 26, 2026 23:52
@sbc100 sbc100 merged commit 9a226dc into main Feb 26, 2026
17 checks passed
@sbc100 sbc100 deleted the wide_arith branch February 26, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants