Skip to content

Add AVX10.2 Intrinsics - #2045

Open
sayantn wants to merge 14 commits into
rust-lang:mainfrom
sayantn:avx10
Open

sayantn wants to merge 14 commits into
rust-lang:mainfrom
sayantn:avx10

Conversation

@sayantn

@sayantn sayantn commented Mar 1, 2026 •

Copy link
Copy Markdown
Contributor

Tracking Issue: rust-lang/rust#153417

  • zero-extending partial moves
  • sum of absolute differences
  • dot product
  • saturating truncating float->integer conversions
  • minmax
  • saturating float->int8 conversions
  • packing float32->float16 conversions
  • float16->float8 conversions with bias
  • float16->float8 conversions
  • float8->float16 conversions
  • SM4 intrinsics
  • Read-shared move intrinsics
  • bfloat16 instructions
    • bfloat16 minmax
    • saturating bfloat16->int8 conversions

AVX10_V1_AUX intrinsics

These instructions are supported in a subset of AVX10.2, but neither GCC nor LLVM supports this feature yet.
TODO: Modify the #[target_feature] attribute once LLVM starts supporting this.

  • integer dot product instructions
  • packing float32->float16 conversions
  • float16->float8 conversions with bias
  • float16->float8 conversions
  • float8->float16 conversions

edit: it seems like LLVM does not want to support them, they've added avx10_v2_aux without avx10_v1_aux.

BF16 Operations

A few BF16 intrinsics (add, sub, mul, div, sqrt, cmp and FMA) require support from core::intrinsics::simd. Since the f16b type is not supported in cg_llvm/intrinsic.rs yet, we can't do them now

Extra Clang Intrinsics

Clang actually supports quite a few more bf16 intrinsics (e.g. set, load, store etc). I have currently not implemented them, I have just implemented the GCC set. Once these are in the Intrinsics Guide, we can modify as needed.

intrinsic-test Integration

I'd love to see these tested via intrinsic-test, but the problem is these are not in the Intrinsics Guide yet. I'll see if I can somehow rig up intrinsic-test to test these (in a future PR).

#[rustc_legacy_const_generics]

I have not added this to any of the intrinsics. @Amanieu let me know if I should add them, or should we stop using this for new ISAs

LLVM Bugs

@sayantn

sayantn commented Mar 7, 2026

Copy link
Copy Markdown
Contributor Author

@Amanieu @folkertdev what do you think, can/should this be merged now, considering the LLVM bugs, or should we wait until the fixes merge?

@folkertdev

Copy link
Copy Markdown
Contributor

I don't have strong feelings about it. I'm assuming this won't really see practical usage? On the other hand we might be adding some test coverage to potentially catch regressions next LLVM upgrade.

So I guess I'm fine with merging, but I don't think it matters much really.

@rustbot

This comment has been minimized.

@sayantn
sayantn force-pushed the avx10 branch 3 times, most recently from f9ffb64 to 778deff Compare May 26, 2026 06:33
@rustbot

This comment has been minimized.

@sayantn
sayantn marked this pull request as ready for review November 18, 2026 23:23
@rustbot

rustbot commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

r? @Amanieu

rustbot has assigned @Amanieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Amanieu, @adamgemmell, @davidtwco, @folkertdev
  • @Amanieu, @adamgemmell, @davidtwco, @folkertdev expanded to Amanieu, adamgemmell, davidtwco, folkertdev
  • Random selection from Amanieu, adamgemmell, davidtwco, folkertdev

Comment thread crates/core_arch/src/x86_64/movrs.rs Outdated
#[unstable(feature = "stdarch_x86_avx10_2", issue = "153417")]
#[cfg_attr(all(test, not(target_vendor = "apple")), assert_instr(vmovrsb))]
pub unsafe fn _mm_maskz_loadrs_epi8(k: __mmask16, p: *const i8) -> __m128i {
_mm_maskz_mov_epi8(k, _mm_loadrs_epi8(p))

@Amanieu Amanieu Nov 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is incorrect: we shouldn't be loading from masked-off elements. This matters when the masked off elements are past the end of a page boundary.

View changes since the review

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.

LLVM doesn't provide masked movrs intrinsics. So I will just remove the masked versions for now, and file an LLVM issue (since clang also does the same thing currently)

Comment thread crates/core_arch/src/x86/avx10_2.rs Resolved
Comment on lines +8374 to +8375
)]
pub fn _mm512_maskz_ipcvtts_roundph_epi8<const SAE: i32>

@Amanieu Amanieu Nov 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need static bounds-checks for these? They are both just aliases for i32.

View changes since the review

@sayantn sayantn Nov 25, 2026 •

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.

sorry I am not getting what you want to say. bounds-checks for what?

edit: oh sorry github ui is showing your comment on a different line. I think we should have a bounds-check for these, since llvm will probably panic if the intrinsic is invoked with out-of-bounds values.

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 spotted that we use uimm_bits(4) for norm in avx512f, even though the doc says that the normalization is determined by imm8[1:0], and the sign control by imm8[3:2]. I used uimm_bits(2) here. Can we even fix the avx512f ones anymore?

This branch has not been deployed

No deployments
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.

4 participants