Skip to content

Add saturating_add() and saturating_sub() to integers - #352

Merged
Shnatsel merged 10 commits into
linebender:mainfrom
Shnatsel:saturating-add
Sep 3, 2026
Merged

Add saturating_add() and saturating_sub() to integers#352
Shnatsel merged 10 commits into
linebender:mainfrom
Shnatsel:saturating-add

Conversation

@Shnatsel

@Shnatsel Shnatsel commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

NEON has all these ops natively. x86 has u8/i8/u16/i16, but 32-bit and 64-bit element widths need to be emulated; that emulation is the source of most of the complexity.

@Shnatsel

Copy link
Copy Markdown
Contributor Author

LLVM 23 pessimizes srai(a, 31) ^ i32::MAX and turns it into two constant broadcasts and a blend. Workarounds are available but I'm not going to special-case i32 further, the code is complicated enough.

Comment thread fearless_simd_tests/tests/harness/ops/saturating_add.rs
Comment thread fearless_simd_gen/src/ops.rs Outdated
# Conflicts:
#	fearless_simd_gen/src/mk_x86.rs
@Shnatsel
Shnatsel enabled auto-merge September 3, 2026 20:19
@Shnatsel
Shnatsel added this pull request to the merge queue Sep 3, 2026
Merged via the queue into linebender:main with commit 21359cc Sep 3, 2026
22 checks passed
@Shnatsel
Shnatsel deleted the saturating-add branch September 3, 2026 20:33
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