Skip to content

Fix/implement checked_{add,sub,mul} and saturating_{add,sub} (using SPIR-V instructions were possible).#561

Draft
eddyb wants to merge 2 commits intomainfrom
eddyb/checked-saturating-spv
Draft

Fix/implement checked_{add,sub,mul} and saturating_{add,sub} (using SPIR-V instructions were possible).#561
eddyb wants to merge 2 commits intomainfrom
eddyb/checked-saturating-spv

Conversation

@eddyb
Copy link
Copy Markdown
Member

@eddyb eddyb commented Apr 13, 2026

After this PR:

  • signed checked_{add,sub} still have no direct SPIR-V equivalents
    • our custom implementation used to have bugs around e.g. 0 + 0 / 0 - 0
      (fixed in this PR, and verified via Alive2: broken vs correct)
  • unsigned checked_{add,sub} and signed/unsigned checked_mul map to SPIR-V instructions
    (OpIAddCarry, OpISubBorrow, OpSMulExtended/OpUMulExtended)
  • saturating_{add,sub} use an Intel extension instead of plainly erroring
    (OpIAddSatINTEL/OpISubSatINTEL)
    • in time, we might choose to emulate these instructions (later in the pipeline)

TODO: add tests for the edge cases, consider the need for OpUAddSatINTEL/OpUSubSatINTEL.

@nazar-pc
Copy link
Copy Markdown
Contributor

Could you also comment on #403? Seems directly applicable here.

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.

2 participants