Skip to content

Add widening integer ops - #415

Merged
Shnatsel merged 5 commits into
linebender:mainfrom
Shnatsel:widening-ops
Oct 20, 2026
Merged

Shnatsel merged 5 commits into
linebender:mainfrom
Shnatsel:widening-ops

Conversation

@Shnatsel

@Shnatsel Shnatsel commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Adds a new SimdIntWiden trait for widening ops on integers, requiring both SimdInt and SimdWiden.

Adds three ops on that trait:

  • Widening multiplication, with the name cribbed from std
  • Widening addition, name made up
  • Pairwise dot product, an oddly specific but widely implemented (even in WASM!) op that I need a portable abstraction for to port the jpeg-encoder crate to Fearless SIMD.

Probably best reviewed commit by commit.

@Shnatsel

Copy link
Copy Markdown
Contributor Author

This can be seen in action in https://github.com/Shnatsel/jpeg-encoder/tree/fearless-simd

@Shnatsel Shnatsel changed the title Add widening ops Add widening integer ops Oct 18, 2026

@LaurenzV LaurenzV 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.

API looks good to me! Just hope there are no hidden traps regarding breaking changes. 😄

],
),
];
for (a, b) in cases {

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.

Up to you, I personally think it would be better if the test oracle consists of hardcoded numbers instead of just "replaying" with scalar Rust and then asserting the results are the same. Same for the widening add/mul tests.

But fine from my side if you prefer it this way!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I generally follow the style you describe, but in this particular case the operation is so arcane that it would be difficult for me to debug if something broke with just hardcoded expected values. I would question whether the expected data was generated correctly, how it was generated, etc. I think in this particular case a scalar reference is easier to follow.

Comment thread fearless_simd_tests/tests/harness/ops/widening_mul.rs Outdated
/// A native-width SIMD vector of [`u8`]s.
type u8s: SimdInt<Self, Element = u8, Block = u8x16<Self>, Mask = Self::mask8s, ByteVector = Self::u8s>
+ SimdWiden<Self, Widened = Self::u16s>;
+ SimdIntWiden<Self, Widened = Self::u16s>;

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.

This is not a breaking change only because the trait is sealed, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct.

I also hope that cargo-semver-checks would scream at us if this weren't the case, but I haven't verified.

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.

In theory if someone imported everything from this module, their code could stop compiling if they have other widening_mul etc. methods in-scope, right? 🤔 Not sure if that's considered a breaking change though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Concrete imports take precedence over wildcard imports. So it would still work unless they used wildcard imports for both.

Cargo explicitly calls this out as a minor change, despite the potential glob collisions: https://doc.rust-lang.org/cargo/reference/semver.html#item-new

@Dr-Emann

Copy link
Copy Markdown
Contributor

Related to #382

The pairwise single vector version seems more fundamental than elementwise widening addition, though, as far as I can tell.

@Shnatsel
Shnatsel added this pull request to the merge queue Oct 20, 2026
Merged via the queue into linebender:main with commit 92bb488 Oct 20, 2026
23 checks passed
@Shnatsel
Shnatsel deleted the widening-ops branch October 20, 2026 07:56
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