This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 2/6] float128: Add conversion from float128 to mpn
- From: "Gabriel F. T. Gomes" <gftg at linux dot vnet dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Date: Fri, 26 May 2017 09:56:32 -0300
- Subject: [PATCH 2/6] float128: Add conversion from float128 to mpn
- Authentication-results: sourceware.org; auth=none
- References: <1495803396-14558-1-git-send-email-gftg@linux.vnet.ibm.com>
Reuse the code for __mpn_extract_long_double to implement
__mpn_extract_float128.
2017-05-15 Gabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
* 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 b741670..95d6c16 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 9721613..02d6b1c 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 0000000..6a7b0e0
--- /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 0000000..b0dd2e9
--- /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
+ <http://www.gnu.org/licenses/>. */
+
+#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 71a6f04..e23cb76 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 <ieee754.h>
-#include <float.h>
-#include <math.h>
-#include <stdlib.h>
+
+#ifdef __FLOAT128_OVERRIDE
+# include <float128_private.h>
+#else
+# include <ieee754.h>
+# include <float.h>
+# include <math.h>
+#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.4.11