Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_sqrt function in mul.cpp got failed. Need to change rounding mode for MXCSR. #23

Open
yuxianch opened this issue Sep 16, 2019 · 1 comment

Comments

@yuxianch
Copy link

Code to reproduce:

#include <boost/numeric/interval.hpp>
#include <boost/test/minimal.hpp>
#include "bugs.hpp"
typedef boost::numeric::interval I;
static bool test_sqrt(double al, double au) {
I a(al, au);
I b = square(sqrt(a));
return subset(abs(a), b);
}
int test_main(int, char*[]) {
BOOST_CHECK(test_sqrt(2, 3));
BOOST_CHECK(test_sqrt(5, 7));
return 0;
}

When linking with -limf(Intel's LIBM Math library), this test would got failed when running. Below is the error message.

test.cpp(15): test test_sqrt(2, 3) failed in function: 'int test_main(int, char **)'
test.cpp(16): test test_sqrt(5, 7) failed in function: 'int test_main(int, char **)'
**** 2 errors detected

This test changed rounding mode only on x87 FPU control register (bits 10 and 11) but not on MXCSR register (bits 13 and 14). There are functions in LIBM that could use x87 or simd instructions. In this case, SSE version of sqrt is called and it uses "sqrtsd %xmm0,%xmm0" instruction. This sqrtsd instruction uses the rounding mode that is in the MXCSR. Therefore, the rounding bits in MXCSR should be updated as well.

@yuxianch
Copy link
Author

Additional info: We have fesetround function (see in fenv.h) to set rounding modes in both x87 control register and MXCSR. It is probably easier to use it. We have also fegetround but it returns Rounding Mode bits from MXCSR in Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant