public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Takashi Yano <tyan0@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin/cygwin-3_3-branch] frexpl: Support smaller long double of LDBL_MANT_DIG == 53.
Date: Fri,  3 Dec 2021 10:15:12 +0000 (GMT)	[thread overview]
Message-ID: <20211203101512.D652C385BF9C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=42cbd7b0a16bafe8ce60fe15ac082ca0ae6e548a

commit 42cbd7b0a16bafe8ce60fe15ac082ca0ae6e548a
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Thu Dec 2 18:51:21 2021 +0900

    frexpl: Support smaller long double of LDBL_MANT_DIG == 53.
    
    - Currently, frexpl() supports only the following cases.
        1) LDBL_MANT_DIG == 64 or 113
        2) 'long double' is equivalent to 'double'
      This patch add support for LDBL_MANT_DIG == 53.

Diff:
---
 newlib/libm/common/frexpl.c | 54 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 42 insertions(+), 12 deletions(-)

diff --git a/newlib/libm/common/frexpl.c b/newlib/libm/common/frexpl.c
index 22c811689..8da2823ca 100644
--- a/newlib/libm/common/frexpl.c
+++ b/newlib/libm/common/frexpl.c
@@ -33,16 +33,42 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "local.h"
 
 /* On platforms where long double is as wide as double.  */
-#if defined(_LDBL_EQ_DBL) || (LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024)
+#if defined(_LDBL_EQ_DBL)
 long double
 frexpl (long double x, int *eptr)
 {
   return frexp(x, eptr);
 }
-#endif
+#else  /* !_DBL_EQ_DBL */
+# if (LDBL_MANT_DIG == 53) /* 64-bit long double */
+static const double scale = 0x1p54;
+
+union ldbl {
+  long double x;
+  struct {
+#  ifdef __IEEE_LITTLE_ENDIAN /* for Intel CPU */
+    __uint32_t fracl;
+    __uint32_t frach:20;
+    __uint32_t exp:11;
+    __uint32_t sign:1;
+#  endif
+#  ifdef __IEEE_BIG_ENDIAN
+    __uint32_t sign:1;
+    __uint32_t exp:11;
+    __uint32_t frach:20;
+#   ifndef ___IEEE_BYTES_LITTLE_ENDIAN
+#   else /* ARMEL without __VFP_FP__ */
+    __uint32_t frach:20;
+    __uint32_t exp:11;
+    __uint32_t sign:1;
+#   endif
+    __uint32_t fracl;
+#  endif
+  } u32;
+};
+# elif (LDBL_MANT_DIG == 64) /* 80-bit long double */
+static const double scale = 0x1p65;
 
-#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
-# if (LDBL_MANT_DIG == 64) /* 80-bit long double */
 union ldbl {
   long double x;
   struct {
@@ -68,7 +94,9 @@ union ldbl {
 #  endif
   } u32;
 };
-# else /* LDBL_MANT_DIG == 113, 128-bit long double */
+# elif (LDBL_MANT_DIG == 113) /* 128-bit long double */
+static const double scale = 0x1p114;
+
 union ldbl {
   long double x;
   struct {
@@ -96,9 +124,11 @@ union ldbl {
 #  endif
   } u32;
 };
+# else
+#  error Unsupported long double format.
 # endif
 
-static const double two114 = 0x1p114;
+static const int scale_exp = LDBL_MANT_DIG + 1;
 
 long double
 frexpl (long double x, int *eptr)
@@ -107,16 +137,16 @@ frexpl (long double x, int *eptr)
   u.x = x;
   int e = u.u32.exp;
   *eptr = 0;
-  if (e == 0x7fff || x == 0)
+  if (e == (LDBL_MAX_EXP*2 - 1) || x == 0)
     return x; /* inf,nan,0 */
   if (e == 0) /* subnormal */
     {
-      u.x *= two114;
+      u.x *= scale;
       e = u.u32.exp;
-      *eptr -= 114;
+      *eptr -= scale_exp;
     }
-  *eptr += e - 16382;
-  u.u32.exp = 0x3ffe; /* 0 */
+  *eptr += e - (LDBL_MAX_EXP - 2);
+  u.u32.exp = LDBL_MAX_EXP - 2; /* -1 */
   return u.x;
 }
-#endif /* End of 80-bit or 128-bit long double */
+#endif /* !_LDBL_EQ_DBL */


                 reply	other threads:[~2021-12-03 10:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211203101512.D652C385BF9C@sourceware.org \
    --to=tyan0@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).