public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jeff Johnston <jjohnstn@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] newlib: Fix long double for unsupported rounding modes and exceptions
Date: Wed, 20 Dec 2023 21:54:32 +0000 (GMT)	[thread overview]
Message-ID: <20231220215432.A15E63858CD1@sourceware.org> (raw)

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

commit 73bce6597c3de790750b80c2b705bf20172516d4
Author: Craig Blackmore <craig.blackmore@embecosm.com>
Date:   Wed Dec 20 20:32:24 2023 +0000

    newlib: Fix long double for unsupported rounding modes and exceptions
    
    RISC-V newlib fails to build for soft float multilibs since long double
    support was enabled in:
    
      commit 04798b7bb69571452d2cfc7e0b052a9bbd3b619d
      Author: Kito Cheng <kito.cheng@sifive.com>
      Date:   Mon Dec 4 15:41:39 2023 +0800
    
          RISC-V: Support long double math
    
          Long double for RISC-V is using 128 bit IEEE 754 format like Aarch64,
          so we reference AArch64 to support that.
    
    The RISC-V soft floating point environment only supports the
    FE_TONEAREST rounding mode and does not support exceptions.  Guard long
    double rounding and exception support with ifdefs based on the presence
    of the relevant rounding modes and exceptions.
    
    Tested on gcc/g++ testsuite using RISC-V GNU Newlib Toolchain built by
    riscv-gnu-toolchain with multilibs:
    
        riscv-sim/-march=rv32i/-mabi=ilp32/-mcmodel=medlow
        riscv-sim/-march=rv32iac/-mabi=ilp32/-mcmodel=medlow
        riscv-sim/-march=rv32im/-mabi=ilp32/-mcmodel=medlow
        riscv-sim/-march=rv32imac/-mabi=ilp32/-mcmodel=medlow
        riscv-sim/-march=rv32imafc/-mabi=ilp32f/-mcmodel=medlow
        riscv-sim/-march=rv64imac/-mabi=lp64/-mcmodel=medlow
    
    Co-authored-by: Simon Cook <simon.cook@embecosm.com>

Diff:
---
 newlib/libm/ld/s_fmal.c   | 14 ++++++++++++--
 newlib/libm/ld/s_lrint.c  |  2 ++
 newlib/libm/ld/s_lround.c |  2 ++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/newlib/libm/ld/s_fmal.c b/newlib/libm/ld/s_fmal.c
index a379346c1..281dd685b 100644
--- a/newlib/libm/ld/s_fmal.c
+++ b/newlib/libm/ld/s_fmal.c
@@ -199,27 +199,37 @@ fmal(long double x, long double y, long double z)
 	 * modes other than FE_TONEAREST are painful.
 	 */
 	if (spread < -LDBL_MANT_DIG) {
+#ifdef FE_INEXACT
 		feraiseexcept(FE_INEXACT);
+#endif
+#ifdef FE_UNDERFLOW
 		if (!isnormal(z))
 			feraiseexcept(FE_UNDERFLOW);
+#endif
 		switch (oround) {
-		case FE_TONEAREST:
+		default: /* FE_TONEAREST */
 			return (z);
+#ifdef FE_TOWARDZERO
 		case FE_TOWARDZERO:
 			if (x > 0.0 ^ y < 0.0 ^ z < 0.0)
 				return (z);
 			else
 				return (nextafterl(z, 0));
+#endif
+#ifdef FE_DOWNWARD
 		case FE_DOWNWARD:
 			if (x > 0.0 ^ y < 0.0)
 				return (z);
 			else
 				return (nextafterl(z, -INFINITY));
-		default:	/* FE_UPWARD */
+#endif
+#ifdef FE_UPWARD
+		case FE_UPWARD:
 			if (x > 0.0 ^ y < 0.0)
 				return (nextafterl(z, INFINITY));
 			else
 				return (z);
+#endif
 		}
 	}
 	if (spread <= LDBL_MANT_DIG * 2)
diff --git a/newlib/libm/ld/s_lrint.c b/newlib/libm/ld/s_lrint.c
index ad9b978fa..dde3cc434 100644
--- a/newlib/libm/ld/s_lrint.c
+++ b/newlib/libm/ld/s_lrint.c
@@ -53,8 +53,10 @@ fn(type x)
 
 	feholdexcept(&env);
 	d = (dtype)roundit(x);
+#if defined(FE_INVALID) && defined(FE_INEXACT)
 	if (fetestexcept(FE_INVALID))
 		feclearexcept(FE_INEXACT);
+#endif
 	feupdateenv(&env);
 	return (d);
 }
diff --git a/newlib/libm/ld/s_lround.c b/newlib/libm/ld/s_lround.c
index f67f9fbeb..fefafa877 100644
--- a/newlib/libm/ld/s_lround.c
+++ b/newlib/libm/ld/s_lround.c
@@ -64,7 +64,9 @@ fn(type x)
 		x = roundit(x);
 		return ((dtype)x);
 	} else {
+#ifdef FE_INVALID
 		feraiseexcept(FE_INVALID);
+#endif
 		return (DTYPE_MAX);
 	}
 }

                 reply	other threads:[~2023-12-20 21:54 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=20231220215432.A15E63858CD1@sourceware.org \
    --to=jjohnstn@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).