From 2e28bd79cafb0db8be6d9688bff8e2c28fb0d311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Wed, 20 Nov 2024 17:43:52 +0100 Subject: [PATCH] Change BOOST_MATH_PROMOTE_DOUBLE_POLICY to false for non-x86 Avoids a massive performance loss due to use of emulated 128 bit types. Fixes issue #1211. --- include/boost/math/policies/policy.hpp | 13 ++++++++++--- test/test_policy_8.cpp | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/boost/math/policies/policy.hpp b/include/boost/math/policies/policy.hpp index ec7b36f2d5..d455aa9053 100644 --- a/include/boost/math/policies/policy.hpp +++ b/include/boost/math/policies/policy.hpp @@ -111,10 +111,17 @@ namespace policies{ #define BOOST_MATH_PROMOTE_FLOAT_POLICY true #endif #ifndef BOOST_MATH_PROMOTE_DOUBLE_POLICY -#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS -#define BOOST_MATH_PROMOTE_DOUBLE_POLICY false -#else +#if !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) \ + && (defined(__i386) || defined(__i386__) || defined(_M_IX86) \ + || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) \ + || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)) +// On non-x86 long double is expected to be either the same as double +// or an emulated 128 bit type - promotion is not sensible. +// On x86 long double is also rather slow these days, but changing the +// policy there has larger compatibility concerns and is left to a later time #define BOOST_MATH_PROMOTE_DOUBLE_POLICY true +#else +#define BOOST_MATH_PROMOTE_DOUBLE_POLICY false #endif #endif #ifndef BOOST_MATH_DISCRETE_QUANTILE_POLICY diff --git a/test/test_policy_8.cpp b/test/test_policy_8.cpp index 14a2897ad6..8b4c6b4eb2 100644 --- a/test/test_policy_8.cpp +++ b/test/test_policy_8.cpp @@ -39,8 +39,8 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK(check_same(make_policy(domain_error(), pole_error(), overflow_error(), underflow_error(), denorm_error(), evaluation_error(), indeterminate_result_error(), digits10<5>()), policy, pole_error, overflow_error, underflow_error, denorm_error, evaluation_error, indeterminate_result_error, digits2<19> >())); BOOST_CHECK(check_same(make_policy(domain_error(), pole_error(), overflow_error(), underflow_error(), denorm_error(), evaluation_error(), indeterminate_result_error(), digits2<10>(), promote_float()), policy, pole_error, overflow_error, underflow_error, denorm_error, evaluation_error, indeterminate_result_error, digits2<10>, promote_float >())); #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS - BOOST_CHECK(check_same(make_policy(domain_error(), pole_error(), overflow_error(), underflow_error(), denorm_error(), evaluation_error(), indeterminate_result_error(), digits2<10>(), promote_float(), promote_double()), policy, pole_error, overflow_error, underflow_error, denorm_error, evaluation_error, indeterminate_result_error, digits2<10>, promote_float, promote_double >())); - BOOST_CHECK(check_same(make_policy(domain_error(), pole_error(), overflow_error(), underflow_error(), denorm_error(), evaluation_error(), indeterminate_result_error(), digits2<10>(), promote_float(), promote_double(), discrete_quantile()), policy, pole_error, overflow_error, underflow_error, denorm_error, evaluation_error, indeterminate_result_error, digits2<10>, promote_float, promote_double, discrete_quantile >())); + BOOST_CHECK(check_same(make_policy(domain_error(), pole_error(), overflow_error(), underflow_error(), denorm_error(), evaluation_error(), indeterminate_result_error(), digits2<10>(), promote_float(), promote_double()), policy, pole_error, overflow_error, underflow_error, denorm_error, evaluation_error, indeterminate_result_error, digits2<10>, promote_float, promote_double >())); + BOOST_CHECK(check_same(make_policy(domain_error(), pole_error(), overflow_error(), underflow_error(), denorm_error(), evaluation_error(), indeterminate_result_error(), digits2<10>(), promote_float(), promote_double(), discrete_quantile()), policy, pole_error, overflow_error, underflow_error, denorm_error, evaluation_error, indeterminate_result_error, digits2<10>, promote_float, promote_double, discrete_quantile >())); #endif