about summary refs log tree commit diff
path: root/math/w_llogb_template.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2016-12-02 01:42:49 +0000
committerJoseph Myers <joseph@codesourcery.com>2016-12-02 01:42:49 +0000
commit55a38f82369669e181a05bcf2ac6c647dcd9b261 (patch)
tree5ecf72dbb2673caa4e87a91b46fdc9a3af66db7d /math/w_llogb_template.c
parent6dc07416777012947152edaf5b7848c9e62c2fc8 (diff)
downloadglibc-55a38f82369669e181a05bcf2ac6c647dcd9b261.tar.gz
glibc-55a38f82369669e181a05bcf2ac6c647dcd9b261.tar.xz
glibc-55a38f82369669e181a05bcf2ac6c647dcd9b261.zip
Add llogb, llogbf, llogbl.
TS 18661-1 defines llogb functions that are like ilogb except that
they return long int instead of int.  Corresponding FP_LLOGB* macros
are defined, whose values are required to have the obvious
correspondence to those of the FP_ILOGB* macros.

This patch implements these functions and macros for glibc.  llogb
uses the type-generic infrastructure, with an implementation similar
to the wrapper for ilogb but with additional conversion from FP_ILOGB*
to FP_LLOGB*; this approach avoids needing to modify or duplicate any
of the architecture-specific ilogb implementations.  Tests are also
based on those for ilogb.

Ideally the llogb functions would alias the ilogb ones when long is
32-bit, but such aliasing requires the associated header declarations
of the different-type alias to be hidden, typically by defining macros
before including the header (see e.g. how
sysdeps/ieee754/dbl-64/wordsize-64/s_llround.c defines lround to
__hidden_lround before including <math.h>).  The infrastructure for
type-generic function implementations does not support defining such
macros at present (since C code can't define a macro whose name is
determined by other macros).  So this patch leaves them as separate
functions (similar to e.g. scalbln and scalbn being separate in such a
case as well), but with the remapping of FP_ILOGB* to FP_LLOGB*
conditioned out in the case where it would be the identity map.

Tested for x86_64, x86, mips64 and powerpc.

	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (llogb):
	New declaration.
	* math/tgmath.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (llogb): New
	macro.
	* math/math.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (__FP_LONG_MAX):
	New macro.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (FP_LLOGB0): Likewise.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (FP_LLOGBNAN): Likewise.
	* math/Versions (llogb): New libm symbol at version GLIBC_2.25.
	(llogbf): Likewise.
	(llogbl): Likewise.
	* math/Makefile (gen-libm-calls): Add w_llogbF.
	(tests): Add test-fp-llogb-constants.
	* math/w_llogb_template.c: New file.  Based on
	math/w_ilogb_template.c.
	* math/libm-test.inc (llogb_test_data): New array.
	(llogb_test): New function.
	(main): Call llogb_test.
	* math/test-fp-llogb-constants.c: New file.  Based on
	math/test-fp-ilogb-constants.c.
	* math/test-tgmath-ret.c (llogb): New CHECK_RET_CONST call.
	(do_test): Call check_return_llogb.
	* math/test-tgmath.c (NCALLS): Increase to 126.
	(F(compile_test)): Call llogb.
	(F(llogb)): New function.
	* manual/math.texi (Exponents and Logarithms): Document llogb,
	llogbf, llogbl, FP_LLOGB0 and FP_LLOGBNAN.
	* manual/libm-err-tab.pl (@all_functions): Add llogb.
	* sysdeps/ieee754/ldbl-opt/nldbl-llogb.c: New file.
	* sysdeps/ieee754/ldbl-opt/w_llogbl.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add llogb.
	(CFLAGS-nldbl-llogb.c): New variable.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
Diffstat (limited to 'math/w_llogb_template.c')
-rw-r--r--math/w_llogb_template.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/math/w_llogb_template.c b/math/w_llogb_template.c
new file mode 100644
index 0000000000..9065bf9b4f
--- /dev/null
+++ b/math/w_llogb_template.c
@@ -0,0 +1,46 @@
+/* Wrapper to implement llogb in terms of ilogb.
+   Copyright (C) 2012-2016 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
+   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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <errno.h>
+#include <limits.h>
+#include <math_private.h>
+
+long int
+M_DECL_FUNC (__llogb) (FLOAT x)
+{
+  int r = M_SUF (__ieee754_ilogb) (x);
+  long int lr = r;
+  if (__glibc_unlikely (r == FP_ILOGB0)
+      || __glibc_unlikely (r == FP_ILOGBNAN)
+      || __glibc_unlikely (r == INT_MAX))
+    {
+#if LONG_MAX != INT_MAX
+      if (r == FP_ILOGB0)
+	lr = FP_LLOGB0;
+      else if (r == FP_ILOGBNAN)
+	lr = FP_LLOGBNAN;
+      else
+	lr = LONG_MAX;
+#endif
+      __set_errno (EDOM);
+      __feraiseexcept (FE_INVALID);
+    }
+  return lr;
+}
+declare_mgen_alias (__llogb, llogb)