[5/5] newlib: ieeefp.h: add the big-endian 80-bit extended layout

Message ID 20261017094038.639129-6-bernie@codewiz.org
State New
Headers
Series newlib: libm: long double fixes |

Commit Message

Bernie Innocenti Oct. 17, 2026, 9:40 a.m. UTC
  struct ieee_ext only had the x87 field order, so on m68k with a 68881
long double (sign and exponent first, 16 bits of padding, then the
mantissa) libm/common/sqrtl.c read the fields from the wrong bytes and
returned wrong results for almost every argument.

Assisted-by: Claude:claude-opus-5-5 claude-code
Signed-off-by: Bernie Innocenti <bernie@codewiz.org>
---
 newlib/libc/include/ieeefp.h | 9 +++++++++
 1 file changed, 9 insertions(+)
  

Patch

diff --git a/newlib/libc/include/ieeefp.h b/newlib/libc/include/ieeefp.h
index 2d6421a4c..1d07c510e 100644
--- a/newlib/libc/include/ieeefp.h
+++ b/newlib/libc/include/ieeefp.h
@@ -192,10 +192,19 @@  typedef union
 
 typedef struct ieee_ext
 {
+#if defined (__IEEE_BIG_ENDIAN) && LDBL_MANT_DIG == 64
+  /* 68881 extended: sign and exponent, 16 bits of padding, mantissa.  */
+  __ieee_ext_field_type	 ext_sign  : 1;
+  __ieee_ext_field_type	 ext_exp   : EXT_EXPBITS;
+  __ieee_ext_field_type	 ext_pad   : 16;
+  __ieee_ext_field_type	 ext_frach : EXT_FRACHBITS;
+  __ieee_ext_field_type	 ext_fracl : EXT_FRACLBITS;
+#else
   __ieee_ext_field_type	 ext_fracl : EXT_FRACLBITS;
   __ieee_ext_field_type	 ext_frach : EXT_FRACHBITS;
   __ieee_ext_field_type	 ext_exp   : EXT_EXPBITS;
   __ieee_ext_field_type	 ext_sign  : 1;
+#endif
 } ieee_ext;
 
 typedef union ieee_ext_u