From fb91e22c252dbefd1b141fdf151903cf5aea7727 Mon Sep 17 00:00:00 2001 From: "Gabriel F. T. Gomes" Date: Thu, 3 Nov 2016 12:26:52 -0200 Subject: [PATCH] float128: Add conversion from float128 to mpn Reuse the code for __mpn_extract_long_double to implement __mpn_extract_float128. 2017-05-15 Gabriel F. T. Gomes * include/gmp.h (__mpn_extract_float128): Declare when __HAVE_DISTINCT_FLOAT128 is 1. * misc/sys/param.h (MIN, MAX): Only define if not yet defined. * sysdeps/ieee754/float128/Makefile: New file. * sysdeps/ieee754/float128/float1282mpn.c: New file. * sysdeps/ieee754/ldbl-128/ldbl2mpn.c (__mpn_extract_float128): New function, which is built when __FLOAT128_OVERRIDE is defined. --- include/gmp.h | 6 ++++++ misc/sys/param.h | 8 ++++++-- sysdeps/ieee754/float128/Makefile | 3 +++ sysdeps/ieee754/float128/float1282mpn.c | 20 ++++++++++++++++++++ sysdeps/ieee754/ldbl-128/ldbl2mpn.c | 18 ++++++++++++++---- 5 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 sysdeps/ieee754/float128/Makefile create mode 100644 sysdeps/ieee754/float128/float1282mpn.c diff --git a/include/gmp.h b/include/gmp.h index b74167097d9..95d6c16f146 100644 --- a/include/gmp.h +++ b/include/gmp.h @@ -15,6 +15,12 @@ extern mp_size_t __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size, int *expt, int *is_neg, long double value); +#if __HAVE_DISTINCT_FLOAT128 +extern mp_size_t __mpn_extract_float128 (mp_ptr res_ptr, mp_size_t size, + int *expt, int *is_neg, + _Float128 value); +#endif + extern float __mpn_construct_float (mp_srcptr frac_ptr, int expt, int sign); extern double __mpn_construct_double (mp_srcptr frac_ptr, int expt, diff --git a/misc/sys/param.h b/misc/sys/param.h index 97216135f29..02d6b1c533a 100644 --- a/misc/sys/param.h +++ b/misc/sys/param.h @@ -99,8 +99,12 @@ #define powerof2(x) ((((x) - 1) & (x)) == 0) /* Macros for min/max. */ -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)>(b))?(a):(b)) +#ifndef MIN +# define MIN(a,b) (((a)<(b))?(a):(b)) +#endif +#ifndef MAX +# define MAX(a,b) (((a)>(b))?(a):(b)) +#endif #endif /* sys/param.h */ diff --git a/sysdeps/ieee754/float128/Makefile b/sysdeps/ieee754/float128/Makefile new file mode 100644 index 00000000000..6a7b0e0f453 --- /dev/null +++ b/sysdeps/ieee754/float128/Makefile @@ -0,0 +1,3 @@ +ifeq ($(subdir),stdlib) +routines += float1282mpn +endif diff --git a/sysdeps/ieee754/float128/float1282mpn.c b/sysdeps/ieee754/float128/float1282mpn.c new file mode 100644 index 00000000000..b0dd2e9844e --- /dev/null +++ b/sysdeps/ieee754/float128/float1282mpn.c @@ -0,0 +1,20 @@ +/* Copyright (C) 2017 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 + . */ + +#define __FLOAT128_OVERRIDE + +#include "../ldbl-128/ldbl2mpn.c" diff --git a/sysdeps/ieee754/ldbl-128/ldbl2mpn.c b/sysdeps/ieee754/ldbl-128/ldbl2mpn.c index 71a6f043bd2..e23cb76b1be 100644 --- a/sysdeps/ieee754/ldbl-128/ldbl2mpn.c +++ b/sysdeps/ieee754/ldbl-128/ldbl2mpn.c @@ -18,10 +18,14 @@ #include "gmp.h" #include "gmp-impl.h" #include "longlong.h" -#include -#include -#include -#include + +#ifdef __FLOAT128_OVERRIDE +# include +#else +# include +# include +# include +#endif /* Convert a `long double' in IEEE854 quad-precision format to a multi-precision integer representing the significand scaled up by its @@ -29,9 +33,15 @@ (MPN frexpl). */ mp_size_t +#ifdef __FLOAT128_OVERRIDE +__mpn_extract_float128 (mp_ptr res_ptr, mp_size_t size, + int *expt, int *is_neg, + _Float128 value) +#else __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size, int *expt, int *is_neg, long double value) +#endif { union ieee854_long_double u; u.d = value; -- 2.47.2