From f0e215f8f51e5faaac9617c560f34014ceff49f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Wed, 5 Sep 2018 15:15:02 +0200 Subject: [PATCH] Math/Angle: Optimize SinCos on Linux --- build/scripts/modules/core.lua | 1 + include/Nazara/Math/Angle.inl | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/build/scripts/modules/core.lua b/build/scripts/modules/core.lua index ae87461e8..e998080f8 100644 --- a/build/scripts/modules/core.lua +++ b/build/scripts/modules/core.lua @@ -19,5 +19,6 @@ MODULE.OsFiles.Posix = { MODULE.OsLibraries.Posix = { "dl", + "m", -- Math library (for sincos()) "pthread" } diff --git a/include/Nazara/Math/Angle.inl b/include/Nazara/Math/Angle.inl index e04a751d9..c22e99e2c 100644 --- a/include/Nazara/Math/Angle.inl +++ b/include/Nazara/Math/Angle.inl @@ -5,6 +5,11 @@ #include #include #include + +#ifdef NAZARA_PLATFORM_POSIX +#include //< sincos +#endif + #include namespace Nz @@ -101,6 +106,29 @@ namespace Nz } }; +#ifdef NAZARA_PLATFORM_POSIX + template + void SinCos(std::enable_if_t::value && !std::is_same::value, double> x, T* sin, T* cos) + { + double s, c; + ::sincos(x, &s, &c); + + *sin = static_cast(s); + *cos = static_cast(c); + } + + template + void SinCos(std::enable_if_t::value, float> x, float* s, float* cos) + { + ::sincosf(x, s, c); + } + + template + void SinCos(std::enable_if_t::value, long double> x, long double* s, long double* c) + { + ::sincosl(x, sin, cos); + } +#else // Naive implementation, hopefully optimized by the compiler template void SinCos(T x, T* sin, T* cos) @@ -108,6 +136,7 @@ namespace Nz *sin = std::sin(x); *cos = std::cos(x); } +#endif } /*! * \ingroup math