Skip to content

Commit

Permalink
Add rem2pi (#544)
Browse files Browse the repository at this point in the history
* Add rem2pi

* fix
  • Loading branch information
wsmoses authored Nov 8, 2022
1 parent 390c3d7 commit b29b7ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ unsafe_to_pointer(ptr) = ccall(Base.@cfunction(x->x, Ptr{Cvoid}, (Ptr{Cvoid},)),
# Julia function to LLVM stem and arity
const known_ops = Dict(
Base.cbrt => (:cbrt, 1),
Base.rem2pi => (:jl_rem2pi, 2),
Base.sqrt => (:sqrt, 1),
Base.sin => (:sin, 1),
Base.sinc => (:sincn, 1),
Expand Down Expand Up @@ -6044,6 +6045,7 @@ end
elseif sparam_vals[2] != T
continue
end
elseif name == :jl_rem2pi
else
all(==(T), sparam_vals) || continue
end
Expand All @@ -6060,7 +6062,7 @@ end
handleCustom(name, [EnumAttribute("readnone", 0; ctx),
StringAttribute("enzyme_shouldrecompute"; ctx)])
end

@assert actualRetType !== nothing

if must_wrap
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ function is_primitive_func(@nospecialize(TT))
if in(ft, PrimitiveFuncs)
return true
end
if ft === typeof(Base.rem2pi)
if TT <: Tuple{ft, Float32, <:Any} || TT <: Tuple{ft, Float64, <:Any} || TT <: Tuple{ft, Float16, <:Any}
return true
end
end
if ft === typeof(Base.cbrt) || ft === typeof(Base.sin) || ft === typeof(Base.cos) ||
ft === typeof(Base.sinc) ||
ft === typeof(Base.tan) || ft === typeof(Base.exp) || ft === typeof(Base.FastMath.exp_fast) ||
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ end
test_scalar(Base.exp10, 1.0)
test_scalar(Base.exp2, 1.0)
test_scalar(Base.expm1, 1.0)
test_scalar(x->rem2pi(x,RoundDown), 0.7)

@test autodiff(Reverse, (x)->log(x), Active(2.0)) == (0.5,)
end
Expand Down

0 comments on commit b29b7ac

Please sign in to comment.