Skip to content

Conversation

@0f-0b
Copy link

@0f-0b 0f-0b commented Nov 23, 2025

This change eliminates the two constants (the abs mask and infinity), reducing code size at hopefully no performance cost. It works because x - x is always +0 when x is finite, and is NaN if and only if x is infinite or NaN.

Generated aarch64 assembly for f32 compared to the current implementation:

is_finite:
    fsub  s0, s0, s0
    fcmp  s0, s0
    cset  w0, vc
    ret

is_finite_std:
    fmov  w9, s0
    mov   w8, #0x7f800000
    and   w9, w9, #0x7fffffff
    cmp   w9, w8
    cset  w0, lt
    ret

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 23, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 23, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants