Skip to content

Commit 2e28bd7

Browse files
author
Reimar Döffinger
committed
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.
1 parent 8f843fd commit 2e28bd7

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

include/boost/math/policies/policy.hpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,17 @@ namespace policies{
111111
#define BOOST_MATH_PROMOTE_FLOAT_POLICY true
112112
#endif
113113
#ifndef BOOST_MATH_PROMOTE_DOUBLE_POLICY
114-
#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
115-
#define BOOST_MATH_PROMOTE_DOUBLE_POLICY false
116-
#else
114+
#if !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) \
115+
&& (defined(__i386) || defined(__i386__) || defined(_M_IX86) \
116+
|| defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) \
117+
|| defined(__x86_64) || defined(__x86_64__) || defined(_M_X64))
118+
// On non-x86 long double is expected to be either the same as double
119+
// or an emulated 128 bit type - promotion is not sensible.
120+
// On x86 long double is also rather slow these days, but changing the
121+
// policy there has larger compatibility concerns and is left to a later time
117122
#define BOOST_MATH_PROMOTE_DOUBLE_POLICY true
123+
#else
124+
#define BOOST_MATH_PROMOTE_DOUBLE_POLICY false
118125
#endif
119126
#endif
120127
#ifndef BOOST_MATH_DISCRETE_QUANTILE_POLICY

test/test_policy_8.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ BOOST_AUTO_TEST_CASE( test_main )
3939
BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>(), indeterminate_result_error<throw_on_error>(), digits10<5>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error>, indeterminate_result_error<throw_on_error>, digits2<19> >()));
4040
BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>(), indeterminate_result_error<throw_on_error>(), digits2<10>(), promote_float<false>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error>, indeterminate_result_error<throw_on_error>, digits2<10>, promote_float<false> >()));
4141
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
42-
BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>(), indeterminate_result_error<throw_on_error>(), digits2<10>(), promote_float<false>(), promote_double<false>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error>, indeterminate_result_error<throw_on_error>, digits2<10>, promote_float<false>, promote_double<false> >()));
43-
BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>(), indeterminate_result_error<throw_on_error>(), digits2<10>(), promote_float<false>(), promote_double<false>(), discrete_quantile<integer_round_down>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error>, indeterminate_result_error<throw_on_error>, digits2<10>, promote_float<false>, promote_double<false>, discrete_quantile<integer_round_down> >()));
42+
BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>(), indeterminate_result_error<throw_on_error>(), digits2<10>(), promote_float<false>(), promote_double<!BOOST_MATH_PROMOTE_DOUBLE_POLICY>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error>, indeterminate_result_error<throw_on_error>, digits2<10>, promote_float<false>, promote_double<!BOOST_MATH_PROMOTE_DOUBLE_POLICY> >()));
43+
BOOST_CHECK(check_same(make_policy(domain_error<ignore_error>(), pole_error<ignore_error>(), overflow_error<ignore_error>(), underflow_error<throw_on_error>(), denorm_error<throw_on_error>(), evaluation_error<ignore_error>(), indeterminate_result_error<throw_on_error>(), digits2<10>(), promote_float<false>(), promote_double<!BOOST_MATH_PROMOTE_DOUBLE_POLICY>(), discrete_quantile<integer_round_down>()), policy<domain_error<ignore_error>, pole_error<ignore_error>, overflow_error<ignore_error>, underflow_error<throw_on_error>, denorm_error<throw_on_error>, evaluation_error<ignore_error>, indeterminate_result_error<throw_on_error>, digits2<10>, promote_float<false>, promote_double<!BOOST_MATH_PROMOTE_DOUBLE_POLICY>, discrete_quantile<integer_round_down> >()));
4444
#endif
4545

4646

0 commit comments

Comments
 (0)