summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/recipes-support/mpfr/mpfr/0001-include-math.h-to-use-predefined-_Float128-definitio.patch382
1 files changed, 347 insertions, 35 deletions
diff --git a/meta/recipes-support/mpfr/mpfr/0001-include-math.h-to-use-predefined-_Float128-definitio.patch b/meta/recipes-support/mpfr/mpfr/0001-include-math.h-to-use-predefined-_Float128-definitio.patch
index 0dcbdce0db..bb813ee94d 100644
--- a/meta/recipes-support/mpfr/mpfr/0001-include-math.h-to-use-predefined-_Float128-definitio.patch
+++ b/meta/recipes-support/mpfr/mpfr/0001-include-math.h-to-use-predefined-_Float128-definitio.patch
@@ -1,44 +1,356 @@
1From 4f2af1afce6edb4ba1dfc9bb4849c9f300efe213 Mon Sep 17 00:00:00 2001 1From c37c9d599b9aced92e182507bf223440bbc9a9f1 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com> 2From: Vincent Lefevre <vincent@vinc17.net>
3Date: Thu, 26 Dec 2024 19:44:12 -0800 3Date: Thu, 6 Mar 2025 01:34:28 +0100
4Subject: [PATCH] include math.h to use predefined _Float128 definition 4Subject: [PATCH] Portability: clean up support for binary128 (a.k.a.
5 float128).
5 6
6glibc has added this patch [1] which defines __HAVE_FLOAT128 for clang 7This fixes a configure failure with Clang and glibc 2.41:
7therefore include math.h to avoid defining _Float128 during configure if 8 https://bugs.gentoo.org/949962
8not needed. 9 https://sourceware.org/bugzilla/show_bug.cgi?id=32750
10 https://sympa.inria.fr/sympa/arc/mpfr/2025-02/msg00025.html
11 https://sympa.inria.fr/sympa/arc/mpfr/2025-03/msg00001.html
9 12
10Fixes 13The issue is the following: in its configure script, GNU MPFR first
11cannot combine with previous '__float128' declaration specifier 14tests whether _Float128 is supported (without header inclusions);
15if it isn't, MPFR then tests whether __float128 is supported, and
16in such a case, it defines _Float128 as __float128 with
12 17
13[1] https://sourceware.org/git/?p=glibc.git;a=blobdiff;f=sysdeps/x86/bits/floatn.h;h=ba030d270a73c71f166083b30dbaf89371ff49fa;hp=e661abaea469b8b916fd312cc42382ad4c5e220f;hb=d773aff467840f5ed305e40c180466e90bd88183;hpb=b2556550a0f952b2a841a0b4bddc999c2df1b233 18 AC_DEFINE([_Float128],[__float128],[__float128 fallback])
14 19
15Upstream-Status: Submitted [https://sympa.inria.fr/sympa/arc/mpfr/2024-12/msg00001.html] 20As Clang supports __float128 but not _Float128 (at least on x86_64,
16Signed-off-by: Khem Raj <raj.khem@gmail.com> 21up to version 19), this fallback is selected. But glibc 2.41 has a
22similar fallback, with a typedef:
23
24 typedef __float128 _Float128;
25
26With the MPFR _Float128 macro defined as __float128, as soon as some
27header such as <stdio.h> is included, this yields
28
29 typedef __float128 __float128;
30
31which is incorrect. This first occurs in the
32
33 AC_MSG_CHECKING(for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency)
34 [...]
35
36configure test (in configure.ac), hence the failure of this test and
37the configure script.
38
39As an attempt to avoid such an issue with header inclusion, a solution
40should be to include the common headers in every configure test.
41
42But since _Float128 is a reserved identifier, we must avoid defining
43it as a macro (a typedef would also be incorrect). This is done here,
44by defining a mpfr_float128 macro instead. In the public mpfr.h header
45file, if the user has defined MPFR_WANT_FLOAT128: mpfr_float128 will
46be defined as _Float128 by default (thus this will not change the API),
47but if _Float128 is not supported, the user should define mpfr_float128
48as __float128 (or an equivalent type that is supported).
49
50* acinclude.m4: changed _Float128 to mpfr_float128 in AC_DEFINE.
51* configure.ac: updated a comment about _Float128.
52* doc/README.dev: update about MPFR_WANT_FLOAT128 and _Float128.
53* doc/mpfr.texi: in "Nomenclature and Types", added a paragraph about
54 binary128 support and the mpfr_float128 macro; update concerning the
55 functions related to binary128 (in particular, in the prototypes,
56 changed _Float128 to mpfr_float128).
57* src/mpfr.h: under "#ifdef MPFR_WANT_FLOAT128", define mpfr_float128
58 as _Float128 if not defined yet; in the prototypes, changed
59 _Float128 to mpfr_float128.
60* src/get_float128.c, src/set_float128.c, tests/tset_float128.c:
61 changed _Float128 to mpfr_float128; updated comments.
62* tests/tversion.c: for "float128 = yes", also output the actual type.
63
64Upstream-Status: Backport [https://gitlab.inria.fr/mpfr/mpfr/-/commit/c37c9d599b9aced92e182507bf223440bbc9a9f1]
65Signed-off-by: Khem Raj <raj.khem@gmail.com>
17--- 66---
18 acinclude.m4 | 6 ++++-- 67 acinclude.m4 | 11 +++++++----
19 1 file changed, 4 insertions(+), 2 deletions(-) 68 configure.ac | 2 +-
69 doc/README.dev | 11 ++---------
70 doc/mpfr.texi | 37 ++++++++++++++++++++++++++-----------
71 src/get_float128.c | 17 ++++++++++-------
72 src/mpfr.h | 10 ++++++++--
73 src/set_float128.c | 15 +++++++++------
74 tests/tset_float128.c | 8 ++++----
75 tests/tversion.c | 8 +++++++-
76 9 files changed, 74 insertions(+), 45 deletions(-)
20 77
21diff --git a/acinclude.m4 b/acinclude.m4
22index 3d7910517..65c4eb9fd 100644
23--- a/acinclude.m4 78--- a/acinclude.m4
24+++ b/acinclude.m4 79+++ b/acinclude.m4
25@@ -805,8 +805,9 @@ dnl the "undefined reference" error disappear. 80@@ -781,8 +781,11 @@ fi
26 if test "$enable_float128" != no; then 81 # End of decimal float checks
27 AC_MSG_CHECKING(if _Float128 with hex constants is supported) 82
28 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ 83 dnl Check if _Float128 or __float128 is available. We also require the
29-volatile _Float128 x = 0x1.fp+16383f128; 84-dnl compiler to support hex constants with the f128 or q suffix (this
30-return x == 0; 85-dnl prevents the _Float128 support with GCC's -std=c90, but who cares?).
31+ #include <math.h> 86+dnl compiler to support hex constants with the f128 or q suffix respectively.
32+ volatile _Float128 x = 0x1.fp+16383f128; 87+dnl If _Float128 is supported, then the mpfr_float128 macro should be
33+ return x == 0; 88+dnl defined as this type. We do not define it here because this will be
34 ]])], 89+dnl done in mpfr.h, and not defining it here is the only way to ensure
35 [AC_MSG_RESULT(yes) 90+dnl that under "make check", mpfr.h really defines it.
36 AC_DEFINE([MPFR_WANT_FLOAT128],1,[Build float128 functions])], 91 dnl Note: We use AC_LINK_IFELSE instead of AC_COMPILE_IFELSE since an
37@@ -816,6 +817,7 @@ dnl Use the q suffix in this case. 92 dnl error may occur only at link time, such as under NetBSD:
38 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 93 dnl https://mail-index.netbsd.org/pkgsrc-users/2018/02/02/msg026220.html
39 #define _Float128 __float128 94@@ -809,8 +812,8 @@ return x == 0;
40 ]], [[
41+#include <math.h>
42 volatile _Float128 x = 0x1.fp+16383q;
43 return x == 0;
44 ]])], 95 ]])],
96 [AC_MSG_RESULT(yes)
97 AC_DEFINE([MPFR_WANT_FLOAT128],2,
98- [Build float128 functions with float128 fallback])
99- AC_DEFINE([_Float128],[__float128],[__float128 fallback])],
100+ [Build float128 functions with __float128 fallback])
101+ AC_DEFINE([mpfr_float128],[__float128],[__float128 fallback])],
102 [AC_MSG_RESULT(no)
103 if test "$enable_float128" = yes; then
104 AC_MSG_ERROR(
105--- a/configure.ac
106+++ b/configure.ac
107@@ -277,7 +277,7 @@ AC_ARG_ENABLE(decimal-float,
108
109 dnl Warning! Not to be confused with _Decimal128. Thus it is better
110 dnl to say binary128 in the description. It can correspond to either
111-dnl _Float128 (ISO/IEC TS 18661) or __float128 (old type name).
112+dnl _Float128 (ISO C23) or __float128 (old type name).
113 AC_ARG_ENABLE(float128,
114 [ --disable-float128 explicitly disable binary128 support
115 --enable-float128 build conversion functions from/to binary128
116--- a/doc/README.dev
117+++ b/doc/README.dev
118@@ -836,13 +836,6 @@ does not conform to the C standard by de
119
120 =====================================================================
121
122-In MPFR, _Float128 may be defined as __float128 if the latter is provided
123-by the compiler, but not the former. In such a case, do not assume that
124-_Float128 and long double are necessarily different types (as required by
125-the WG14 N2579 draft "IEC 60559 interchange and extended types").
126-
127- =====================================================================
128-
129 For string suffix selection, do not write expressions of the form
130 string + integer, such as
131
132--- a/doc/mpfr.texi
133+++ b/doc/mpfr.texi
134@@ -833,6 +833,26 @@ MPFR has a global (or per-thread) flag f
135 provides operations on flags (@ref{Exceptions}). This C data type is used
136 to represent a group of flags (or a mask).
137
138+@cindex binary128
139+@cindex float128
140+@tindex @code{_Float128}
141+@tindex @code{__float128}
142+@tindex @code{mpfr_float128}
143+MPFR can be built with binary128 support (a.k.a.@: float128) for some
144+conversion functions if the @samp{_Float128} type (from ISO C23) or
145+the @samp{__float128} type (a common extension) is available. This is
146+automatically detected, but the @samp{--enable-float128} configure option
147+can also be used to ensure this support. For this support, MPFR uses a
148+@code{mpfr_float128} macro, which needs to be defined as a supported type
149+for the binary128 format, typically @samp{_Float128} or @samp{__float128},
150+depending on the compiler and the system used to compile the user code.
151+Before including @file{mpfr.h}, the user needs to do the following (in
152+any order): define the @code{MPFR_WANT_FLOAT128} macro and define the
153+@code{mpfr_float128} macro as the actual float128 type; @file{mpfr.h} will
154+define @code{mpfr_float128} as @samp{_Float128} by default, but mainly for
155+compatibility with software written for MPFR@tie{}4.1.x and 4.2.0, where
156+the prototypes used @samp{_Float128}.
157+
158 @node MPFR Variable Conventions, Rounding, Nomenclature and Types, MPFR Basics
159 @comment node-name, next, previous, up
160 @section MPFR Variable Conventions
161@@ -3646,9 +3666,9 @@ return zero otherwise.
162 @end deftypefun
163
164 @deftypefun int mpfr_buildopt_float128_p (void)
165-Return a non-zero value if MPFR was compiled with @samp{_Float128} support
166-(that is, MPFR was built with the @samp{--enable-float128} configure option),
167-return zero otherwise.
168+Return a non-zero value if MPFR was compiled with binary128 support
169+(a.k.a.@: float128), return zero otherwise. @xref{Nomenclature and Types}
170+for additional information.
171 @end deftypefun
172
173 @deftypefun int mpfr_buildopt_decimal_p (void)
174--- a/src/get_float128.c
175+++ b/src/get_float128.c
176@@ -1,5 +1,5 @@
177 /* mpfr_get_float128 -- convert a multiple precision floating-point
178- number to a _Float128 number
179+ number to a binary128 (a.k.a. float128) number
180
181 Copyright 2012-2023 Free Software Foundation, Inc.
182 Contributed by the AriC and Caramba projects, INRIA.
183@@ -25,17 +25,20 @@ https://www.gnu.org/licenses/ or write t
184
185 #ifdef MPFR_WANT_FLOAT128
186
187+/* Note: mpfr_get_float128 is a macro defined as the actual binary128 type:
188+ either _Float128 or __float128. */
189+
190 /* generic code */
191-_Float128
192+mpfr_float128
193 mpfr_get_float128 (mpfr_srcptr x, mpfr_rnd_t rnd_mode)
194 {
195
196 if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x)))
197- return (_Float128) mpfr_get_d (x, rnd_mode);
198+ return (mpfr_float128) mpfr_get_d (x, rnd_mode);
199 else /* now x is a normal non-zero number */
200 {
201- _Float128 r; /* result */
202- _Float128 m;
203+ mpfr_float128 r; /* result */
204+ mpfr_float128 m;
205 mpfr_exp_t e; /* exponent of x (before rounding) */
206 mpfr_exp_t sh; /* exponent shift, so that x/2^sh is in the double range */
207 const int emin = -16381;
208@@ -62,7 +65,7 @@ mpfr_get_float128 (mpfr_srcptr x, mpfr_r
209
210 MPFR_SAVE_EXPO_MARK (expo);
211
212- /* First round x to the target _Float128 precision, taking the
213+ /* First round x to the target binary128 precision, taking the
214 reduced precision of the subnormals into account, so that all
215 subsequent operations are exact (this avoids double rounding
216 problems). */
217@@ -83,7 +86,7 @@ mpfr_get_float128 (mpfr_srcptr x, mpfr_r
218 always work if GMP_NUMB_BITS > IEEE_FLOAT128_MANT_DIG.
219 MPFR_LIMB_HIGHBIT has the advantage to fit on 1 bit. */
220 r += yp[i];
221- r *= 1 / (2 * (_Float128) MPFR_LIMB_HIGHBIT);
222+ r *= 1 / (2 * (mpfr_float128) MPFR_LIMB_HIGHBIT);
223 }
224
225 mpfr_clear (y);
226--- a/src/mpfr.h
227+++ b/src/mpfr.h
228@@ -476,8 +476,14 @@ __MPFR_DECLSPEC int mpfr_set_decimal128
229 #endif
230 __MPFR_DECLSPEC int mpfr_set_ld (mpfr_ptr, long double, mpfr_rnd_t);
231 #ifdef MPFR_WANT_FLOAT128
232-__MPFR_DECLSPEC int mpfr_set_float128 (mpfr_ptr, _Float128, mpfr_rnd_t);
233-__MPFR_DECLSPEC _Float128 mpfr_get_float128 (mpfr_srcptr, mpfr_rnd_t);
234+/* The user is free to define mpfr_float128 as another equivalent type,
235+ such as __float128 if this one is supported by the current compiler
236+ but _Float128 isn't. */
237+# ifndef mpfr_float128
238+# define mpfr_float128 _Float128
239+# endif
240+__MPFR_DECLSPEC int mpfr_set_float128 (mpfr_ptr, mpfr_float128, mpfr_rnd_t);
241+__MPFR_DECLSPEC mpfr_float128 mpfr_get_float128 (mpfr_srcptr, mpfr_rnd_t);
242 #endif
243 __MPFR_DECLSPEC int mpfr_set_z (mpfr_ptr, mpz_srcptr, mpfr_rnd_t);
244 __MPFR_DECLSPEC int mpfr_set_z_2exp (mpfr_ptr, mpz_srcptr, mpfr_exp_t,
245--- a/src/set_float128.c
246+++ b/src/set_float128.c
247@@ -1,4 +1,4 @@
248-/* mpfr_set_float128 -- convert a machine _Float128 number to
249+/* mpfr_set_float128 -- convert a binary128 (a.k.a. float128) number to
250 a multiple precision floating-point number
251
252 Copyright 2012-2023 Free Software Foundation, Inc.
253@@ -26,8 +26,11 @@ https://www.gnu.org/licenses/ or write t
254
255 #ifdef MPFR_WANT_FLOAT128
256
257+/* Note: mpfr_get_float128 is a macro defined as the actual binary128 type:
258+ either _Float128 or __float128. */
259+
260 #if MPFR_WANT_FLOAT128 == 1
261-/* _Float128 type from ISO/IEC TS 18661 */
262+/* _Float128 type from ISO C23 */
263 # define MPFR_FLOAT128_MAX 0x1.ffffffffffffffffffffffffffffp+16383f128
264 #elif MPFR_WANT_FLOAT128 == 2
265 /* __float128 type (GNU C extension) */
266@@ -37,12 +40,12 @@ https://www.gnu.org/licenses/ or write t
267 #endif
268
269 int
270-mpfr_set_float128 (mpfr_ptr r, _Float128 d, mpfr_rnd_t rnd_mode)
271+mpfr_set_float128 (mpfr_ptr r, mpfr_float128 d, mpfr_rnd_t rnd_mode)
272 {
273 mpfr_t t;
274 mp_limb_t *tp;
275 int inexact, shift_exp, neg, e, i;
276- _Float128 p[14], q[14];
277+ mpfr_float128 p[14], q[14];
278 MPFR_SAVE_EXPO_DECL (expo);
279
280 /* Check for NaN */
281@@ -66,7 +69,7 @@ mpfr_set_float128 (mpfr_ptr r, _Float128
282 return 0;
283 }
284 /* Check for ZERO */
285- else if (MPFR_UNLIKELY (d == (_Float128) 0.0))
286+ else if (MPFR_UNLIKELY (d == (mpfr_float128) 0.0))
287 return mpfr_set_d (r, (double) d, rnd_mode);
288
289 shift_exp = 0; /* invariant: remainder to deal with is d*2^shift_exp */
290@@ -129,7 +132,7 @@ mpfr_set_float128 (mpfr_ptr r, _Float128
291
292 for (i = MPFR_LAST_LIMB (t); i >= 0; i--)
293 {
294- d *= 2 * (_Float128) MPFR_LIMB_HIGHBIT;
295+ d *= 2 * (mpfr_float128) MPFR_LIMB_HIGHBIT;
296 tp[i] = (mp_limb_t) d;
297 d -= tp[i];
298 }
299--- a/tests/tset_float128.c
300+++ b/tests/tset_float128.c
301@@ -33,7 +33,7 @@ https://www.gnu.org/licenses/ or write t
302 static void
303 check_special (void)
304 {
305- _Float128 f;
306+ mpfr_float128 f;
307 mpfr_t x;
308
309 mpfr_init2 (x, 113);
310@@ -162,7 +162,7 @@ static void
311 check_large (void)
312 {
313 mpfr_exp_t emin, emax;
314- _Float128 f, e;
315+ mpfr_float128 f, e;
316 int i;
317 mpfr_t x, y;
318 int r;
319@@ -177,7 +177,7 @@ check_large (void)
320 /* check with the largest float128 number 2^16384*(1-2^(-113)) */
321 for (f = 1.0, i = 0; i < 113; i++)
322 f = f + f;
323- f = f - (_Float128) 1.0;
324+ f = f - (mpfr_float128) 1.0;
325 mpfr_set_ui (y, 1, MPFR_RNDN);
326 mpfr_mul_2ui (y, y, 113, MPFR_RNDN);
327 mpfr_sub_ui (y, y, 1, MPFR_RNDN);
328@@ -258,7 +258,7 @@ check_small (void)
329 {
330 int t[5] = { 1, 2, 17, 111, 112 };
331 mpfr_exp_t emin;
332- _Float128 e, f;
333+ mpfr_float128 e, f;
334 int i, j, neg, inex, r;
335 mpfr_t w, x, y, z;
336
337--- a/tests/tversion.c
338+++ b/tests/tversion.c
339@@ -309,10 +309,16 @@ main (void)
340 err = 1;
341 }
342
343+#ifdef MPFR_WANT_FLOAT128
344+# define MPFR_F128 "yes (" MAKE_STR(mpfr_float128) ")"
345+#else
346+# define MPFR_F128 "no"
347+#endif
348+
349 (printf) ("[tversion] TLS = %s, float128 = %s, decimal = %s,"
350 " GMP internals = %s\n",
351 mpfr_buildopt_tls_p () ? "yes" : "no",
352- mpfr_buildopt_float128_p () ? "yes" : "no",
353+ MPFR_F128,
354 mpfr_buildopt_decimal_p () ? "yes"
355 #if defined(DECIMAL_BID_FORMAT)
356 " (BID)"