Skip to content

loongarch: Use LLVM intrinsics for vdiv/vmod - #2229

Open
heiher wants to merge 1 commit into
rust-lang:mainfrom
heiher:revert-vidv-vmod
Open

heiher wants to merge 1 commit into
rust-lang:mainfrom
heiher:revert-vidv-vmod

Conversation

@heiher

@heiher heiher commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Miri reports UB on division by zero with the LSX vdiv/vmod intrinsics when implemented via the portable simd_div/simd_rem helpers. 1

Per clarification from the LoongArch ISA developers, the hardware defines that vdiv/vmod return 0 when the divisor is zero (this will be documented in the SIMD reference). This differs from the earlier assumption in PR #2078, so the portable helpers are not a correct match.

Switch back to the corresponding LLVM intrinsics so the Rust wrappers preserve the defined ISA behavior.

Footnotes

  1. https://github.com/rust-lang/stdarch/pull/2221#issuecomment-5688403926

@rustbot

rustbot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
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, @sayantn
  • @Amanieu, @adamgemmell, @davidtwco, @folkertdev, @sayantn expanded to Amanieu, adamgemmell, davidtwco, folkertdev, sayantn
  • Random selection from Amanieu, adamgemmell, davidtwco, folkertdev, sayantn

Miri reports UB on division by zero with the LSX vdiv/vmod
intrinsics when implemented via the portable simd_div/simd_rem
helpers. [^1]

Per clarification from the LoongArch ISA developers, the hardware
defines that vdiv/vmod return 0 when the divisor is zero (this
will be documented in the SIMD reference). This differs from the
earlier assumption in PR rust-lang#2078, so the portable helpers are not
a correct match.

Switch back to the corresponding LLVM intrinsics so the Rust
wrappers preserve the defined ISA behavior.

[^1]: rust-lang#2221 (comment)

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.

3 participants