]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Correct implementation of fmaf.
authorJakub Jelinek <jakub@redhat.com>
Mon, 11 Oct 2010 13:27:05 +0000 (09:27 -0400)
committerUlrich Drepper <drepper@gmail.com>
Mon, 11 Oct 2010 13:27:05 +0000 (09:27 -0400)
22 files changed:
ChangeLog
NEWS
include/fenv.h
math/feupdateenv.c
math/ftestexcept.c
math/libm-test.inc
sysdeps/i386/fpu/feupdateenv.c
sysdeps/i386/fpu/ftestexcept.c
sysdeps/i386/i686/multiarch/s_fmaf.c
sysdeps/ia64/fpu/feupdateenv.c
sysdeps/ia64/fpu/ftestexcept.c
sysdeps/ieee754/dbl-64/s_fmaf.c [new file with mode: 0644]
sysdeps/powerpc/fpu/feupdateenv.c
sysdeps/powerpc/fpu/ftestexcept.c
sysdeps/s390/fpu/feupdateenv.c
sysdeps/s390/fpu/ftestexcept.c
sysdeps/sh/sh4/fpu/ftestexcept.c
sysdeps/sparc/fpu/feupdateenv.c
sysdeps/sparc/fpu/ftestexcept.c
sysdeps/x86_64/fpu/feupdateenv.c
sysdeps/x86_64/fpu/ftestexcept.c
sysdeps/x86_64/multiarch/s_fmaf.c

index 36271c2e7ec96935947ac6d1109c869484f7fda7..8255ce00970e840b1c020923a9b39db35d3c9d4a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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]
diff --git a/NEWS b/NEWS
index d7027b52e4a9f8b0bcfaf3c506b3eef253ae7649..f8482c4172a6911e5f94f7249477b0e2e4cf298b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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
index 254162d45c59e67533b5788d17367efd2598c9ed..3605f8150eba113abff04262dca84d60d4602105 100644 (file)
@@ -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
index 3e6aed4fdf3f9202821437ecf58af69e0db25804..dd7a1afdb5af6d9d401bf19ca3bd1e3fcf65ee75 100644 (file)
@@ -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.
 
@@ -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)
index 4be3fb770f491d955331baf91e1ef4ad87100b4d..951d1346c544b25629ba9a10d9e1e2081b5be20e 100644 (file)
@@ -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.
 
@@ -25,5 +25,6 @@ fetestexcept (int excepts)
 {
   return 0;
 }
+libm_hidden_def (fetestexcept)
 stub_warning (fetestexcept)
 #include <stub-tag.h>
index 6650b889c54d67f415a684f874ed0869433a5d72..2d48f719c937288ce1aee89d466a5028ea76eb80 100644 (file)
@@ -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);
 }
index a58963837fb28cd88064b569a73a9b989e43b547..e283403bf77078d2c8fb945d1df967594c148ff0 100644 (file)
@@ -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.
 
@@ -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);
index 1979fe13fd00df8e33508cda4a089a72c94ab16c..1c0ae0d02cc4339b87a7bb5a0cde90dc609d58a9 100644 (file)
@@ -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.
 
@@ -38,3 +38,4 @@ fetestexcept (int excepts)
 
   return (temp | xtemp) & excepts & FE_ALL_EXCEPT;
 }
+libm_hidden_def (fetestexcept)
index 4ea9be48ac65fc10c01bf20cbaed7fcb95f82097..a52bd56e8fcf227aa02a30f677479ed320d1100a 100644 (file)
@@ -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>
index 72f12287fa09e5efee92d651e7fa59e2f68bad25..f961fdca38943aedea3d4006bb3fe2f9f3b7bf6c 100644 (file)
@@ -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.
 
@@ -38,3 +38,4 @@ feupdateenv (const fenv_t *envp)
   /* Success.  */
   return 0;
 }
+libm_hidden_def (feupdateenv)
index 64c37d8c8f3024bcd0b41f064e3bd97d3647a880..0d8190b46e53ccbdad5699cf0682bfbe1547c27a 100644 (file)
@@ -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.
 
@@ -30,3 +30,4 @@ fetestexcept (int excepts)
 
   return (fpsr >> 13) & excepts & FE_ALL_EXCEPT;
 }
+libm_hidden_def (fetestexcept)
diff --git a/sysdeps/ieee754/dbl-64/s_fmaf.c b/sysdeps/ieee754/dbl-64/s_fmaf.c
new file mode 100644 (file)
index 0000000..9721876
--- /dev/null
@@ -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
index 5fca301fe5137d0805ccdd2b1282c911e4e05dd0..9a157c54fbeed77ddc8e88990af17f1e95a3cc37 100644 (file)
@@ -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.
@@ -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);
index 64406c41dc03594634875804c32b08cb9a100519..cda11f56b439e982a285bb172446b26ab4bcb974 100644 (file)
@@ -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
@@ -31,3 +31,4 @@ fetestexcept (int excepts)
      just:  */
   return u.l[1] & excepts;
 }
+libm_hidden_def (fetestexcept)
index 64411e880be53ae0479dbfd3924d441623c30fcb..80f9687d71abcec73917bbd9e24e3a60bbb81d6f 100644 (file)
@@ -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).
 
@@ -38,3 +38,4 @@ feupdateenv (const fenv_t *envp)
   /* Success.  */
   return 0;
 }
+libm_hidden_def (feupdateenv)
index 51af57e90e4a4128d219642c313828e2f694f0c9..50d5afe3ee6d4de100ae977941e6ab02bf907d31 100644 (file)
@@ -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).
 
@@ -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)
index 17a2ccfc80d36d8a94156e4c2df921e5a6af17ed..a15868b02ce36e94440a157a49f6f4d3d72bab50 100644 (file)
@@ -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
@@ -30,3 +30,4 @@ fetestexcept (int excepts)
 
   return temp & excepts & FE_ALL_EXCEPT;
 }
+libm_hidden_def (fetestexcept)
index b2615379b98749c7496e88a79bf0a256c62d61bb..008c379a1e9decca7a9b3576c9dc72757fdc1035 100644 (file)
@@ -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
@@ -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);
index abfaa3299df0588f539b4f0c72b546ac939d9b0a..e77f513b1796dcb7b70ba44dd757ec529c0652b1 100644 (file)
@@ -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
@@ -28,3 +28,4 @@ fetestexcept (int excepts)
 
   return tmp & excepts & FE_ALL_EXCEPT;
 }
+libm_hidden_def (fetestexcept)
index e23f1affa64779f74c6f7b1e3f761e3dd7e0fb66..291c56bd1001ace0b6287b4a2bba57779703e7bf 100644 (file)
@@ -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.
 
@@ -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);
index 091c25157bcfa78180c5c5bda107885a6863df20..f3b54ad80caadfebd88a06ddf5a59b1aa4132d6c 100644 (file)
@@ -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
@@ -31,3 +31,4 @@ fetestexcept (int excepts)
 
   return (temp | mxscr) & excepts & FE_ALL_EXCEPT;
 }
+libm_hidden_def (fetestexcept)
index de1c4b6f41b492ecd87d039a3bd31983e3991f7c..85ef65a50ecb9d62cb6ab41c0865e79d7b497d31 100644 (file)
@@ -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
@@ -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>