Skip to content

Commit

Permalink
Correct implementation of fmaf.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Jelinek authored and Ulrich Drepper committed Oct 11, 2010
1 parent c579b20 commit 9ff8d36
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 19 deletions.
25 changes: 25 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
2010-10-07 Jakub Jelinek <jakub@redhat.com>

[BZ #3268]
* math/libm-test.inc (fma_test): Add 2 fmaf tests.
* sysdeps/ieee754/dbl-64/s_fmaf.c: New file.
* sysdeps/i386/i686/multiarch/s_fmaf.c: Include
sysdeps/ieee754/dbl-64/s_fmaf.c instead of math/s_fmaf.c.
* sysdeps/x86_64/multiarch/s_fmaf.c: Likewise.
* include/fenv.h (feupdateenv, fetestexcept): Add libm_hidden_proto.
* math/feupdateenv.c (feupdateenv): Add libm_hidden_ver.
* sysdeps/i386/fpu/feupdateenv.c (feupdateenv): Likewise.
* sysdeps/powerpc/fpu/feupdateenv.c (feupdateenv): Likewise.
* sysdeps/x86_64/fpu/feupdateenv.c (feupdateenv): Likewise.
* sysdeps/sparc/fpu/feupdateenv.c (feupdateenv): Likewise.
* sysdeps/ia64/fpu/feupdateenv.c (feupdateenv): Add libm_hidden_def.
* sysdeps/s390/fpu/feupdateenv.c (feupdateenv): Likewise.
* math/ftestexcept.c (fetestexcept): Likewise.
* sysdeps/ia64/fpu/ftestexcept.c (fetestexcept): Likewise.
* sysdeps/i386/fpu/ftestexcept.c (fetestexcept): Likewise.
* sysdeps/s390/fpu/ftestexcept.c (fetestexcept): Likewise.
* sysdeps/powerpc/fpu/ftestexcept.c (fetestexcept): Likewise.
* sysdeps/x86_64/fpu/ftestexcept.c (fetestexcept): Likewise.
* sysdeps/sparc/fpu/ftestexcept.c (fetestexcept): Likewise.
* sysdeps/sh/sh4/fpu/ftestexcept.c (fetestexcept): Likewise.

2010-10-11 Ulrich Drepper <drepper@gmail.com>

[BZ #12107]
Expand Down
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Version 2.13

* The following bugs are resolved with this release:

7066, 10851, 11611, 11640, 11701, 11840, 11856, 11883, 11903, 11904,
3268, 7066, 10851, 11611, 11640, 11701, 11840, 11856, 11883, 11903, 11904,
11968, 11979, 12005, 12037, 12067, 12077, 12092, 12107

* New Linux interfaces: prlimit, prlimit64, fanotify_init, fanotify_mark
Expand Down
2 changes: 2 additions & 0 deletions include/fenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ libm_hidden_proto (fegetenv)
libm_hidden_proto (fesetenv)
libm_hidden_proto (fesetround)
libm_hidden_proto (feholdexcept)
libm_hidden_proto (feupdateenv)
libm_hidden_proto (fetestexcept)

#endif
3 changes: 2 additions & 1 deletion math/feupdateenv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Install given floating-point environment and raise exceptions.
Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
Copyright (C) 1997, 1999, 2000, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
Expand Down Expand Up @@ -31,6 +31,7 @@ __feupdateenv (const fenv_t *envp)
strong_alias (__feupdateenv, __old_feupdateenv)
compat_symbol (libm, __old_feupdateenv, feupdateenv, GLIBC_2_1);
#endif
libm_hidden_ver (__feupdateenv, feupdateenv)
versioned_symbol (libm, __feupdateenv, feupdateenv, GLIBC_2_2);

stub_warning (feupdateenv)
Expand Down
3 changes: 2 additions & 1 deletion math/ftestexcept.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Test exception in current environment.
Copyright (C) 1997 Free Software Foundation, Inc.
Copyright (C) 1997, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
Expand All @@ -25,5 +25,6 @@ fetestexcept (int excepts)
{
return 0;
}
libm_hidden_def (fetestexcept)
stub_warning (fetestexcept)
#include <stub-tag.h>
4 changes: 4 additions & 0 deletions math/libm-test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2789,6 +2789,10 @@ fma_test (void)
TEST_fff_f (fma, minus_infty, minus_infty, minus_infty, nan_value, INVALID_EXCEPTION);

TEST_fff_f (fma, 1.25L, 0.75L, 0.0625L, 1.0L);
#ifdef TEST_FLOAT
TEST_fff_f (fma, 0x1.7ff8p+13, 0x1.000002p+0, 0x1.ffffp-24, 0x1.7ff802p+13);
TEST_fff_f (fma, 0x1.fffp+0, 0x1.00001p+0, -0x1.fffp+0, 0x1.fffp-20);
#endif

END (fma);
}
Expand Down
3 changes: 2 additions & 1 deletion sysdeps/i386/fpu/feupdateenv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Install given floating-point environment and raise exceptions.
Copyright (C) 1997,99,2000,01,07 Free Software Foundation, Inc.
Copyright (C) 1997,99,2000,01,07,2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
Expand Down Expand Up @@ -57,4 +57,5 @@ strong_alias (__feupdateenv, __old_feupdateenv)
compat_symbol (libm, BP_SYM (__old_feupdateenv), BP_SYM (feupdateenv), GLIBC_2_1);
#endif

libm_hidden_ver (__feupdateenv, feupdateenv)
versioned_symbol (libm, BP_SYM (__feupdateenv), BP_SYM (feupdateenv), GLIBC_2_2);
3 changes: 2 additions & 1 deletion sysdeps/i386/fpu/ftestexcept.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Test exception in current environment.
Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc.
Copyright (C) 1997, 2003, 2004, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
Expand Down Expand Up @@ -38,3 +38,4 @@ fetestexcept (int excepts)

return (temp | xtemp) & excepts & FE_ALL_EXCEPT;
}
libm_hidden_def (fetestexcept)
2 changes: 1 addition & 1 deletion sysdeps/i386/i686/multiarch/s_fmaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ weak_alias (__fmaf, fmaf)
# define __fmaf __fmaf_ia32
#endif

#include <math/s_fmaf.c>
#include <sysdeps/ieee754/dbl-64/s_fmaf.c>
3 changes: 2 additions & 1 deletion sysdeps/ia64/fpu/feupdateenv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Install given floating-point environment and raise exceptions.
Copyright (C) 1997, 2000, 2007 Free Software Foundation, Inc.
Copyright (C) 1997, 2000, 2007, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Christian Boissat <Christian.Boissat@cern.ch>, 1999.
Expand Down Expand Up @@ -38,3 +38,4 @@ feupdateenv (const fenv_t *envp)
/* Success. */
return 0;
}
libm_hidden_def (feupdateenv)
3 changes: 2 additions & 1 deletion sysdeps/ia64/fpu/ftestexcept.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Test exception in current environment.
Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
Copyright (C) 1997, 1999, 2000, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Christian Boissat <Christian.Boissat@cern.ch>, 1999.
Expand Down Expand Up @@ -30,3 +30,4 @@ fetestexcept (int excepts)

return (fpsr >> 13) & excepts & FE_ALL_EXCEPT;
}
libm_hidden_def (fetestexcept)
50 changes: 50 additions & 0 deletions sysdeps/ieee754/dbl-64/s_fmaf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Compute x * y + z as ternary operation.
Copyright (C) 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <jakub@redhat.com>, 2010.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

#include <math.h>
#include <fenv.h>
#include <ieee754.h>

/* This implementation relies on double being more than twice as
precise as float and uses rounding to odd in order to avoid problems
with double rounding.
See a paper by Boldo and Melquiond:
http://www.lri.fr/~melquion/doc/08-tc.pdf */

float
__fmaf (float x, float y, float z)
{
fenv_t env;
/* Multiplication is always exact. */
double temp = (double) x * (double) y;
union ieee754_double u;
feholdexcept (&env);
fesetround (FE_TOWARDZERO);
/* Perform addition with round to odd. */
u.d = temp + (double) z;
if ((u.ieee.mantissa1 & 1) == 0 && u.ieee.exponent != 0xff)
u.ieee.mantissa1 |= fetestexcept (FE_INEXACT) != 0;
feupdateenv (&env);
/* And finally truncation with round to nearest. */
return (float) u.d;
}
#ifndef __fmaf
weak_alias (__fmaf, fmaf)
#endif
3 changes: 2 additions & 1 deletion sysdeps/powerpc/fpu/feupdateenv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Install given floating-point environment and raise exceptions.
Copyright (C) 1997, 1999, 2000, 2001, 2007, 2008
Copyright (C) 1997, 1999, 2000, 2001, 2007, 2008, 2010
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
Expand Down Expand Up @@ -66,4 +66,5 @@ strong_alias (__feupdateenv, __old_feupdateenv)
compat_symbol (libm, BP_SYM (__old_feupdateenv), BP_SYM (feupdateenv), GLIBC_2_1);
#endif

libm_hidden_ver (__feupdateenv, feupdateenv)
versioned_symbol (libm, BP_SYM (__feupdateenv), BP_SYM (feupdateenv), GLIBC_2_2);
3 changes: 2 additions & 1 deletion sysdeps/powerpc/fpu/ftestexcept.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Test exception in current environment.
Copyright (C) 1997 Free Software Foundation, Inc.
Copyright (C) 1997, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -31,3 +31,4 @@ fetestexcept (int excepts)
just: */
return u.l[1] & excepts;
}
libm_hidden_def (fetestexcept)
3 changes: 2 additions & 1 deletion sysdeps/s390/fpu/feupdateenv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Install given floating-point environment and raise exceptions.
Copyright (C) 2000 Free Software Foundation, Inc.
Copyright (C) 2000, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Denis Joseph Barrow (djbarrow@de.ibm.com).
Expand Down Expand Up @@ -38,3 +38,4 @@ feupdateenv (const fenv_t *envp)
/* Success. */
return 0;
}
libm_hidden_def (feupdateenv)
3 changes: 2 additions & 1 deletion sysdeps/s390/fpu/ftestexcept.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Test exception in current environment.
Copyright (C) 2000 Free Software Foundation, Inc.
Copyright (C) 2000, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Denis Joseph Barrow (djbarrow@de.ibm.com).
Expand Down Expand Up @@ -31,3 +31,4 @@ fetestexcept (int excepts)
temp = (temp >> FPC_DXC_SHIFT) | (temp >> FPC_FLAGS_SHIFT);
return temp & excepts & FE_ALL_EXCEPT;
}
libm_hidden_def (fetestexcept)
3 changes: 2 additions & 1 deletion sysdeps/sh/sh4/fpu/ftestexcept.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Test exception in current environment.
Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc.
Copyright (C) 1997, 1998, 2000, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -30,3 +30,4 @@ fetestexcept (int excepts)

return temp & excepts & FE_ALL_EXCEPT;
}
libm_hidden_def (fetestexcept)
3 changes: 2 additions & 1 deletion sysdeps/sparc/fpu/feupdateenv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Install given floating-point environment and raise exceptions.
Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
Copyright (C) 1997, 1999, 2000, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -46,4 +46,5 @@ strong_alias (__feupdateenv, __old_feupdateenv)
compat_symbol (libm, __old_feupdateenv, feupdateenv, GLIBC_2_1);
#endif

libm_hidden_ver (__feupdateenv, feupdateenv)
versioned_symbol (libm, __feupdateenv, feupdateenv, GLIBC_2_2);
3 changes: 2 additions & 1 deletion sysdeps/sparc/fpu/ftestexcept.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Test exception in current environment.
Copyright (C) 1997 Free Software Foundation, Inc.
Copyright (C) 1997, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -28,3 +28,4 @@ fetestexcept (int excepts)

return tmp & excepts & FE_ALL_EXCEPT;
}
libm_hidden_def (fetestexcept)
3 changes: 2 additions & 1 deletion sysdeps/x86_64/fpu/feupdateenv.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Install given floating-point environment and raise exceptions.
Copyright (C) 1997,99,2000,01,07 Free Software Foundation, Inc.
Copyright (C) 1997,99,2000,01,07,2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
Expand Down Expand Up @@ -48,4 +48,5 @@ strong_alias (__feupdateenv, __old_feupdateenv)
compat_symbol (libm, __old_feupdateenv, feupdateenv, GLIBC_2_1);
#endif

libm_hidden_ver (__feupdateenv, feupdateenv)
versioned_symbol (libm, __feupdateenv, feupdateenv, GLIBC_2_2);
3 changes: 2 additions & 1 deletion sysdeps/x86_64/fpu/ftestexcept.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Test exception in current environment.
Copyright (C) 2001 Free Software Foundation, Inc.
Copyright (C) 2001, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -31,3 +31,4 @@ fetestexcept (int excepts)

return (temp | mxscr) & excepts & FE_ALL_EXCEPT;
}
libm_hidden_def (fetestexcept)
4 changes: 2 additions & 2 deletions sysdeps/x86_64/multiarch/s_fmaf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* FMA version of fmaf.
Copyright (C) 2009 Free Software Foundation, Inc.
Copyright (C) 2009, 2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -39,4 +39,4 @@ weak_alias (__fmaf, fmaf)
# define __fmaf __fmaf_sse2
#endif

#include <math/s_fmaf.c>
#include <sysdeps/ieee754/dbl-64/s_fmaf.c>

0 comments on commit 9ff8d36

Please sign in to comment.