-
Notifications
You must be signed in to change notification settings - Fork 58
Testable Models for SIMD Intrinsics #423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thank you very much! I am yet to read the full PR, but can you please explain how the testing is actually done (as also required by the challenge spec)? I see there is a |
Thanks for the quick comments. We will do another pass on this PR in the next few days. |
* Provided more detailed description for how to model and test intrinsics * Restored static asserts which were in the upstream code * Switched the use of u64 back to u32 to make it closer to upstream * Defined functions like `transpose` to reduce visual diffs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the documentation updates, this is really helpful. Some more comments below, but also one larger request: please include a CI job so that those tests that you created are actually run in our CI.
* Add ci job for simd models tests, with logging of rng seed. * Fix testable simd models CI job. * Use LAzyLock instead of lazy_static. * edited readme * revert to working neon intrinsics --------- Co-authored-by: karthikbhargavan <[email protected]>
@karthikbhargavan could you solve the compilation failures to pass CI tests? |
Solution to challenge 15, resolves #173.
This PR provides testable models for
core::arch
intrinsics, including abstractions to streamline the process of implementing these intrinsics and their tests.Currently there are 384 x86 intrinsics modelled, and 181 aarch64 intrinsics modelled.
The methodology for writing the models is decribed in
testable-simd-models/README.md
.First, we model the SIMD types as bitvectors that can be converted to and from arrays of machine integers.
Then, we model the raw operations on these types as functions over bitvectors, while keeping as much code as possible unchanged from the Rust code in
rust-lang/stdarch/crates/core_arch
.Finally, we write tests (using a generic macro) to compare the behaviour of our models with the corresponding intrinsic implementations in Rust core.
Interestingly, in the process of modeling these intrinsivcs, we found bugs in the implementation of two intrinsics,
_mm256_bsrli_epi128
and_mm512_bsrli_epi128
. These bugs were fixed by our PR in the 2025-06-30 version of the library. In a small way, this shows off the impact of writing testable models of the SIMD intrinsics.The model of intrinsics defined here is also used as the basis of formal proofs of Rust programs that use intrinsics. In particular, the
libcrux
cryptographic library uses these models in its proofs of the post-quantum cryptographic algorithms.As next steps, we intend to extend these testable models to a larger subset of core (beyond SIMD) and then translate these Rust models to models in F*, Rocq, and Lean, to enable proofs using our models in these backends. This work is being done as part of the hax project.
The work in this PR was primarily done by Aniket Mishra, under the supervision of Karthikeyan Bhargavan and Maxime Buyse at Cryspen.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.