Skip to content

Math operations for f16 incorrectly implemented #1622

Open

Description

@bjorn3

libm has no such intrinsics as logf16 and roundf16. Discovered in rust-lang/rust#148206 (comment).

Activity

  1. tgross35 commented on Jan 9, 2026

    @tgross35
    Member

    Those are real functions in C23 and are available with some libms, e.g. https://github.com/llvm/llvm-project/blob/ddb706bbb04a460fb2741268039c69787dc8b2fc/libc/src/math/roundf16.h#L17. I think LLVM will eventually start using them in some lowerings, there are legit usecases (e.g. fmaf16 currently lowers to extend f64 -> fmaf64 -> trunc f16 to get the right precision, but fmaf16 is way cheaper if you don't have hardware f64). So IMO cranelift doesn't need to change anything here, we can just add wrappers in libm that forward to the f32 versions.

  2. bjorn3 commented on Jan 9, 2026

    @bjorn3
    MemberAuthor

    Compiler-builtins doesn't have logf16 at least.

  3. tgross35 commented on Jan 9, 2026

    @tgross35
    Member

    Right, currently - that's why I said we we can just add wrappers there.

  4. tgross35 commented on Jan 10, 2026

    @tgross35
    Member

    Actually, even easier; we can just add fallbacks to the intrinsics that go via the f32 implementations.

  5. tgross35 commented on Jan 10, 2026

    @tgross35
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions