Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-1.9: Backports for julia 1.9.0-alpha2 / 1.9.0-beta1 #47602

Merged
merged 57 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
05c8f3b
Limit initial OpenBLAS thread count (#46844)
staticfloat Nov 15, 2022
9606388
fix #46778, precompile() for abstract but compileable signatures (#47…
JeffBezanson Nov 16, 2022
0e17295
fix #47410, syntax error with anonfn inside `elseif` and short-circui…
JeffBezanson Nov 16, 2022
9dfd76b
ensure bindings handle write barriers for ty and globalref (#47580)
vtjnash Nov 16, 2022
d85e9ac
Turn on Intel jitevents by default on Linux (#47586)
vchuravy Nov 20, 2022
b5d6b03
Doc: The default sorting alg. is stable from 1.9 (#47579)
petvana Nov 21, 2022
3bc94a9
update MPFR (#47659)
simonbyrne Nov 21, 2022
f8f0c63
Add compat note for `sortperm(x; dims)` (#47657)
mcabbott Nov 22, 2022
382661c
build: add get-lld target (#47589)
petvana Nov 23, 2022
0f271d7
Print the detailed type on heap snapshot (#47503)
gbaraldi Nov 23, 2022
c615a49
Remove typeinfer lock altogether (#46825)
pchintalapudi Nov 23, 2022
3b414c6
Fix regression in generic_bitcast with Union{} arguments. (#47605)
maleadt Nov 24, 2022
aba112c
Filesystem: `rm(; recursive=true)` should ignore `UV_EACCES` (#47668)
staticfloat Nov 24, 2022
24505fc
Fix overflow in pow5 (#47511)
LilithHafner Nov 26, 2022
6fb45be
Fix GCExt test (#47699)
vchuravy Nov 27, 2022
0865ae0
Fix REPL keybinding CTRL-Q for stdlib methods (#47637)
rashidrafeek Nov 28, 2022
cfbb86a
fix 5-arg `mul!` for vectors of vectors (#47665)
ranocha Nov 28, 2022
93587d7
Add support for "package extensions" to code loading (#47695)
KristofferC Dec 7, 2022
dc1369e
🤖 Bump the Pkg stdlib from ed6a5497e to 5d8b9ddb8 (#47828)
DilumAluthgeBot Dec 7, 2022
9b9a703
Fix and simplify inference timing logic (#47711)
pchintalapudi Nov 26, 2022
1b85c1f
Fix nth_methtable tparam of -1 when n==0 (#47666)
apaz-cli Nov 28, 2022
81f8582
Fix generator-invocation legality check for varargs generators (#47739)
Keno Nov 29, 2022
9da50d2
Bump libuv. (#47707)
maleadt Nov 30, 2022
fcf02e8
Provider cycleclock() for 32bit ARM targets (#47358)
fingolfin Nov 30, 2022
628c953
strengthen setglobal to default to release-consume ordering (#47742)
vtjnash Nov 30, 2022
dfec160
fix unescaping in `global` expressions (#47719)
simeonschaub Dec 1, 2022
d8cbffd
Refactor and document sorting dispatch (#47383)
LilithHafner Dec 3, 2022
930314e
Comment out test in subtype that causes hang due to StackOverflow(#47…
vchuravy Dec 3, 2022
01ae8b7
Prioritize build_dir for generated headers (#47783)
vchuravy Dec 4, 2022
dba443d
Set `OPENBLAS_NUM_THREADS=1` on local Distributed workers (#47803)
staticfloat Dec 5, 2022
ce7a372
Add native julia fmod (#47501)
gbaraldi Dec 6, 2022
712a123
Fix libjulia install name and libjulia-internal rpath on OS X (#47220)
jonathan-conder-sm Dec 7, 2022
d561447
Replace the `.ji` serialization with sysimage format
timholy Feb 7, 2022
f8a5cd6
Allow re-initialization and caching of foreign types (#47407)
vchuravy Nov 27, 2022
12a4863
Fix physical_memory exports. (#47859)
maleadt Dec 10, 2022
2866e26
Fix missing GC root in Symbol construction (#47865)
Keno Dec 11, 2022
0b845b1
TOML: print: handle mixed vector of dicts and non-dicts (#47876)
fonsp Dec 12, 2022
3d80653
Fixups for #47383 (fixes `runbenchmarks("sort")`) (#47822)
LilithHafner Dec 13, 2022
a548ee3
fixes for jl_rewrap_unionall
vtjnash Nov 30, 2022
31df7c8
call specialized method instance when encountering unspecialized sparams
vtjnash Nov 19, 2022
9827f1d
ensure sparams are cached correctly for widened methods
vtjnash Nov 21, 2022
a506f43
ensure types are UnionAll wrapped are cached correctly for widened Va…
vtjnash Nov 22, 2022
3e1373e
add back wordaround for `Slot objects should not occur in an AST` in …
KristofferC Dec 14, 2022
5848e99
Reduce invalidations when loading JuliaData packages (#47889)
timholy Dec 15, 2022
86e8ef9
intersect: fix a minor soundness issue with supertypes (#47813)
vtjnash Dec 16, 2022
8432d4f
make Ctrl-C during sleeping work better (#47901)
JeffBezanson Dec 16, 2022
eba98e5
revert promotions of abstract arrays inside other arrays (#47893)
KristofferC Dec 19, 2022
a16ffd6
Revert "Emit safepoints at function entry (#41616)"
Dec 20, 2022
5a684f0
Revert "improve performance issue of `@nospecialize`-d keyword func c…
Dec 20, 2022
327e081
only load extensions once dependencies have finished loading (#47927)
KristofferC Dec 19, 2022
95cb3a8
Precompile cache: always add worklist CIs (#47924)
timholy Dec 20, 2022
f17d1df
put back the old QuickSort, PartialQuickSort, and MergeSort algorithm…
LilithHafner Dec 20, 2022
3ea7f6c
add bounds check to Slices indexing (#47622)
mcabbott Dec 20, 2022
22789c0
Reduce codegen lock scope (#46836)
pchintalapudi Dec 13, 2022
9a592dd
Implement support for object caching through pkgimages (#47184)
vchuravy Dec 27, 2022
7880930
Apply `InitialOptimizations` more consistently in sorting & fix dispa…
LilithHafner Dec 22, 2022
6adc428
Restore libgcc_s symlinkin in !macOS (#47986)
antonio-rojas Dec 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add native julia fmod (#47501)
* Add native julia rem

Co-authored-by: Alex Arslan <[email protected]>
(cherry picked from commit cf5ae03)
  • Loading branch information
gbaraldi authored and KristofferC committed Dec 8, 2022
commit ce7a372555b90ae881df24466133e64f2d6c6877
106 changes: 104 additions & 2 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ exponent_one(::Type{Float16}) = 0x3c00
exponent_half(::Type{Float16}) = 0x3800
significand_mask(::Type{Float16}) = 0x03ff

mantissa(x::T) where {T} = reinterpret(Unsigned, x) & significand_mask(T)

for T in (Float16, Float32, Float64)
@eval significand_bits(::Type{$T}) = $(trailing_ones(significand_mask(T)))
@eval exponent_bits(::Type{$T}) = $(sizeof(T)*8 - significand_bits(T) - 1)
Expand Down Expand Up @@ -414,9 +416,109 @@ muladd(x::T, y::T, z::T) where {T<:IEEEFloat} = muladd_float(x, y, z)
# TODO: faster floating point fld?
# TODO: faster floating point mod?

rem(x::T, y::T) where {T<:IEEEFloat} = rem_float(x, y)
function unbiased_exponent(x::T) where {T<:IEEEFloat}
return (reinterpret(Unsigned, x) & exponent_mask(T)) >> significand_bits(T)
end

function explicit_mantissa_noinfnan(x::T) where {T<:IEEEFloat}
m = mantissa(x)
issubnormal(x) || (m |= significand_mask(T) + uinttype(T)(1))
return m
end

function _to_float(number::U, ep) where {U<:Unsigned}
F = floattype(U)
S = signed(U)
epint = unsafe_trunc(S,ep)
lz::signed(U) = unsafe_trunc(S, Core.Intrinsics.ctlz_int(number) - U(exponent_bits(F)))
number <<= lz
epint -= lz
bits = U(0)
if epint >= 0
bits = number & significand_mask(F)
bits |= ((epint + S(1)) << significand_bits(F)) & exponent_mask(F)
else
bits = (number >> -epint) & significand_mask(F)
end
return reinterpret(F, bits)
end

@assume_effects :terminates_locally :nothrow function rem_internal(x::T, y::T) where {T<:IEEEFloat}
xuint = reinterpret(Unsigned, x)
yuint = reinterpret(Unsigned, y)
if xuint <= yuint
if xuint < yuint
return x
end
return zero(T)
end

e_x = unbiased_exponent(x)
e_y = unbiased_exponent(y)
# Most common case where |y| is "very normal" and |x/y| < 2^EXPONENT_WIDTH
if e_y > (significand_bits(T)) && (e_x - e_y) <= (exponent_bits(T))
m_x = explicit_mantissa_noinfnan(x)
m_y = explicit_mantissa_noinfnan(y)
d = urem_int((m_x << (e_x - e_y)), m_y)
iszero(d) && return zero(T)
return _to_float(d, e_y - uinttype(T)(1))
end
# Both are subnormals
if e_x == 0 && e_y == 0
return reinterpret(T, urem_int(xuint, yuint) & significand_mask(T))
end

m_x = explicit_mantissa_noinfnan(x)
e_x -= uinttype(T)(1)
m_y = explicit_mantissa_noinfnan(y)
lz_m_y = uinttype(T)(exponent_bits(T))
if e_y > 0
e_y -= uinttype(T)(1)
else
m_y = mantissa(y)
lz_m_y = Core.Intrinsics.ctlz_int(m_y)
end

tz_m_y = Core.Intrinsics.cttz_int(m_y)
sides_zeroes_cnt = lz_m_y + tz_m_y

# n>0
exp_diff = e_x - e_y
# Shift hy right until the end or n = 0
right_shift = min(exp_diff, tz_m_y)
m_y >>= right_shift
exp_diff -= right_shift
e_y += right_shift
# Shift hx left until the end or n = 0
left_shift = min(exp_diff, uinttype(T)(exponent_bits(T)))
m_x <<= left_shift
exp_diff -= left_shift

m_x = urem_int(m_x, m_y)
iszero(m_x) && return zero(T)
iszero(exp_diff) && return _to_float(m_x, e_y)

while exp_diff > sides_zeroes_cnt
exp_diff -= sides_zeroes_cnt
m_x <<= sides_zeroes_cnt
m_x = urem_int(m_x, m_y)
end
m_x <<= exp_diff
m_x = urem_int(m_x, m_y)
return _to_float(m_x, e_y)
end

function rem(x::T, y::T) where {T<:IEEEFloat}
if isfinite(x) && !iszero(x) && isfinite(y) && !iszero(y)
return copysign(rem_internal(abs(x), abs(y)), x)
elseif isinf(x) || isnan(y) || iszero(y) # y can still be Inf
return T(NaN)
else
return x
end
end

function mod(x::T, y::T) where T<:AbstractFloat
function mod(x::T, y::T) where {T<:AbstractFloat}
r = rem(x,y)
if r == 0
copysign(r,y)
Expand Down
123 changes: 123 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2929,3 +2929,126 @@ end
@test false == ceil(Bool, -0.7)
end
end

@testset "modf" begin
@testset "remd" begin
denorm_min = nextfloat(0.0)
minfloat = floatmin(Float64)
maxfloat = floatmax(Float64)
values = [3.0,denorm_min,-denorm_min, minfloat,
-minfloat, maxfloat, -maxfloat]
# rem (0, y) == 0 for y != 0.
for val in values
@test isequal(rem(0.0, val), 0.0)
end
# rem (-0, y) == -0 for y != 0.
for val in values
@test isequal(rem(-0.0, val), -0.0)
end
# rem (+Inf, y) == NaN
values2 = [3.0,-1.1,0.0,-0.0,denorm_min,minfloat,
maxfloat,Inf,-Inf]
for val in values2
@test isequal(rem(Inf, val), NaN)
end
# rem (-Inf, y) == NaN
for val in values2
@test isequal(rem(-Inf, val), NaN)
end
# rem (x, +0) == NaN
values3 = values2[begin:end-2]
for val in values3
@test isequal(rem(val, 0.0), NaN)
end
# rem (x, -0) == NaN
for val in values3
@test isequal(rem(val, -0.0), NaN)
end
# rem (x, +Inf) == x for x not infinite.
@test isequal(rem(0.0, Inf), 0.0)
@test isequal(rem(-0.0, Inf), -0.0)
@test isequal(rem(denorm_min, Inf), denorm_min)
@test isequal(rem(minfloat, Inf), minfloat)
@test isequal(rem(maxfloat, Inf), maxfloat)
@test isequal(rem(3.0, Inf), 3.0)
# rem (x, -Inf) == x for x not infinite.
@test isequal(rem(0.0, -Inf), 0.0)
@test isequal(rem(-0.0, -Inf), -0.0)
@test isequal(rem(denorm_min, -Inf), denorm_min)
@test isequal(rem(minfloat, -Inf), minfloat)
@test isequal(rem(maxfloat, -Inf), maxfloat)
@test isequal(rem(3.0, -Inf), 3.0)
#NaN tests
@test isequal(rem(0.0, NaN), NaN)
@test isequal(rem(1.0, NaN), NaN)
@test isequal(rem(Inf, NaN), NaN)
@test isequal(rem(NaN, 0.0), NaN)
@test isequal(rem(NaN, 1.0), NaN)
@test isequal(rem(NaN, Inf), NaN)
@test isequal(rem(NaN, NaN), NaN)
#Sign tests
@test isequal(rem(6.5, 2.25), 2.0)
@test isequal(rem(-6.5, 2.25), -2.0)
@test isequal(rem(6.5, -2.25), 2.0)
@test isequal(rem(-6.5, -2.25), -2.0)
values4 = [maxfloat,-maxfloat,minfloat,-minfloat,
denorm_min, -denorm_min]
for val in values4
@test isequal(rem(maxfloat,val), 0.0)
end
for val in values4
@test isequal(rem(-maxfloat,val), -0.0)
end
@test isequal(rem(minfloat, maxfloat), minfloat)
@test isequal(rem(minfloat, -maxfloat), minfloat)
values5 = values4[begin+2:end]
for val in values5
@test isequal(rem(minfloat,val), 0.0)
end
@test isequal(rem(-minfloat, maxfloat), -minfloat)
@test isequal(rem(-minfloat, -maxfloat), -minfloat)
for val in values5
@test isequal(rem(-minfloat,val), -0.0)
end
values6 = values4[begin:end-2]
for val in values6
@test isequal(rem(denorm_min,val), denorm_min)
end
@test isequal(rem(denorm_min, denorm_min), 0.0)
@test isequal(rem(denorm_min, -denorm_min), 0.0)
for val in values6
@test isequal(rem(-denorm_min,val), -denorm_min)
end
@test isequal(rem(-denorm_min, denorm_min), -0.0)
@test isequal(rem(-denorm_min, -denorm_min), -0.0)
#Max value tests
values7 = [0x3p-1074,-0x3p-1074,0x3p-1073,-0x3p-1073]
for val in values7
@test isequal(rem(0x1p1023,val), 0x1p-1073)
end
@test isequal(rem(0x1p1023, 0x3p-1022), 0x1p-1021)
@test isequal(rem(0x1p1023, -0x3p-1022), 0x1p-1021)
for val in values7
@test isequal(rem(-0x1p1023,val), -0x1p-1073)
end
@test isequal(rem(-0x1p1023, 0x3p-1022), -0x1p-1021)
@test isequal(rem(-0x1p1023, -0x3p-1022), -0x1p-1021)

end

@testset "remf" begin
@test isequal(rem(Float32(0x1p127), Float32(0x3p-149)), Float32(0x1p-149))
@test isequal(rem(Float32(0x1p127), -Float32(0x3p-149)), Float32(0x1p-149))
@test isequal(rem(Float32(0x1p127), Float32(0x3p-148)), Float32(0x1p-147))
@test isequal(rem(Float32(0x1p127), -Float32(0x3p-148)), Float32(0x1p-147))
@test isequal(rem(Float32(0x1p127), Float32(0x3p-126)), Float32(0x1p-125))
@test isequal(rem(Float32(0x1p127), -Float32(0x3p-126)), Float32(0x1p-125))
@test isequal(rem(-Float32(0x1p127), Float32(0x3p-149)), -Float32(0x1p-149))
@test isequal(rem(-Float32(0x1p127), -Float32(0x3p-149)), -Float32(0x1p-149))
@test isequal(rem(-Float32(0x1p127), Float32(0x3p-148)), -Float32(0x1p-147))
@test isequal(rem(-Float32(0x1p127), -Float32(0x3p-148)), -Float32(0x1p-147))
@test isequal(rem(-Float32(0x1p127), Float32(0x3p-126)), -Float32(0x1p-125))
@test isequal(rem(-Float32(0x1p127), -Float32(0x3p-126)), -Float32(0x1p-125))
end

end