Skip to content

Decide and document where stdarch intrinsics are allowed to diverge from asm behavior #2057

@RalfJung

Description

@RalfJung

stdarch has started using the simd_* LLVM intrinsics for many operations, which is great news for backends like cranelift and Miri. However, it also means we get extra optimizations that would otherwise not apply: LLVM will constant-fold these operations using its usual NaN rules, which means that the sign and payload of a NaN can be different from what would happen if the vendor intrinsic was implemented by an inline assembly block.

Which differences are acceptable?

  • I assume that we only want to tolerate differences in NaN payloads/signs, but not in whether a NaN is returned. (That was relevant for instance in Revert "Merge pull request #1871 from folkertdev/aarch64-float-min-max" #2052.)
  • On targets like ARM32 where subnormal numbers do not work properly for SIMD vectors, we might also see differences in the actual numerical results -- if LLVM constant-folds those operations, that will be done with proper subnormal support. I don't know if we currently use LLVM's portable SIMD representation here.

Currently, I don't think we properly document this anywhere? It doesn't seem too unlikely that someone might expect the vendor intrinsics to always behave exactly like the corresponding asm instructions, so we better clarify the expectations here. Would the module-level docs be a good place to document this?
Cc @rust-lang/libs-api

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions