Skip to content

Conversation

@folkertdev
Copy link
Contributor

This intrinsic is useful for the adler32 checksum algorithm.

The test attempts to hit a bunch of overflow and truncation cases, and I've validated it on real hardware.

@rustbot
Copy link
Collaborator

rustbot commented Dec 18, 2025

Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two.
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Dec 18, 2025
Comment on lines 1238 to 1241
let intermediate = i32::from(i16::from(a1).wrapping_mul(i16::from(b1 as i8)))
.wrapping_add(i32::from(i16::from(a2).wrapping_mul(i16::from(b2 as i8))))
.wrapping_add(i32::from(i16::from(a3).wrapping_mul(i16::from(b3 as i8))))
.wrapping_add(i32::from(i16::from(a4).wrapping_mul(i16::from(b4 as i8))));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the as i8 is intentional here so that sign extension is used. So try_from would not work here, how does miri generally handle this?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know the type of everything involved here, but there is cast_signed/cast_unsigned -- does that suffice?

Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I am slightly concerned about slowly growing a huge avx512 file that nobody has an overview of any more.^^ But as long as there's a clear motivation in the form of a core ecosystem crate, I hope that will naturally limit the scope of what we have to support.

View changes since this review

/// <https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_dpbusd_epi32>
/// <https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_dpbusd_epi32>
/// <https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_dpbusd_epi32>
fn vpdpbusd<'tcx>(
Copy link
Member

Choose a reason for hiding this comment

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

If this is only used in avx512, please move the function to that file.

interp_ok(())
}

/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in a with corresponding signed
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in a with corresponding signed
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in `a` with corresponding signed

same for all the other references to variable names in the doc comment

Comment on lines +1238 to +1242
let intermediate = i32::from(i16::from(a1).wrapping_mul(i16::from(b1.cast_signed())))
.wrapping_add(i32::from(i16::from(a2).wrapping_mul(i16::from(b2.cast_signed()))))
.wrapping_add(i32::from(i16::from(a3).wrapping_mul(i16::from(b3.cast_signed()))))
.wrapping_add(i32::from(i16::from(a4).wrapping_mul(i16::from(b4.cast_signed()))));

Copy link
Member

Choose a reason for hiding this comment

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

We should find a way to make this more readable...
As a start, why are you mixing i16 and i32? And why wrapping_mul? multiplying two i8 as an i16 cannot overflow, right? Same for add. If things can never overflow, please use the strict operations.

Also, I think it would make sense to let-bind the 4 multiplications. Maybe that could even be written in a loop, e.g. via from_fn?

}

#[target_feature(enable = "avx512vnni")]
unsafe fn test_avx512vnni() {
Copy link
Member

Choose a reason for hiding this comment

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

You mentioned that this is aiming to hit a bunch of overflow and truncation cases. Please add comments pointing that out.

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Dec 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 20, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: Waiting for the PR author to address review comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants