Mercurial > hg > octave-lyh > gnulib-hg
changeset 13839:9f1a04b1a802
ceil, floor: avoid spurious failure with icc
* tests/test-ceilf2.c (ceilf_reference): Avoid icc's use of DAZ
[denormals-as-zero] when optimizing without -mieee-fp option.
* tests/test-floorf2.c (floorf_reference): Likewise.
* tests/test-ceilf1.c (dummy): New function.
(main): Use it to outsmart icc's optimization.
* tests/test-floorf1.c (dummy, main): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Fri, 05 Nov 2010 15:26:35 -0600 |
parents | 2a545b8a8c9e |
children | 4a556ba5903b |
files | ChangeLog tests/test-ceilf1.c tests/test-ceilf2.c tests/test-floorf1.c tests/test-floorf2.c |
diffstat | 5 files changed, 94 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2010-11-05 Eric Blake <eblake@redhat.com> + ceil, floor: avoid spurious failure with icc + * tests/test-ceilf2.c (ceilf_reference): Avoid icc's use of DAZ + [denormals-as-zero] when optimizing without -mieee-fp option. + * tests/test-floorf2.c (floorf_reference): Likewise. + * tests/test-ceilf1.c (dummy): New function. + (main): Use it to outsmart icc's optimization. + * tests/test-floorf1.c (dummy, main): Likewise. + tests: require working signbit * modules/ceilf-tests (Depends-on): Add signbit. * modules/ceill-tests (Depends-on): Likewise.
--- a/tests/test-ceilf1.c +++ b/tests/test-ceilf1.c @@ -28,40 +28,53 @@ #include "nan.h" #include "macros.h" +/* If IEEE compliance was not requested, the ICC compiler inlines its + own ceilf assembly that turns -0.0f to 0.0f; but that is a correct + result when IEEE is not enforced. To avoid spurious failure, we + have to provide this dummy function in order to outsmart ICC's + inlining, and call our ceilf through a function pointer. */ +static float +dummy (float f) +{ + return 0; +} + int -main () +main (int argc, char **argv _GL_UNUSED) { + float (*my_ceilf) (float) = argc ? ceilf : dummy; + /* Zero. */ - ASSERT (ceilf (0.0f) == 0.0f); - ASSERT (!signbit (ceilf (0.0f))); - ASSERT (ceilf (minus_zerof) == 0.0f); - ASSERT (!!signbit (minus_zerof) == !!signbit (ceilf (minus_zerof))); + ASSERT (my_ceilf (0.0f) == 0.0f); + ASSERT (!signbit (my_ceilf (0.0f))); + ASSERT (my_ceilf (minus_zerof) == 0.0f); + ASSERT (!!signbit (minus_zerof) == !!signbit (my_ceilf (minus_zerof))); /* Positive numbers. */ - ASSERT (ceilf (0.3f) == 1.0f); - ASSERT (ceilf (0.7f) == 1.0f); - ASSERT (ceilf (1.0f) == 1.0f); - ASSERT (ceilf (1.001f) == 2.0f); - ASSERT (ceilf (1.5f) == 2.0f); - ASSERT (ceilf (1.999f) == 2.0f); - ASSERT (ceilf (2.0f) == 2.0f); - ASSERT (ceilf (65535.99f) == 65536.0f); - ASSERT (ceilf (65536.0f) == 65536.0f); - ASSERT (ceilf (2.341e31f) == 2.341e31f); + ASSERT (my_ceilf (0.3f) == 1.0f); + ASSERT (my_ceilf (0.7f) == 1.0f); + ASSERT (my_ceilf (1.0f) == 1.0f); + ASSERT (my_ceilf (1.001f) == 2.0f); + ASSERT (my_ceilf (1.5f) == 2.0f); + ASSERT (my_ceilf (1.999f) == 2.0f); + ASSERT (my_ceilf (2.0f) == 2.0f); + ASSERT (my_ceilf (65535.99f) == 65536.0f); + ASSERT (my_ceilf (65536.0f) == 65536.0f); + ASSERT (my_ceilf (2.341e31f) == 2.341e31f); /* Negative numbers. */ - ASSERT (ceilf (-0.3f) == 0.0f); - ASSERT (ceilf (-0.7f) == 0.0f); - ASSERT (ceilf (-1.0f) == -1.0f); - ASSERT (ceilf (-1.5f) == -1.0f); - ASSERT (ceilf (-1.999f) == -1.0f); - ASSERT (ceilf (-2.0f) == -2.0f); - ASSERT (ceilf (-65535.99f) == -65535.0f); - ASSERT (ceilf (-65536.0f) == -65536.0f); - ASSERT (ceilf (-2.341e31f) == -2.341e31f); + ASSERT (my_ceilf (-0.3f) == 0.0f); + ASSERT (my_ceilf (-0.7f) == 0.0f); + ASSERT (my_ceilf (-1.0f) == -1.0f); + ASSERT (my_ceilf (-1.5f) == -1.0f); + ASSERT (my_ceilf (-1.999f) == -1.0f); + ASSERT (my_ceilf (-2.0f) == -2.0f); + ASSERT (my_ceilf (-65535.99f) == -65535.0f); + ASSERT (my_ceilf (-65536.0f) == -65536.0f); + ASSERT (my_ceilf (-2.341e31f) == -2.341e31f); /* Infinite numbers. */ - ASSERT (ceilf (1.0f / 0.0f) == 1.0f / 0.0f); - ASSERT (ceilf (-1.0f / 0.0f) == -1.0f / 0.0f); + ASSERT (my_ceilf (1.0f / 0.0f) == 1.0f / 0.0f); + ASSERT (my_ceilf (-1.0f / 0.0f) == -1.0f / 0.0f); /* NaNs. */ - ASSERT (isnanf (ceilf (NaNf ()))); + ASSERT (isnanf (my_ceilf (NaNf ()))); return 0; }
--- a/tests/test-ceilf2.c +++ b/tests/test-ceilf2.c @@ -63,6 +63,9 @@ if (z > L_(0.0)) { + /* Work around ICC's desire to optimize denormal floats to 0. */ + if (z < FLT_MIN) + return L_(1.0); /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */ if (z < TWO_MANT_DIG) {
--- a/tests/test-floorf1.c +++ b/tests/test-floorf1.c @@ -28,40 +28,53 @@ #include "nan.h" #include "macros.h" +/* If IEEE compliance was not requested, the ICC compiler inlines its + own floorf assembly that turns -0.0f to 0.0f; but that is a correct + result when IEEE is not enforced. To avoid spurious failure, we + have to provide this dummy function in order to outsmart ICC's + inlining, and call our floorf through a function pointer. */ +static float +dummy (float f) +{ + return 0; +} + int -main () +main (int argc, char **argv _GL_UNUSED) { + float (*my_floorf) (float) = argc ? floorf : dummy; + /* Zero. */ - ASSERT (floorf (0.0f) == 0.0f); - ASSERT (!signbit (floorf (0.0f))); - ASSERT (floorf (minus_zerof) == 0.0f); - ASSERT (!!signbit (minus_zerof) == !!signbit (floorf (minus_zerof))); + ASSERT (my_floorf (0.0f) == 0.0f); + ASSERT (!signbit (my_floorf (0.0f))); + ASSERT (my_floorf (minus_zerof) == 0.0f); + ASSERT (!!signbit (minus_zerof) == !!signbit (my_floorf (minus_zerof))); /* Positive numbers. */ - ASSERT (floorf (0.3f) == 0.0f); - ASSERT (floorf (0.7f) == 0.0f); - ASSERT (floorf (1.0f) == 1.0f); - ASSERT (floorf (1.5f) == 1.0f); - ASSERT (floorf (1.999f) == 1.0f); - ASSERT (floorf (2.0f) == 2.0f); - ASSERT (floorf (65535.99f) == 65535.0f); - ASSERT (floorf (65536.0f) == 65536.0f); - ASSERT (floorf (2.341e31f) == 2.341e31f); + ASSERT (my_floorf (0.3f) == 0.0f); + ASSERT (my_floorf (0.7f) == 0.0f); + ASSERT (my_floorf (1.0f) == 1.0f); + ASSERT (my_floorf (1.5f) == 1.0f); + ASSERT (my_floorf (1.999f) == 1.0f); + ASSERT (my_floorf (2.0f) == 2.0f); + ASSERT (my_floorf (65535.99f) == 65535.0f); + ASSERT (my_floorf (65536.0f) == 65536.0f); + ASSERT (my_floorf (2.341e31f) == 2.341e31f); /* Negative numbers. */ - ASSERT (floorf (-0.3f) == -1.0f); - ASSERT (floorf (-0.7f) == -1.0f); - ASSERT (floorf (-1.0f) == -1.0f); - ASSERT (floorf (-1.001f) == -2.0f); - ASSERT (floorf (-1.5f) == -2.0f); - ASSERT (floorf (-1.999f) == -2.0f); - ASSERT (floorf (-2.0f) == -2.0f); - ASSERT (floorf (-65535.99f) == -65536.0f); - ASSERT (floorf (-65536.0f) == -65536.0f); - ASSERT (floorf (-2.341e31f) == -2.341e31f); + ASSERT (my_floorf (-0.3f) == -1.0f); + ASSERT (my_floorf (-0.7f) == -1.0f); + ASSERT (my_floorf (-1.0f) == -1.0f); + ASSERT (my_floorf (-1.001f) == -2.0f); + ASSERT (my_floorf (-1.5f) == -2.0f); + ASSERT (my_floorf (-1.999f) == -2.0f); + ASSERT (my_floorf (-2.0f) == -2.0f); + ASSERT (my_floorf (-65535.99f) == -65536.0f); + ASSERT (my_floorf (-65536.0f) == -65536.0f); + ASSERT (my_floorf (-2.341e31f) == -2.341e31f); /* Infinite numbers. */ - ASSERT (floorf (1.0f / 0.0f) == 1.0f / 0.0f); - ASSERT (floorf (-1.0f / 0.0f) == -1.0f / 0.0f); + ASSERT (my_floorf (1.0f / 0.0f) == 1.0f / 0.0f); + ASSERT (my_floorf (-1.0f / 0.0f) == -1.0f / 0.0f); /* NaNs. */ - ASSERT (isnanf (floorf (NaNf ()))); + ASSERT (isnanf (my_floorf (NaNf ()))); return 0; }
--- a/tests/test-floorf2.c +++ b/tests/test-floorf2.c @@ -76,6 +76,9 @@ } else if (z < L_(0.0)) { + /* Work around ICC's desire to optimize denormal floats to 0. */ + if (z > -FLT_MIN) + return L_(-1.0); /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */ if (z > - TWO_MANT_DIG) {