public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Fix floating-point environment support for soft float
@ 2023-01-27  8:53 Maciej W. Rozycki
  2023-01-27  9:08 ` Kito Cheng
  2023-01-27 13:26 ` Corinna Vinschen
  0 siblings, 2 replies; 3+ messages in thread
From: Maciej W. Rozycki @ 2023-01-27  8:53 UTC (permalink / raw)
  To: newlib; +Cc: Kito Cheng

We don't have floating-point exception or non-default rounding mode 
support for the RISC-V soft-float environment, `feraiseexcept' and 
`fesetround' do nothing unless the `__riscv_flen' macro has been set. 
Therefore following ISO C language requirements[1] only define macros 
for soft float that correspond to actually supported floating-point 
environment features, removing failures from GCC testing such as:

FAIL: gcc.dg/torture/fp-int-convert-timode-3.c   -O0  execution test
FAIL: gcc.dg/torture/fp-int-convert-timode-4.c   -O0  execution test

References:

[1] "Programming languages -- C", ISO/IEC 9899:2023, working draft --
    September 3, 2022, Section 7.6 "Floating-point environment <fenv.h>"

Fixes: 7040b2de0883 ("Add RISC-V port for libm")
Signed-off-by: Maciej W. Rozycki <macro@embecosm.com>
---
 newlib/libc/machine/riscv/sys/fenv.h |    9 +++++++++
 1 file changed, 9 insertions(+)

newlib-riscv-fenv-soft-float.diff
Index: newlib/newlib/libc/machine/riscv/sys/fenv.h
===================================================================
--- newlib.orig/newlib/libc/machine/riscv/sys/fenv.h
+++ newlib/newlib/libc/machine/riscv/sys/fenv.h
@@ -14,6 +14,8 @@
 
 #include <stddef.h>
 
+#if __riscv_flen
+
 /* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA:
  * Version 2.1", Section 8.2, "Floating-Point Control and Status
  * Register":
@@ -69,6 +71,13 @@
  * floating-point unit."
  */
 
+#else /* !__riscv_flen */
+
+#define FE_ALL_EXCEPT   0x00000000
+#define FE_TONEAREST    0x00000000
+
+#endif /* !__riscv_flen */
+
 typedef size_t fenv_t;
 typedef size_t fexcept_t;
 extern const fenv_t fe_dfl_env;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: Fix floating-point environment support for soft float
  2023-01-27  8:53 [PATCH] RISC-V: Fix floating-point environment support for soft float Maciej W. Rozycki
@ 2023-01-27  9:08 ` Kito Cheng
  2023-01-27 13:26 ` Corinna Vinschen
  1 sibling, 0 replies; 3+ messages in thread
From: Kito Cheng @ 2023-01-27  9:08 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: newlib

[-- Attachment #1: Type: text/plain, Size: 1820 bytes --]

ok, thanks!

On Fri, Jan 27, 2023 at 4:53 PM Maciej W. Rozycki <macro@embecosm.com>
wrote:

> We don't have floating-point exception or non-default rounding mode
> support for the RISC-V soft-float environment, `feraiseexcept' and
> `fesetround' do nothing unless the `__riscv_flen' macro has been set.
> Therefore following ISO C language requirements[1] only define macros
> for soft float that correspond to actually supported floating-point
> environment features, removing failures from GCC testing such as:
>
> FAIL: gcc.dg/torture/fp-int-convert-timode-3.c   -O0  execution test
> FAIL: gcc.dg/torture/fp-int-convert-timode-4.c   -O0  execution test
>
> References:
>
> [1] "Programming languages -- C", ISO/IEC 9899:2023, working draft --
>     September 3, 2022, Section 7.6 "Floating-point environment <fenv.h>"
>
> Fixes: 7040b2de0883 ("Add RISC-V port for libm")
> Signed-off-by: Maciej W. Rozycki <macro@embecosm.com>
> ---
>  newlib/libc/machine/riscv/sys/fenv.h |    9 +++++++++
>  1 file changed, 9 insertions(+)
>
> newlib-riscv-fenv-soft-float.diff
> Index: newlib/newlib/libc/machine/riscv/sys/fenv.h
> ===================================================================
> --- newlib.orig/newlib/libc/machine/riscv/sys/fenv.h
> +++ newlib/newlib/libc/machine/riscv/sys/fenv.h
> @@ -14,6 +14,8 @@
>
>  #include <stddef.h>
>
> +#if __riscv_flen
> +
>  /* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA:
>   * Version 2.1", Section 8.2, "Floating-Point Control and Status
>   * Register":
> @@ -69,6 +71,13 @@
>   * floating-point unit."
>   */
>
> +#else /* !__riscv_flen */
> +
> +#define FE_ALL_EXCEPT   0x00000000
> +#define FE_TONEAREST    0x00000000
> +
> +#endif /* !__riscv_flen */
> +
>  typedef size_t fenv_t;
>  typedef size_t fexcept_t;
>  extern const fenv_t fe_dfl_env;
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: Fix floating-point environment support for soft float
  2023-01-27  8:53 [PATCH] RISC-V: Fix floating-point environment support for soft float Maciej W. Rozycki
  2023-01-27  9:08 ` Kito Cheng
@ 2023-01-27 13:26 ` Corinna Vinschen
  1 sibling, 0 replies; 3+ messages in thread
From: Corinna Vinschen @ 2023-01-27 13:26 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: newlib, Kito Cheng

On Jan 27 08:53, Maciej W. Rozycki wrote:
> We don't have floating-point exception or non-default rounding mode 
> support for the RISC-V soft-float environment, `feraiseexcept' and 
> `fesetround' do nothing unless the `__riscv_flen' macro has been set. 
> Therefore following ISO C language requirements[1] only define macros 
> for soft float that correspond to actually supported floating-point 
> environment features, removing failures from GCC testing such as:
> 
> FAIL: gcc.dg/torture/fp-int-convert-timode-3.c   -O0  execution test
> FAIL: gcc.dg/torture/fp-int-convert-timode-4.c   -O0  execution test
> 
> References:
> 
> [1] "Programming languages -- C", ISO/IEC 9899:2023, working draft --
>     September 3, 2022, Section 7.6 "Floating-point environment <fenv.h>"
> 
> Fixes: 7040b2de0883 ("Add RISC-V port for libm")
> Signed-off-by: Maciej W. Rozycki <macro@embecosm.com>
> ---
>  newlib/libc/machine/riscv/sys/fenv.h |    9 +++++++++
>  1 file changed, 9 insertions(+)

Pushed.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-27 13:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-27  8:53 [PATCH] RISC-V: Fix floating-point environment support for soft float Maciej W. Rozycki
2023-01-27  9:08 ` Kito Cheng
2023-01-27 13:26 ` Corinna Vinschen

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).