Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix x86 / x86_64 expl / expl10l wild results in directed rounding mod…
…es (bug 16356).

This patch fixes bug 16356, bad results from x86 / x86_64 expl /
exp10l in directed rounding modes, the most serious of the bugs shown
up by my patch expanding libm test coverage.  When I fixed bug 16293,
I thought it was only necessary to set round-to-nearest when using
frndint in expm1 functions, because in other cases the cancellation
error from having the resulting fractional part close to 1 or -1 would
not be significant.  However, in expl and exp10l, the way the final
fractional part gets computed (something more complicated than a
simple subtraction, because more precision is needed than you'd get
that way) can result in a value outside the range [-1, 1] when the
argument to frndint was very close to an integer and was rounded the
"wrong" way because of the rounding mode - and the f2xm1 instruction
has undefined results if its argument is outside [-1, 1], so resulting
in the large errors seen.  So this patch removes the USE_AS_EXPM1L
conditionals on the round-to-nearest settings, so all of expl, expm1l
and exp10l now get round-to-nearest used for frndint (meaning the
final fractional part can at most be slightly above 0.5 in
magnitude).  Associated tests of exp and exp10 are added and testing
of exp10 in directed rounding modes enabled.

Tested x86_64 and x86 and ulps updated accordingly.

	* sysdeps/i386/fpu/e_expl.S (IEEE754_EXPL): Also set
	round-to-nearest for [!USE_AS_EXPM1L].
	* sysdeps/x86_64/fpu/e_expl.S (IEEE754_EXPL): Likewise.
	* math/auto-libm-test-in: Do not expect cosh tests to fail.  Add
	more tests of exp and exp10.  Expect some exp10 tests to miss
	exceptions or fail in directed rounding modes.
	* math/auto-libm-test-out: Regenerated.
	* math/libm-test.inc (exp10_tonearest_test_data): New array.
	(exp10_test_tonearest): New function.
	(exp10_towardzero_test_data): New array.
	(exp10_test_towardzero): New function.
	(exp10_downward_test_data): New array.
	(exp10_test_downward): New function.
	(exp10_upward_test_data): New array.
	(exp10_test_upward): New function.
	(main): Call the new functions.
	* sysdeps/i386/fpu/libm-test-ulps: Update.
	* sysdeps/x86_64/fpu/libm-test-ulps: Likewise.
  • Loading branch information
Joseph Myers committed Dec 21, 2013
1 parent 31e3a40 commit 5b0626b
Show file tree
Hide file tree
Showing 9 changed files with 1,059 additions and 550 deletions.
22 changes: 22 additions & 0 deletions ChangeLog
@@ -1,3 +1,25 @@
2013-12-21 Joseph Myers <joseph@codesourcery.com>

[BZ #16356]
* sysdeps/i386/fpu/e_expl.S (IEEE754_EXPL): Also set
round-to-nearest for [!USE_AS_EXPM1L].
* sysdeps/x86_64/fpu/e_expl.S (IEEE754_EXPL): Likewise.
* math/auto-libm-test-in: Do not expect cosh tests to fail. Add
more tests of exp and exp10. Expect some exp10 tests to miss
exceptions or fail in directed rounding modes.
* math/auto-libm-test-out: Regenerated.
* math/libm-test.inc (exp10_tonearest_test_data): New array.
(exp10_test_tonearest): New function.
(exp10_towardzero_test_data): New array.
(exp10_test_towardzero): New function.
(exp10_downward_test_data): New array.
(exp10_test_downward): New function.
(exp10_upward_test_data): New array.
(exp10_test_upward): New function.
(main): Call the new functions.
* sysdeps/i386/fpu/libm-test-ulps: Update.
* sysdeps/x86_64/fpu/libm-test-ulps: Likewise.

2013-12-20 Joseph Myers <joseph@codesourcery.com>

* math/auto-libm-test-in: Add more tests of acos, acosh, asin,
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Expand Up @@ -22,7 +22,7 @@ Version 2.19
15966, 15985, 15988, 15997, 16032, 16034, 16036, 16037, 16038, 16041,
16055, 16071, 16072, 16074, 16077, 16078, 16103, 16112, 16143, 16144,
16146, 16150, 16151, 16153, 16167, 16172, 16195, 16214, 16245, 16271,
16274, 16283, 16289, 16293, 16314, 16316, 16330, 16338.
16274, 16283, 16289, 16293, 16314, 16316, 16330, 16338, 16356.

* The public headers no longer use __unused nor __block. This change is to
support compiling programs that are derived from BSD sources and use
Expand Down
27 changes: 17 additions & 10 deletions math/auto-libm-test-in
Expand Up @@ -519,11 +519,10 @@ cosh 0x2.c679d1f73f0fap+8
cosh 0x2.c679d1f73f0fcp+8
cosh -0x2.c679d1f73f0fap+8
cosh -0x2.c679d1f73f0fcp+8
# Bug 16356: bad results from expl (and so coshl) in round-upward mode.
cosh 0x2.c679d1f73f0fb624d358b213a7p+8 xfail-rounding:ldbl-96-intel:x86 xfail-rounding:ldbl-96-intel:x86_64
cosh 0x2.c679d1f73f0fb624d358b213a8p+8 xfail-rounding:ldbl-96-intel:x86 xfail-rounding:ldbl-96-intel:x86_64
cosh -0x2.c679d1f73f0fb624d358b213a7p+8 xfail-rounding:ldbl-96-intel:x86 xfail-rounding:ldbl-96-intel:x86_64
cosh -0x2.c679d1f73f0fb624d358b213a8p+8 xfail-rounding:ldbl-96-intel:x86 xfail-rounding:ldbl-96-intel:x86_64
cosh 0x2.c679d1f73f0fb624d358b213a7p+8
cosh 0x2.c679d1f73f0fb624d358b213a8p+8
cosh -0x2.c679d1f73f0fb624d358b213a7p+8
cosh -0x2.c679d1f73f0fb624d358b213a8p+8
cosh 0x2.c5d37700c6bb03a4p+12 no-test-inline
cosh 0x2.c5d37700c6bb03a8p+12 no-test-inline
cosh -0x2.c5d37700c6bb03a4p+12 no-test-inline
Expand Down Expand Up @@ -712,6 +711,7 @@ exp 1000.0 xfail-rounding:dbl-64
exp 710 xfail-rounding:dbl-64
exp -1234
# Bug 16284: results on directed rounding may be incorrect.
exp 0x2.c679d1f73f0fb628p+8 xfail-rounding:dbl-64
exp 1e5 xfail-rounding:dbl-64
exp max xfail-rounding:dbl-64
exp -7.4444006192138124e+02
Expand All @@ -726,15 +726,22 @@ exp10 36
exp10 -36
exp10 305
exp10 -305
exp10 4932
exp10 -4932
exp10 1e5
# Bug 16284: results on directed rounding may be incorrect.
exp10 4932 xfail-rounding:flt-32
# Bug 16361: underflow exception may be misssing
exp10 -4932 missing-underflow:ldbl-96-intel:x86 missing-underflow:ldbl-96-intel:x86_64
# Bug 16284: results on directed rounding may be incorrect.
exp10 1e5 xfail-rounding:flt-32
exp10 -1e5
exp10 1e6
# Bug 16284: results on directed rounding may be incorrect.
exp10 1e6 xfail-rounding:flt-32
exp10 -1e6
exp10 max
# Bug 16284: results on directed rounding may be incorrect.
exp10 max xfail-rounding:flt-32
exp10 -max
exp10 0.75
# Bug 16284: results on directed rounding may be incorrect.
exp10 0x1.348e45573a1dd72cp+8 xfail-rounding:flt-32 xfail-rounding:dbl-64

exp2 0
exp2 -0
Expand Down
1,254 changes: 732 additions & 522 deletions math/auto-libm-test-out

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions math/libm-test.inc
Expand Up @@ -7280,6 +7280,62 @@ exp10_test (void)
END;
}


static const struct test_f_f_data exp10_tonearest_test_data[] =
{
AUTO_TESTS_f_f (exp10, tonearest),
};

static void
exp10_test_tonearest (void)
{
START (exp10_tonearest);
RUN_TEST_LOOP_f_f (exp10, exp10_tonearest_test_data, FE_TONEAREST);
END;
}


static const struct test_f_f_data exp10_towardzero_test_data[] =
{
AUTO_TESTS_f_f (exp10, towardzero),
};

static void
exp10_test_towardzero (void)
{
START (exp10_towardzero);
RUN_TEST_LOOP_f_f (exp10, exp10_towardzero_test_data, FE_TOWARDZERO);
END;
}


static const struct test_f_f_data exp10_downward_test_data[] =
{
AUTO_TESTS_f_f (exp10, downward),
};

static void
exp10_test_downward (void)
{
START (exp10_downward);
RUN_TEST_LOOP_f_f (exp10, exp10_downward_test_data, FE_DOWNWARD);
END;
}


static const struct test_f_f_data exp10_upward_test_data[] =
{
AUTO_TESTS_f_f (exp10, upward),
};

static void
exp10_test_upward (void)
{
START (exp10_upward);
RUN_TEST_LOOP_f_f (exp10, exp10_upward_test_data, FE_UPWARD);
END;
}

static void
pow10_test (void)
{
Expand Down Expand Up @@ -12819,6 +12875,10 @@ main (int argc, char **argv)
exp_test_downward ();
exp_test_upward ();
exp10_test ();
exp10_test_tonearest ();
exp10_test_towardzero ();
exp10_test_downward ();
exp10_test_upward ();
exp2_test ();
expm1_test ();
expm1_test_tonearest ();
Expand Down
4 changes: 0 additions & 4 deletions sysdeps/i386/fpu/e_expl.S
Expand Up @@ -130,7 +130,6 @@ ENTRY(IEEE754_EXPL)
#endif
3: FLDLOG /* 1 log2(base) */
fmul %st(1), %st /* 1 x log2(base) */
#ifdef USE_AS_EXPM1L
/* Set round-to-nearest temporarily. */
subl $8, %esp
cfi_adjust_cfa_offset (8)
Expand All @@ -139,15 +138,12 @@ ENTRY(IEEE754_EXPL)
andl 4(%esp), %edx
movl %edx, (%esp)
fldcw (%esp)
#endif
frndint /* 1 i */
fld %st(1) /* 2 x */
frndint /* 2 xi */
#ifdef USE_AS_EXPM1L
fldcw 4(%esp)
addl $8, %esp
cfi_adjust_cfa_offset (-8)
#endif
fld %st(1) /* 3 i */
fldt MO(c0) /* 4 c0 */
fld %st(2) /* 5 xi */
Expand Down
114 changes: 109 additions & 5 deletions sysdeps/i386/fpu/libm-test-ulps
Expand Up @@ -7095,6 +7095,10 @@ Test "cosh_downward (-0x2.c5e3bp+8)":
ildouble: 1
Test "cosh_downward (-0x2.c679d1f73f0fap+8)":
ildouble: 2
Test "cosh_downward (-0x2.c679d1f73f0fb624p+8)":
ildouble: 2
Test "cosh_downward (-0x2.c679d1f73f0fb628p+8)":
ildouble: 2
Test "cosh_downward (-0x2.c679d1f73f0fcp+8)":
ildouble: 1
Test "cosh_downward (-0x2.c679dp+8)":
Expand Down Expand Up @@ -7181,15 +7185,25 @@ Test "cosh_towardzero (-0x2.c5d37700c6bbp+12)":
ldouble: 2
Test "cosh_towardzero (-0x2.c5e3acd2922a6p+8)":
ildouble: 1
Test "cosh_towardzero (-0x2.c679d1f73f0fap+8)":
ildouble: 2
Test "cosh_towardzero (-0x2.c679d1f73f0fb624p+8)":
ildouble: 2
Test "cosh_towardzero (-0x2.c679d1f73f0fb628p+8)":
ildouble: 2
Test "cosh_towardzero (-0x2.c679dp+8)":
double: 1
ildouble: 1
Test "cosh_towardzero (-0x5.96a7ep+4)":
double: 1
ildouble: 2
ldouble: 1
Test "cosh_towardzero (0x1.6p+4)":
ildouble: 1
ldouble: 2
Test "cosh_towardzero (0x1.8p+4)":
ildouble: 1
ldouble: 1
Test "cosh_towardzero (0x2.c5d374p+12)":
ldouble: 1
Test "cosh_towardzero (0x2.c5d37700c6bb03a4p+12)":
Expand Down Expand Up @@ -7240,6 +7254,11 @@ ildouble: 1
Test "cosh_upward (-0x2.c679d1f73f0fap+8)":
double: 1
ildouble: 1
Test "cosh_upward (-0x2.c679d1f73f0fb624p+8)":
ildouble: 1
Test "cosh_upward (-0x2.c679d1f73f0fb628p+8)":
ildouble: 1
ldouble: 1
Test "cosh_upward (-0x2.c679d1f73f0fcp+8)":
ildouble: 1
Test "cosh_upward (-0x2p-16384)":
Expand Down Expand Up @@ -7292,6 +7311,11 @@ ildouble: 1
Test "cosh_upward (0x2.c679d1f73f0fap+8)":
double: 1
ildouble: 1
Test "cosh_upward (0x2.c679d1f73f0fb624p+8)":
ildouble: 1
Test "cosh_upward (0x2.c679d1f73f0fb628p+8)":
ildouble: 2
ldouble: 1
Test "cosh_upward (0x2.c679d1f73f0fcp+8)":
ildouble: 1
Test "cosh_upward (0x2.c679d4p+8)":
Expand Down Expand Up @@ -8323,11 +8347,13 @@ Test "Real part of: ctan_towardzero (0x1p+0 + 0x1.63p+8 i)":
ildouble: 1
ldouble: 1
Test "Real part of: ctan_towardzero (0x1p+0 + 0x1.6dp+8 i)":
ildouble: 1
ldouble: 1
ildouble: 2
ldouble: 2
Test "Real part of: ctan_towardzero (0x1p+0 + 0x2.dp+4 i)":
double: 1
idouble: 1
ildouble: 1
ldouble: 1
Test "Real part of: ctan_towardzero (0x1p+0 + 0x2.fp+4 i)":
double: 1
idouble: 1
Expand Down Expand Up @@ -8361,6 +8387,9 @@ double: 1
idouble: 1
ildouble: 1
ldouble: 1
Test "Imaginary part of: ctan_towardzero (0xcp-4 + 0x1.4p+0 i)":
ildouble: 2
ldouble: 2
Test "Real part of: ctan_towardzero (0xf.ffffffffffff8p+1020 + 0x1p+0 i)":
double: 1
idouble: 1
Expand Down Expand Up @@ -9188,8 +9217,8 @@ Test "Imaginary part of: ctanh_towardzero (0x1.63p+8 + 0x1p+0 i)":
ildouble: 1
ldouble: 1
Test "Imaginary part of: ctanh_towardzero (0x1.6dp+8 + 0x1p+0 i)":
ildouble: 1
ldouble: 1
ildouble: 2
ldouble: 2
Test "Imaginary part of: ctanh_towardzero (0x1p+0 + 0x8p+1020 i)":
double: 1
idouble: 1
Expand Down Expand Up @@ -9235,6 +9264,8 @@ ldouble: 1
Test "Imaginary part of: ctanh_towardzero (0x2.dp+4 + 0x1p+0 i)":
double: 1
idouble: 1
ildouble: 1
ldouble: 1
Test "Imaginary part of: ctanh_towardzero (0x2.fp+4 + 0x1p+0 i)":
double: 1
idouble: 1
Expand Down Expand Up @@ -9697,6 +9728,48 @@ Test "exp10 (0xcp-4)":
ildouble: 1
ldouble: 1

# exp10_downward
Test "exp10_downward (0x1.348e45573a1dd72cp+8)":
ildouble: 2
ldouble: 2
Test "exp10_downward (0x3p+0)":
double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 1
ldouble: 1

# exp10_tonearest
Test "exp10_tonearest (0xcp-4)":
ildouble: 1
ldouble: 1

# exp10_towardzero
Test "exp10_towardzero (-0x1p+0)":
ildouble: 1
ldouble: 1
Test "exp10_towardzero (0x1.344p+12)":
ildouble: 1
ldouble: 1
Test "exp10_towardzero (0x3p+0)":
double: 1
float: 1
idouble: 1
ifloat: 1

# exp10_upward
Test "exp10_upward (0x1.344p+12)":
ildouble: 1
ldouble: 1
Test "exp10_upward (0x3p+0)":
double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 1
ldouble: 1

# exp_downward
Test "exp_downward (0x2.c5cp+8)":
double: 1
Expand Down Expand Up @@ -9788,6 +9861,9 @@ ldouble: 1
Test "exp_upward (-0x2.e870a7e5e88cp+8)":
ildouble: 1
ldouble: 1
Test "exp_upward (0x2.c679d1f73f0fb628p+8)":
ildouble: 1
ldouble: 1
Test "exp_upward (1)":
double: 1
float: 1
Expand Down Expand Up @@ -14500,7 +14576,7 @@ double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 1
ildouble: 2
ldouble: 3

Function: "cosh_upward":
Expand Down Expand Up @@ -14740,6 +14816,34 @@ Function: "exp10":
ildouble: 1
ldouble: 1

Function: "exp10_downward":
double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 2
ldouble: 2

Function: "exp10_tonearest":
ildouble: 1
ldouble: 1

Function: "exp10_towardzero":
double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 1
ldouble: 1

Function: "exp10_upward":
double: 1
float: 1
idouble: 1
ifloat: 1
ildouble: 1
ldouble: 1

Function: "exp_downward":
double: 1
float: 1
Expand Down

0 comments on commit 5b0626b

Please sign in to comment.