Skip to content

Fix unsigned 64-bit saturating multiplication overflow - #3950

Merged
aneshlya merged 1 commit into
ispc:mainfrom
vera-rubin:fix/uint64-saturating-mul
Oct 15, 2026
Merged

aneshlya merged 1 commit into
ispc:mainfrom
vera-rubin:fix/uint64-saturating-mul

Conversation

@vera-rubin

Copy link
Copy Markdown
Contributor

Description

Both uniform and varying uint64 overloads return 0xffffffff00000000 for saturating_mul(0x8000000000000000, 2). The documented saturation requires UINT64_MAX (0xffffffffffffffff).

uniform uint64 a = 0x8000000000000000, b = 2;
uniform uint64 result = saturating_mul(a, b);

We compute the cross products in 64 bits and saturate before shifting when they exceed UINT32_MAX. We've added exact integer comparisons covering overflow, nonoverflowing boundaries, both operand orders and mixed varying lanes.

The reproducer and regression pass after the fix, and the existing saturation tests still pass.

ISPC 1.33.0dev at 4ab7487c09f226d09060d51a964c2575c6a773f8

# from the checkout with the built compiler on PATH:
python3 scripts/run_tests.py --target=sse4-i32x4 --opt=O2 -j3 --non-interactive tests/func-tests/pmulus-i64-overflow.ispc

Related Issue

  • Linked to relevant issue(s) (N/A: this PR reports the bug)

Checklist

  • Code formatting checked
  • One commit per logical change
  • Compiler lit tests (N/A)
  • New stdlib functional regression
  • Documentation update (N/A)

— ChipLab

@vera-rubin
vera-rubin requested a review from aneshlya as a code owner October 15, 2026 01:11
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for opening your first pull request, and welcome to ISPC! 🎉 A maintainer will review your changes soon.
To help the review go smoothly, please make sure you've read CONTRIBUTING, formatted any C/C++ changes with clang-format, and that the test suite passes. We appreciate your contribution!

@dbabokin

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T01:24:43.141351Z e9b55b7 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: e9b55b7d42

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@aneshlya aneshlya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good! Thanks for using ChipLab with ispc!

@aneshlya
aneshlya merged commit 1de0cbb into ispc:main Oct 15, 2026
158 checks passed
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.

saturating_mul for uint64 returns 0xffffffff00000000 instead of UINT64_MAX on overflow

3 participants