Skip to content

x86: Add missing instructions for ML-KEM compressions#349

Merged
jargh merged 7 commits intoawslabs:mainfrom
mkannwischer:mlkem-compression-instructions
Feb 27, 2026
Merged

x86: Add missing instructions for ML-KEM compressions#349
jargh merged 7 commits intoawslabs:mainfrom
mkannwischer:mlkem-compression-instructions

Conversation

@mkannwischer
Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

This PR adds 7 additional missing AVX2 instructions that we require for the ML-KEM compressions. With those @hanno-becker was able to prove correctness of the 4 compression functions for d=4,5,10,11 (see pq-code-package/mlkem-native#1545). The 5 missing instructions for the 4 decompression functions proven in pq-code-package/mlkem-native#1543 were already added as a part of #346.

I ran the sematests for all instructions for a while, that plus the completed proofs give us some confidence that the instruction models are actually correct, but please take a look.

This completes the proofs of the arithmetic x86 backend of ML-KEM. 🎉🥳

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@mkannwischer mkannwischer marked this pull request as ready for review February 12, 2026 15:29
@dkostic dkostic self-requested a review February 23, 2026 17:10
@jargh jargh self-requested a review February 24, 2026 00:38
@mkannwischer mkannwischer force-pushed the mlkem-compression-instructions branch from 12d4967 to be978fc Compare February 25, 2026 02:28
@mkannwischer
Copy link
Copy Markdown
Contributor Author

Thanks @jargh, @dkostic for the review of #346.
I have rebased this PR on top of main just now.
Please take a look.

Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
@mkannwischer mkannwischer force-pushed the mlkem-compression-instructions branch from be978fc to b2c883e Compare February 27, 2026 03:51
Copy link
Copy Markdown
Contributor

@jargh jargh left a comment

Choose a reason for hiding this comment

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

All this looks great and all my tests are fine. It would be nice if you could also add a few more simulator test cases to sanity-check (1) memory versions of the new instructions where applicable, and (2) oversized immediates to check masking or otherwise where applicable. This patch gives a few examples that could be added. I don't consider this critical since I've already done so locally and confirmed they all seem fine, so if you are in a rush I can just approve anyway :-)

349.patch

@mkannwischer
Copy link
Copy Markdown
Contributor Author

All this looks great and all my tests are fine. It would be nice if you could also add a few more simulator test cases to sanity-check (1) memory versions of the new instructions where applicable, and (2) oversized immediates to check masking or otherwise where applicable. This patch gives a few examples that could be added. I don't consider this critical since I've already done so locally and confirmed they all seem fine, so if you are in a rush I can just approve anyway :-)

349.patch

Thanks for the review! I'd appreciate if we can get it merged first and I'll add the additional tests in a follow-up PR later today. This way we can move forward in mlkem-native already.

@jargh jargh self-assigned this Feb 27, 2026
Copy link
Copy Markdown
Contributor

@jargh jargh left a comment

Choose a reason for hiding this comment

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

OK, will now approve and merge

@jargh jargh merged commit 628a9cc into awslabs:main Feb 27, 2026
11 checks passed
mkannwischer added a commit to pq-code-package/mlkem-native that referenced this pull request Feb 27, 2026
The vpmulhrsw and compression instruction support has been merged
upstream (awslabs/s2n-bignum#349). Switch back from the fork to
upstream awslabs/s2n-bignum@628a9cc.

Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
mkannwischer added a commit to mkannwischer/s2n-bignum that referenced this pull request Mar 16, 2026
Add simulator test patterns for VPSRLDQ, VPEXTRW, VPADDQ, VPACKUSWB,
VPBLENDVB, VPMADDUBSW, and VPMADDWD, covering both register and memory
operand variants.

Proposed by @jargh in awslabs#349

Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
@jargh jargh mentioned this pull request Mar 17, 2026
mkannwischer added a commit to mkannwischer/s2n-bignum that referenced this pull request Mar 24, 2026
Add simulator test patterns for VPSRLDQ, VPEXTRW, VPADDQ, VPACKUSWB,
VPBLENDVB, VPMADDUBSW, and VPMADDWD, covering both register and memory
operand variants.

Proposed by @jargh in awslabs#349

Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
jargh pushed a commit that referenced this pull request Mar 24, 2026
Add simulator test patterns for VPSRLDQ, VPEXTRW, VPADDQ, VPACKUSWB,
VPBLENDVB, VPMADDUBSW, and VPMADDWD, covering both register and memory
operand variants.

Proposed by @jargh in #349

Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
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