Skip to content

Commit 78df0c1

Browse files
authored
Use libquadmath sincos rather than sin and cos (#119)
On macOS AArch64 with libquadmath, this provides a performance improvement: median 477 ns on this branch vs. 880 ns on master. On FreeBSD AArch64 with libm, the performance on this branch is identical to master, about 610 ns for both. (Note that the Julia version used on macOS and FreeBSD here differed: 1.12.7 on macOS and 1.14.0-DEV.3218 on FreeBSD.)
1 parent f44b19e commit 78df0c1

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎src/Quadmath.jl‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,12 @@ if VERSION < v"1.14.0-DEV.2070"
367367
end
368368
end
369369

370-
sincos(x::Float128) = (sin(x), cos(x))
370+
function sincos(x::Float128)
371+
sin = Ref{Cfloat128}()
372+
cos = Ref{Cfloat128}()
373+
@quad_ccall(@autoql(sincos)(x::Cfloat128, sin::Ref{Cfloat128}, cos::Ref{Cfloat128})::Cvoid)
374+
return (Float128(sin[]), Float128(cos[]))
375+
end
371376

372377
## misc
373378

‎test/runtests.jl‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ end
143143
if !Sys.iswindows()
144144
@test fma(x,x,Float128(-1.0)) ≈ Float128(1)
145145
end
146+
@test sin(x) ≈ sin(xd)
147+
@test cos(x) ≈ cos(xd)
148+
@test all(sincos(x) .≈ (sin(x), cos(x)))
146149
end
147150
@testset "complex" begin
148151
x = sqrt(ComplexF128(1.0 + 1.0im))

0 commit comments

Comments
 (0)