diff --git a/CMakeLists.txt b/CMakeLists.txt index 727a9d1..63acd4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ include(CMakePackageConfigHelpers) option(OMATH_BUILD_TESTS "Build unit tests" ON) option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON) option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF) +option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON) if (OMATH_BUILD_AS_SHARED_LIBRARY) @@ -30,6 +31,9 @@ endif() target_compile_features(omath PUBLIC cxx_std_23) +if (OMATH_USE_AVX2) + target_compile_definitions(omath PUBLIC OMATH_USE_AVX2) +endif() add_subdirectory(source) diff --git a/source/projectile_prediction/ProjPredEngineAVX2.cpp b/source/projectile_prediction/ProjPredEngineAVX2.cpp index 208d573..9c63fd9 100644 --- a/source/projectile_prediction/ProjPredEngineAVX2.cpp +++ b/source/projectile_prediction/ProjPredEngineAVX2.cpp @@ -2,13 +2,14 @@ // Created by Vlad on 2/23/2025. // #include "omath/projectile_prediction/ProjPredEngineAVX2.hpp" - +#include "source_location" namespace omath::projectile_prediction { - std::optional> ProjPredEngineAVX2::MaybeCalculateAimPoint(const Projectile& projectile, - const Target& target) const + std::optional> ProjPredEngineAVX2::MaybeCalculateAimPoint([[maybe_unused]] const Projectile& projectile, + [[maybe_unused]] const Target& target) const { +#ifdef OMATH_USE_AVX2 const float bulletGravity = m_gravityConstant * projectile.m_gravityScale; const float v0 = projectile.m_launchSpeed; const float v0Sqr = v0 * v0; @@ -134,5 +135,7 @@ namespace omath::projectile_prediction const float d = std::sqrt(dSqr); const float tanTheta = term / d; return angles::RadiansToDegrees(std::atan(tanTheta)); +#endif + throw std::runtime_error(std::format("{} AVX2 feature is not enabled!", std::source_location::current().function_name())); } } // namespace omath::projectile_prediction