From 525f803984f278e65dc07ca1156bdeca63755810 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 20 Dec 2016 00:46:53 +0000 Subject: Add fmaxmag, fminmag functions. TS 18661-1 defines fmaxmag and fminmag functions that return the argument with maximum / minimum magnitude (acting like fmax / fmin if the arguments have the same magnitude or either argument is a NaN). These correspond to the IEEE 754-2008 operations maxNumMag and minNumMag. This patch implements these functions for glibc. They are implemented with type-generic templates. Tests are based on those for fmax and fmin. Tested for x86_64, x86, mips64 and powerpc. * math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (fmaxmag): New declaration. (fminmag): Likewise. * math/tgmath.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (fmaxmag): New macro. [__GLIBC_USE (IEC_60559_BFP_EXT)] (fminmag): Likewise. * math/Versions (fmaxmag): New libm symbol at version GLIBC_2.25. (fmaxmagf): Likewise. (fmaxmagl): Likewise. (fminmag): Likewise. (fminmagf): Likewise. (fminmagl): Likewise. * math/Makefile (gen-libm-calls): Add s_fmaxmagF and s_fminmagF. * math/s_fmaxmag_template.c: New file. * math/s_fminmag_template.c: Likewise. * math/libm-test.inc (fmaxmag_test_data): New array. (fmaxmag_test): New function. (fminmag_test_data): New array. (fminmag_test): New function. (main): Call fmaxmag_test and fminmag_test. * math/test-tgmath.c (NCALLS): Increase to 132. (F(compile_test)): Call fmaxmag and fminmag. (F(fminmag)): New function. (F(fmaxmag)): Likewise. * manual/arith.texi (Misc FP Arithmetic): Document fminmag, fminmagf, fminmagl, fmaxmag, fmaxmagf and fmaxmagl. * manual/libm-err-tab.pl (@all_functions): Add fmaxmag and fminmag. * sysdeps/ieee754/ldbl-opt/nldbl-fmaxmag.c: New file. * sysdeps/ieee754/ldbl-opt/nldbl-fminmag.c: Likewise. * sysdeps/ieee754/ldbl-opt/s_fmaxmagl.c: Likewise. * sysdeps/ieee754/ldbl-opt/s_fminmagl.c: Likewise. * sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add fmaxmag and fminmag. (CFLAGS-nldbl-fmaxmag.c): New variable. (CFLAGS-nldbl-fminmag.c): Likewise. * 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. --- sysdeps/ieee754/ldbl-opt/Makefile | 4 +++- sysdeps/ieee754/ldbl-opt/nldbl-fmaxmag.c | 26 ++++++++++++++++++++++++++ sysdeps/ieee754/ldbl-opt/nldbl-fminmag.c | 26 ++++++++++++++++++++++++++ sysdeps/ieee754/ldbl-opt/s_fmaxmagl.c | 5 +++++ sysdeps/ieee754/ldbl-opt/s_fminmagl.c | 5 +++++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 sysdeps/ieee754/ldbl-opt/nldbl-fmaxmag.c create mode 100644 sysdeps/ieee754/ldbl-opt/nldbl-fminmag.c create mode 100644 sysdeps/ieee754/ldbl-opt/s_fmaxmagl.c create mode 100644 sysdeps/ieee754/ldbl-opt/s_fminmagl.c (limited to 'sysdeps/ieee754') diff --git a/sysdeps/ieee754/ldbl-opt/Makefile b/sysdeps/ieee754/ldbl-opt/Makefile index ba13515..99aa6c6 100644 --- a/sysdeps/ieee754/ldbl-opt/Makefile +++ b/sysdeps/ieee754/ldbl-opt/Makefile @@ -43,7 +43,7 @@ libnldbl-calls = asprintf dprintf fprintf fscanf fwprintf fwscanf iovfscanf \ isoc99_wscanf isoc99_fwscanf isoc99_swscanf \ isoc99_vwscanf isoc99_vfwscanf isoc99_vswscanf \ nextup nextdown totalorder totalordermag getpayload \ - canonicalize setpayload setpayloadsig llogb + canonicalize setpayload setpayloadsig llogb fmaxmag fminmag libnldbl-routines = $(libnldbl-calls:%=nldbl-%) libnldbl-inhibit-o = $(object-suffixes) libnldbl-static-only-routines = $(libnldbl-routines) @@ -97,7 +97,9 @@ CFLAGS-nldbl-finite.c = -fno-builtin-finitel CFLAGS-nldbl-floor.c = -fno-builtin-floorl CFLAGS-nldbl-fma.c = -fno-builtin-fmal CFLAGS-nldbl-fmax.c = -fno-builtin-fmaxl +CFLAGS-nldbl-fmaxmag.c = -fno-builtin-fmaxmagl CFLAGS-nldbl-fmin.c = -fno-builtin-fminl +CFLAGS-nldbl-fminmag.c = -fno-builtin-fminmagl CFLAGS-nldbl-fmod.c = -fno-builtin-fmodl CFLAGS-nldbl-frexp.c = -fno-builtin-frexpl CFLAGS-nldbl-gamma.c = -fno-builtin-gammal diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-fmaxmag.c b/sysdeps/ieee754/ldbl-opt/nldbl-fmaxmag.c new file mode 100644 index 0000000..ebb2449 --- /dev/null +++ b/sysdeps/ieee754/ldbl-opt/nldbl-fmaxmag.c @@ -0,0 +1,26 @@ +/* Compatibility routine for IEEE double as long double for fmaxmag. + Copyright (C) 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 + . */ + +#include "nldbl-compat.h" + +double +attribute_hidden +fmaxmagl (double x, double y) +{ + return fmaxmag (x, y); +} diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-fminmag.c b/sysdeps/ieee754/ldbl-opt/nldbl-fminmag.c new file mode 100644 index 0000000..4819920 --- /dev/null +++ b/sysdeps/ieee754/ldbl-opt/nldbl-fminmag.c @@ -0,0 +1,26 @@ +/* Compatibility routine for IEEE double as long double for fminmag. + Copyright (C) 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 + . */ + +#include "nldbl-compat.h" + +double +attribute_hidden +fminmagl (double x, double y) +{ + return fminmag (x, y); +} diff --git a/sysdeps/ieee754/ldbl-opt/s_fmaxmagl.c b/sysdeps/ieee754/ldbl-opt/s_fmaxmagl.c new file mode 100644 index 0000000..7e23761 --- /dev/null +++ b/sysdeps/ieee754/ldbl-opt/s_fmaxmagl.c @@ -0,0 +1,5 @@ +/* fmaxmagl is not subject to complex aliasing rules. It was added in + glibc 2.25. */ +#define declare_mgen_alias(from, to) weak_alias (M_SUF (from), M_SUF (to)) +#include +#include diff --git a/sysdeps/ieee754/ldbl-opt/s_fminmagl.c b/sysdeps/ieee754/ldbl-opt/s_fminmagl.c new file mode 100644 index 0000000..46c1051 --- /dev/null +++ b/sysdeps/ieee754/ldbl-opt/s_fminmagl.c @@ -0,0 +1,5 @@ +/* fminmagl is not subject to complex aliasing rules. It was added in + glibc 2.25. */ +#define declare_mgen_alias(from, to) weak_alias (M_SUF (from), M_SUF (to)) +#include +#include -- cgit v1.1