Skip to content
Merged
Changes from all commits
Commits
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
30 changes: 15 additions & 15 deletions base/ryu/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pow5bits(e) = ((e * 1217359) >> 19) + 1

Compute `(m * mul) >> j`, where `j >= 8*sizeof(U)`. The type of the results is the larger of `U` or `UInt32`.
"""
@inline function mulshift(m::U, mul, j) where {U<:Unsigned}
function mulshift(m::U, mul, j) where {U<:Unsigned}
W = widen(U)
nbits = 8*sizeof(U)
return ((((W(m) * (mul % U)) >> nbits) + W(m) * (mul >> nbits)) >> (j - nbits)) % promote_type(U,UInt32)
Expand All @@ -64,7 +64,7 @@ lengthforindex(idx) = div(((Int64(16 * idx) * 1292913986) >> 32) + 1 + 16 + 8, 9

Return `true` if `5^p` is a divisor of `x`.
"""
@inline function pow5(x, p)
function pow5(x, p)
x % (5^p) == 0
end

Expand All @@ -80,7 +80,7 @@ pow2(x, p) = (x & ((Int64(1) << p) - 1)) == 0

The number of decimal digits of the integer `v`.
"""
@inline function decimallength(v)
function decimallength(v)
v >= 10000000000000000 && return 17
v >= 1000000000000000 && return 16
v >= 100000000000000 && return 15
Expand All @@ -99,7 +99,7 @@ The number of decimal digits of the integer `v`.
v >= 10 && return 2
return 1
end
@inline function decimallength(v::UInt32)
function decimallength(v::UInt32)
v >= 100000000 && return 9
v >= 10000000 && return 8
v >= 1000000 && return 7
Expand All @@ -110,23 +110,23 @@ end
v >= 10 && return 2
return 1
end
@inline function decimallength(v::UInt16)
function decimallength(v::UInt16)
v >= 10000 && return 5
v >= 1000 && return 4
v >= 100 && return 3
v >= 10 && return 2
return 1
end

@inline function mulshiftinvsplit(::Type{T}, mv, mp, mm, i, j) where {T}
function mulshiftinvsplit(::Type{T}, mv, mp, mm, i, j) where {T}
mul = pow5invsplit_lookup(T, i)
vr = mulshift(mv, mul, j)
vp = mulshift(mp, mul, j)
vm = mulshift(mm, mul, j)
return vr, vp, vm
end

@inline function mulshiftsplit(::Type{T}, mv, mp, mm, i, j) where {T}
function mulshiftsplit(::Type{T}, mv, mp, mm, i, j) where {T}
mul = pow5split_lookup(T, i)
vr = mulshift(mv, mul, j)
vp = mulshift(mp, mul, j)
Expand All @@ -139,7 +139,7 @@ end

Compute `p = a*b` where `b = bLo + bHi<<64`, returning the result as `pLo, pHi` where `p = pLo + pHi<<128`.
"""
@inline function umul256(a, bHi, bLo)
function umul256(a, bHi, bLo)
aLo = a % UInt64
aHi = (a >> 64) % UInt64

Expand Down Expand Up @@ -169,14 +169,14 @@ end

Compute `pHi = (a*b)>>128` where `b = bLo + bHi<<64`.
"""
@inline umul256_hi(a, bHi, bLo) = umul256(a, bHi, bLo)[2]
umul256_hi(a, bHi, bLo) = umul256(a, bHi, bLo)[2]

"""
Ryu.mulshiftmod1e9(m, mula, mulb, mulc, j)::UInt32

Compute `(m * mul) >> j % 10^9` where `mul = mula + mulb<<64 + mulc<<128`, and `j >= 128`.
"""
@inline function mulshiftmod1e9(m, mula, mulb, mulc, j)
function mulshiftmod1e9(m, mula, mulb, mulc, j)
b0 = UInt128(m) * mula
b1 = UInt128(m) * mulb
b2 = UInt128(m) * mulc
Expand All @@ -188,7 +188,7 @@ Compute `(m * mul) >> j % 10^9` where `mul = mula + mulb<<64 + mulc<<128`, and `
return (v % UInt32) - UInt32(1000000000) * shifted
end

@inline function append_sign(x, plus, space, buf, pos)
function append_sign(x, plus, space, buf, pos)
if signbit(x) && !isnan(x) # suppress minus sign for signaling NaNs
buf[pos] = UInt8('-')
pos += 1
Expand All @@ -202,7 +202,7 @@ end
return pos
end

@inline function append_n_digits(olength, digits, buf, pos)
function append_n_digits(olength, digits, buf, pos)
i = 0
while digits >= 10000
c = digits % 10000
Expand Down Expand Up @@ -230,7 +230,7 @@ end
return pos + i
end

@inline function append_d_digits(olength, digits, buf, pos, decchar)
function append_d_digits(olength, digits, buf, pos, decchar)
i = 0
while digits >= 10000
c = digits % 10000
Expand Down Expand Up @@ -261,7 +261,7 @@ end
return pos + i
end

@inline function append_c_digits(count, digits, buf, pos)
function append_c_digits(count, digits, buf, pos)
i = 0
while i < count - 1
c = (digits % 100) << 1
Expand All @@ -276,7 +276,7 @@ end
return pos + i
end

@inline function append_nine_digits(digits, buf, pos)
function append_nine_digits(digits, buf, pos)
if digits == 0
for _ = 1:9
buf[pos] = UInt8('0')
Expand Down