>       setpayloadl: New module.

Oops, it appears that I had not correctly tested this on some platforms.
With these two fixes, it should be better.


2024-04-16  Bruno Haible  <br...@clisp.org>

        setpayloadl: Fix platform-specific bugs.
        * lib/setpayloadl.c (setpayloadl): On m68k, consider the actual memory
        layout of a 'long double'. On platforms with quadruple-precision
        'long double', store 111 bits of payload, not only 110 bits.

>From aee30d7401ea4f0648eb369665ddabd535cab716 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Wed, 17 Apr 2024 00:38:07 +0200
Subject: [PATCH 1/7] setpayloadl: Fix platform-specific bugs.

* lib/setpayloadl.c (setpayloadl): On m68k, consider the actual memory
layout of a 'long double'. On platforms with quadruple-precision
'long double', store 111 bits of payload, not only 110 bits.
---
 ChangeLog         | 7 +++++++
 lib/setpayloadl.c | 9 ++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 03c6919131..7521411127 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-04-16  Bruno Haible  <br...@clisp.org>
+
+	setpayloadl: Fix platform-specific bugs.
+	* lib/setpayloadl.c (setpayloadl): On m68k, consider the actual memory
+	layout of a 'long double'. On platforms with quadruple-precision
+	'long double', store 111 bits of payload, not only 110 bits.
+
 2024-04-16  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Prefer 'not in' over 'not ... in'.
diff --git a/lib/setpayloadl.c b/lib/setpayloadl.c
index 7d25bafae0..6b5a1e24df 100644
--- a/lib/setpayloadl.c
+++ b/lib/setpayloadl.c
@@ -80,9 +80,8 @@ setpayloadl (long double *result, long double payload)
       x.word[1] = (x.word[1] & 0xC0000000U) | (uint32_t) (pl >> 32);
       x.word[0] = (uint32_t) pl;
 #   elif LDBL_EXPBIT0_WORD == 0 && LDBL_EXPBIT0_BIT == 16 /* on m68k */
-      x.word[0] = (x.word[0] & 0xFFFFC000U) | (uint32_t) (pl >> 48)
-      x.word[1] = (uint32_t) (pl >> 16);
-      x.word[2] = (uint32_t) (pl << 16);
+      x.word[1] = (x.word[1] & 0xC0000000U) | (uint32_t) (pl >> 32);
+      x.word[2] = (uint32_t) pl;
 #   else
 #    error "Please port gnulib setpayloadl.c to your platform!"
 #   endif
@@ -103,8 +102,8 @@ setpayloadl (long double *result, long double payload)
 #   if LDBL_EXPBIT0_BIT == 16
       memory_long_double pl;
       pl.value = payload + TWO_LDBL_MANT_DIG;
-      x.word[LDBL_EXPBIT0_WORD] = (x.word[LDBL_EXPBIT0_WORD] & 0xFFFFC000U)
-                                  | (pl.word[LDBL_EXPBIT0_WORD] & 0x00003FFFU);
+      x.word[LDBL_EXPBIT0_WORD] = (x.word[LDBL_EXPBIT0_WORD] & 0xFFFF8000U)
+                                  | (pl.word[LDBL_EXPBIT0_WORD] & 0x00007FFFU);
       x.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD == 0 ? 1 : -1)] =
         pl.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD == 0 ? 1 : -1)];
       x.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD == 0 ? 2 : -2)] =
-- 
2.34.1

Reply via email to