Skip to content

Reducing the definitions of the floor, ceil, and trunc methods to mitigate invalidation #335

Description

@kimikage

At least as of julia v1.0, floor(x) has fallen back to round(x, RoundDown).
Starting with julia v0.11, floor(T, x) has also been made to fall back to round(T, x, RoundDown).(cf. JuliaLang/julia#45598)

Therefore, it should be sufficient to define only round(x, ::RoundingMode) and round(T, x, ::RoundingMode) in FPN.
Conversely, starting with Julia v0.11, defining methods such as floor(T, x) may carry a higher risk of invalidation.
(As efforts related to TTFX within the Julia ecosystem are also advancing, it is unclear what impact this will have on actual performance.)

Of course, invalidation triggered by the 2-/3-arg round is, in principle, unavoidable.
However, I think it can be effective if the invalidation results from the casual (type-instable) use of functions like floor.

Since rounding functions like floor are expected to be inlined when there is no risk of overflow/underflow (e.g., ceil(typemax(Q0f7))), I don't think there will be much of a performance penalty.
It’s fragile against piracy and future changes to Base implementation, but I’m sure someone will notice and fix it.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions