Skip to content

Commit 4e53f3d

Browse files
committed
Support older versions of julia
1 parent 4bd8c45 commit 4e53f3d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/FixedPointDecimals.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@ using Base: decompose, BitInteger
3939
using BitIntegers: BitIntegers, UInt256, Int256
4040
import Parsers
4141

42-
include("fldmod-by-const.jl")
42+
# The effects system in newer versions of Julia is necessary for the fldmod_by_const
43+
# optimization to take affect without adverse performance impacts.
44+
# For older versions of julia, we will fall back to the flmod implementation, which works
45+
# very fast for all FixedDecimals of size <= 64 bits.
46+
if isdefined(Base, Symbol("@assume_effects"))
47+
include("fldmod-by-const.jl")
48+
else
49+
# We force-inline this, to allow the fldmod operation to be specialized for a constant
50+
# second argument (converting divide-by-power-of-ten instructions with the cheaper
51+
# multiply-by-inverse-coefficient.) Sadly this doesn't work for Int128.
52+
@inline fldmod_by_const(x,y) = (fld(x,y), mod(x,y))
53+
end
4354

4455
# floats that support fma and are roughly IEEE-like
4556
const FMAFloat = Union{Float16, Float32, Float64, BigFloat}

src/fldmod-by-const.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ end
3030
return x - quotient * y
3131
end
3232

33-
Base.@assume_effects :total function div_by_const(x::T, ::Val{C}) where {T, C}
33+
function div_by_const(x::T, ::Val{C}) where {T, C}
3434
# These checks will be compiled away during specialization.
3535
# While for `*(FixedDecimal, FixedDecimal)`, C will always be a power of 10, these
3636
# checks allow this function to work for any `C > 0`, in case that's useful in the

0 commit comments

Comments
 (0)