This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, i386]: Committed: Prevent NaNs for sqrt(0.0) with -mrecip
- From: "Uros Bizjak" <ubizjak at gmail dot com>
- To: tbp <tbptbp at gmail dot com>
- Cc: "Richard Guenther" <richard dot guenther at gmail dot com>, "GCC Patches" <gcc-patches at gcc dot gnu dot org>, "Giovanni Bajo" <rasky at develer dot com>, "Bradley Lucier" <lucier at math dot purdue dot edu>, "Roger Sayle" <roger at eyesopen dot com>
- Date: Tue, 19 Jun 2007 13:25:41 +0200
- Subject: [PATCH, i386]: Committed: Prevent NaNs for sqrt(0.0) with -mrecip
Hello!
> My point merely was that, considering one operation, you'd introduce
> NaN for a not so special value (0) which, in a *fast* math scenario,
> could be produced at any previous stage due to denormal clamping; with
> no sane way to take care of.
> Again, if you look at prior art (icc, AMD's manual...), that's the
> only special case they covered.
Attached patch fixes -mrecip for sqrt(0.0). Patch was tested on
i686-pc-linux-gnu, and is committed to mainline SVN.
2007-06-18 Uros Bizjak <ubizjak@gmail.com>
* config/i386/i386.c (ix86_emit_swsqrtsf): Limit the result of
rsqrt insn to FLT_MAX to avoid NaN for zero input argument.
Uros.
Index: i386.c
===================================================================
--- i386.c (revision 125790)
+++ i386.c (working copy)
@@ -22590,7 +22590,7 @@
void ix86_emit_swsqrtsf (rtx res, rtx a, enum machine_mode mode,
bool recip)
{
- rtx x0, e0, e1, e2, e3, three, half;
+ rtx x0, e0, e1, e2, e3, three, half, bignum;
x0 = gen_reg_rtx (mode);
e0 = gen_reg_rtx (mode);
@@ -22600,15 +22600,18 @@
three = CONST_DOUBLE_FROM_REAL_VALUE (dconst3, SFmode);
half = CONST_DOUBLE_FROM_REAL_VALUE (dconsthalf, SFmode);
+ bignum = gen_lowpart (SFmode, GEN_INT (0x7f7fffff));
if (VECTOR_MODE_P (mode))
{
three = ix86_build_const_vector (SFmode, true, three);
half = ix86_build_const_vector (SFmode, true, half);
+ bignum = ix86_build_const_vector (SFmode, true, bignum);
}
three = force_reg (mode, three);
half = force_reg (mode, half);
+ bignum = force_reg (mode, bignum);
/* sqrt(a) = 0.5 * a * rsqrtss(a) * (3.0 - a * rsqrtss(a) * rsqrtss(a))
1.0 / sqrt(a) = 0.5 * rsqrtss(a) * (3.0 - a * rsqrtss(a) * rsqrtss(a)) */
@@ -22617,6 +22620,9 @@
emit_insn (gen_rtx_SET (VOIDmode, x0,
gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
UNSPEC_RSQRT)));
+ emit_insn (gen_rtx_SET (VOIDmode, x0,
+ gen_rtx_SMIN (mode, x0, bignum)));
+
/* e0 = x0 * a */
emit_insn (gen_rtx_SET (VOIDmode, e0,
gen_rtx_MULT (mode, x0, a)));