You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/methods.jl
+4-3Lines changed: 4 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -57,8 +57,7 @@ for RM in (RoundingMode{:Up}, RoundingMode{:Down}, RoundingMode{:ToZero}, Roundi
57
57
end
58
58
59
59
Base.:-(x::T) where T<:EmulatedInteger=-x[] % T
60
-
# `abs` on an unsigned is the identity; `% T` would add a useless `& maxvalue` the compiler can't elide. Signed `abs` lowers to the storage intrinsic + modular re-clean.
61
-
Base.abs(x::EmulatedUnsigned) = x
60
+
# Signed `abs` lowers to the storage intrinsic + modular re-clean. Unsigned needs no method: `EmulatedUnsigned <: Unsigned`, so `Base.abs(::Unsigned)` (the identity) already applies; adding one would only supersede it and widen invalidations.
62
61
Base.abs(x::T) where T<:EmulatedSigned=abs(x[]) % T
63
62
64
63
# Storage-level `-x[]` already produces the bit pattern of the flipped sign value (no overflow for non-`typemin` inputs and the same wraparound as 2's complement for `typemin`); the `% T` cast re-cleans the wasted bits.
@@ -120,6 +119,7 @@ end
120
119
# `minvalue`/`maxvalue` return literals of the storage type, so `reinterpret` suffices.
121
120
Base.typemin(::Type{T}) where T<:EmulatedInteger=reinterpret(T, minvalue(T))
122
121
Base.typemax(::Type{T}) where T<:EmulatedInteger=reinterpret(T, maxvalue(T))
122
+
# Anchor the multiplicative identity on `oneunit` rather than `one`. Both break the `one`/`oneunit` mutual recursion, but `oneunit` has far fewer precompiled callers in Base's numeric code, so it invalidates a much smaller backedge set.
123
123
Base.oneunit(::Type{T}) where T<:EmulatedInteger=reinterpret(T, T |> storagetypeof |> one)
124
124
125
125
# Storage has `wastedbits(T)` extra zero (unsigned) or sign-extension (signed) bits at the top; subtract them to get the logical leading-zero count.
@@ -159,7 +159,8 @@ for B in Union{Base.BitInteger, Base.IEEEFloat} |> Base.uniontypes .|> Symbol
159
159
@eval Base.$B(x::EmulatedInteger) = x[] |>$B
160
160
end
161
161
162
-
for f in (:<, :<=, :>, :>=)
162
+
# Only `<` and `<=` are defined; Base derives `>`/`>=` from them (`>(x, y) = y < x`). Defining `>`/`>=` here would supersede their universal `Any` fallbacks and invalidate a large amount of precompiled Base code for no behavioral gain.
0 commit comments