Skip to content

Add signed/unsigned casting - #435

Merged
Shnatsel merged 4 commits into
linebender:mainfrom
RunDevelopment:int-signed-unsigned
Nov 24, 2026
Merged

Shnatsel merged 4 commits into
linebender:mainfrom
RunDevelopment:int-signed-unsigned

Conversation

@RunDevelopment

Copy link
Copy Markdown
Contributor

This PR adds SimdInt::{Signed, Unsigned, cast_signed, cast_unsigned} to allow users to cast the signedness of a vector without needing to name the target vector type. Similar to #420.

I also added SimdInt::unsigned_abs() because it's trivial to implement using the new APIs.


I'm thinking of this PR as prep for abs_diff, but I'm not sure if this is the right approach long term. IMO, std::simd's traits SimdInt and SimdUint are much more elegant, but it's a little late for that now. Except if we add traits like trait SimdSigned: SimdInt and trait SimdUnsigned: SimdInt and move all sign-specific operations there.

Ideas very welcome.

@Shnatsel Shnatsel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the direction. This doesn't conflict with #439 as far as I can tell.

Personally I find the SimdInt/SimdUint split in std::simd cumbersome. It makes docs harder to navigate and makes abstracting over signedness much more difficult.

I think the generic bounds could be strengthened, I've left inline comments on the relevant code.

Please add tests that pin down behavior in edge cases so we don't break it accidentally in the future.

@RunDevelopment

Copy link
Copy Markdown
Contributor Author

Done.

I added a few more bounds than you suggested. For example, I strengthened the bounds around masks. This should allow users to share masks between signed and unsigned vectors without issue. I also strengthened the bounds of SimdFloat::Bits a tiny bit.

@Shnatsel Shnatsel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good now. Thank you!

@LaurenzV

Copy link
Copy Markdown
Collaborator

@Shnatsel Do you want to merge? I might cut a new release today or tomorrow.

@Shnatsel
Shnatsel added this pull request to the merge queue Nov 24, 2026
@Shnatsel

Copy link
Copy Markdown
Contributor

SGTM. After you publish I might write a blog post for linebender.org about the progress since 1.0

Merged via the queue into linebender:main with commit 9c00a4c Nov 24, 2026
23 checks passed
@RunDevelopment
RunDevelopment deleted the int-signed-unsigned branch November 24, 2026 20:07
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.

3 participants