public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Support Zfinx/Zdinx extension.
@ 2023-07-26 10:03 Kito Cheng
  2023-07-26 13:27 ` Corinna Vinschen
  2023-10-10  5:26 ` Sebastian Huber
  0 siblings, 2 replies; 3+ messages in thread
From: Kito Cheng @ 2023-07-26 10:03 UTC (permalink / raw)
  To: newlib, kito.cheng; +Cc: Kito Cheng, Jesse Huang

Zfinx/Zdinx are new extensions ratified in 2022, it similar to F/D extensions,
support hard float operation for single/double precision, but the difference
between Zfinx/Zdinx and F/D is Zfinx/Zdinx is operating under general purpose
registers rather than dedicated floating-point registers.

This patch improve the hard float support detection for RISC-V port, so
that Zfinx/Zdinx can have better/right performance.

Co-authored-by: Jesse Huang <jesse.huang@sifive.com>
---
 newlib/libc/include/machine/ieeefp.h        |  4 ++--
 newlib/libc/machine/riscv/ieeefp.c          | 10 +++++-----
 newlib/libc/machine/riscv/sys/fenv.h        |  2 +-
 newlib/libm/common/math_config.h            |  6 ++++--
 newlib/libm/machine/riscv/e_sqrt.c          |  2 +-
 newlib/libm/machine/riscv/ef_sqrt.c         |  2 +-
 newlib/libm/machine/riscv/feclearexcept.c   |  3 ++-
 newlib/libm/machine/riscv/fegetenv.c        |  3 ++-
 newlib/libm/machine/riscv/fegetexceptflag.c |  3 ++-
 newlib/libm/machine/riscv/fegetround.c      |  3 ++-
 newlib/libm/machine/riscv/feholdexcept.c    |  3 ++-
 newlib/libm/machine/riscv/feraiseexcept.c   |  3 ++-
 newlib/libm/machine/riscv/fesetenv.c        |  3 ++-
 newlib/libm/machine/riscv/fesetexceptflag.c |  3 ++-
 newlib/libm/machine/riscv/fesetround.c      |  3 ++-
 newlib/libm/machine/riscv/fetestexcept.c    |  3 ++-
 newlib/libm/machine/riscv/feupdateenv.c     |  3 ++-
 newlib/libm/machine/riscv/riscv_math.h      | 12 +++++++++---
 newlib/libm/machine/riscv/s_copysign.c      |  3 ++-
 newlib/libm/machine/riscv/s_fabs.c          |  3 ++-
 newlib/libm/machine/riscv/s_finite.c        |  3 ++-
 newlib/libm/machine/riscv/s_fmax.c          |  3 ++-
 newlib/libm/machine/riscv/s_fmin.c          |  3 ++-
 newlib/libm/machine/riscv/s_fpclassify.c    |  5 ++---
 newlib/libm/machine/riscv/s_isinf.c         |  4 ++--
 newlib/libm/machine/riscv/s_isnan.c         |  4 ++--
 newlib/libm/machine/riscv/s_llrint.c        |  3 ++-
 newlib/libm/machine/riscv/s_llround.c       |  3 ++-
 newlib/libm/machine/riscv/s_lrint.c         |  3 ++-
 newlib/libm/machine/riscv/s_lround.c        |  3 ++-
 newlib/libm/machine/riscv/sf_copysign.c     |  3 ++-
 newlib/libm/machine/riscv/sf_fabs.c         |  3 ++-
 newlib/libm/machine/riscv/sf_finite.c       |  3 ++-
 newlib/libm/machine/riscv/sf_fmax.c         |  3 ++-
 newlib/libm/machine/riscv/sf_fmin.c         |  3 ++-
 newlib/libm/machine/riscv/sf_fpclassify.c   |  3 ++-
 newlib/libm/machine/riscv/sf_isinf.c        |  4 ++--
 newlib/libm/machine/riscv/sf_isnan.c        |  4 ++--
 newlib/libm/machine/riscv/sf_llrint.c       |  3 ++-
 newlib/libm/machine/riscv/sf_llround.c      |  3 ++-
 newlib/libm/machine/riscv/sf_lrint.c        |  3 ++-
 newlib/libm/machine/riscv/sf_lround.c       |  3 ++-
 42 files changed, 93 insertions(+), 56 deletions(-)

diff --git a/newlib/libc/include/machine/ieeefp.h b/newlib/libc/include/machine/ieeefp.h
index a29557a6d..abadf520b 100644
--- a/newlib/libc/include/machine/ieeefp.h
+++ b/newlib/libc/include/machine/ieeefp.h
@@ -218,10 +218,10 @@
 #else
 #define __IEEE_LITTLE_ENDIAN
 #endif
-#ifdef __riscv_flen
+#if defined(__riscv_flen) || defined (__riscv_zfinx)
 # define _SUPPORTS_ERREXCEPT
 #endif
-#if __riscv_flen == 64
+#if (__riscv_flen == 64) || defined (__riscv_zdinx)
 # define __OBSOLETE_MATH_DEFAULT 0
 #else
 # define __OBSOLETE_MATH_DEFAULT 1
diff --git a/newlib/libc/machine/riscv/ieeefp.c b/newlib/libc/machine/riscv/ieeefp.c
index 60ecacfc2..185da648c 100644
--- a/newlib/libc/machine/riscv/ieeefp.c
+++ b/newlib/libc/machine/riscv/ieeefp.c
@@ -11,7 +11,7 @@
 
 #include <ieeefp.h>
 
-#ifdef __riscv_flen
+#if defined(__riscv_flen) || defined (__riscv_zfinx)
 static void
 fssr(unsigned value)
 {
@@ -85,7 +85,7 @@ fpgetmask(void)
 fp_rnd
 fpgetround(void)
 {
-#ifdef __riscv_flen
+#if defined(__riscv_flen) || defined (__riscv_zfinx)
   unsigned rm = (frsr () >> 5) & 0x7;
   return frm_fp_rnd (rm);
 #else
@@ -96,7 +96,7 @@ fpgetround(void)
 fp_except
 fpgetsticky(void)
 {
-#ifdef __riscv_flen
+#if defined(__riscv_flen) || defined (__riscv_zfinx)
   return frm_fp_except(frsr ());
 #else
   return 0;
@@ -112,7 +112,7 @@ fpsetmask(fp_except mask)
 fp_rnd
 fpsetround(fp_rnd rnd_dir)
 {
-#ifdef __riscv_flen
+#if defined(__riscv_flen) || defined (__riscv_zfinx)
   unsigned fsr = frsr ();
   unsigned rm = (fsr >> 5) & 0x7;
   unsigned new_rm;
@@ -134,7 +134,7 @@ fpsetround(fp_rnd rnd_dir)
 fp_except
 fpsetsticky(fp_except sticky)
 {
-#ifdef __riscv_flen
+#if defined(__riscv_flen) || defined (__riscv_zfinx)
   unsigned fsr = frsr ();
   fssr (frm_except(sticky) | (fsr & ~0x1f));
   return frm_fp_except(fsr);
diff --git a/newlib/libc/machine/riscv/sys/fenv.h b/newlib/libc/machine/riscv/sys/fenv.h
index 772f3833f..1d577d527 100644
--- a/newlib/libc/machine/riscv/sys/fenv.h
+++ b/newlib/libc/machine/riscv/sys/fenv.h
@@ -14,7 +14,7 @@
 
 #include <stddef.h>
 
-#if __riscv_flen
+#if defined(__riscv_f) || defined(__riscv_zfinx)
 
 /* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA:
  * Version 2.1", Section 8.2, "Floating-Point Control and Status
diff --git a/newlib/libm/common/math_config.h b/newlib/libm/common/math_config.h
index 0f78b5c09..bf881e81b 100644
--- a/newlib/libm/common/math_config.h
+++ b/newlib/libm/common/math_config.h
@@ -72,7 +72,8 @@
 
 /* Compiler can inline fma as a single instruction.  */
 #ifndef HAVE_FAST_FMA
-# if __aarch64__ || (__ARM_FEATURE_FMA && (__ARM_FP & 8)) || __riscv_flen >= 64
+# if __aarch64__ || (__ARM_FEATURE_FMA && (__ARM_FP & 8)) \
+     || __riscv_flen >= 64 || defined (__riscv_zdinx)
 #   define HAVE_FAST_FMA 1
 # else
 #   define HAVE_FAST_FMA 0
@@ -80,7 +81,8 @@
 #endif
 
 #ifndef HAVE_FAST_FMAF
-# if HAVE_FAST_FMA || (__ARM_FEATURE_FMA && (__ARM_FP & 4)) || __riscv_flen >= 32
+# if HAVE_FAST_FMA || (__ARM_FEATURE_FMA && (__ARM_FP & 4)) \
+     || __riscv_flen >= 32 || defined (__riscv_zfinx)
 #  define HAVE_FAST_FMAF 1
 # else
 #  define HAVE_FAST_FMAF 0
diff --git a/newlib/libm/machine/riscv/e_sqrt.c b/newlib/libm/machine/riscv/e_sqrt.c
index d6bfd90ad..0c5aaadf3 100644
--- a/newlib/libm/machine/riscv/e_sqrt.c
+++ b/newlib/libm/machine/riscv/e_sqrt.c
@@ -36,7 +36,7 @@
 #include <math.h>
 #include "math_config.h"
 
-#if defined(__riscv_fsqrt) && __riscv_flen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64
 
 double
 __ieee754_sqrt (double x)
diff --git a/newlib/libm/machine/riscv/ef_sqrt.c b/newlib/libm/machine/riscv/ef_sqrt.c
index 1f378f547..cc41813dd 100644
--- a/newlib/libm/machine/riscv/ef_sqrt.c
+++ b/newlib/libm/machine/riscv/ef_sqrt.c
@@ -36,7 +36,7 @@
 #include <math.h>
 #include "math_config.h"
 
-#if defined(__riscv_fsqrt) && __riscv_flen >= 32
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32
 
 float
 __ieee754_sqrtf (float x)
diff --git a/newlib/libm/machine/riscv/feclearexcept.c b/newlib/libm/machine/riscv/feclearexcept.c
index 90c7775a4..e236a59eb 100644
--- a/newlib/libm/machine/riscv/feclearexcept.c
+++ b/newlib/libm/machine/riscv/feclearexcept.c
@@ -33,6 +33,7 @@
 
 #include <fenv.h>
 #include <stddef.h>
+#include "riscv_math.h"
 
 /* This implementation is intended to comply with the following
  * specification:
@@ -47,7 +48,7 @@
 int feclearexcept(int excepts)
 {
 
-#if __riscv_flen
+#if __RISCV_HARD_FLOAT
 
   /* Mask excepts to be sure only supported flag bits are set */
 
diff --git a/newlib/libm/machine/riscv/fegetenv.c b/newlib/libm/machine/riscv/fegetenv.c
index c1488c789..10a9af337 100644
--- a/newlib/libm/machine/riscv/fegetenv.c
+++ b/newlib/libm/machine/riscv/fegetenv.c
@@ -32,6 +32,7 @@
 */
 
 #include <fenv.h>
+#include "riscv_math.h"
 
 /* This implementation is intended to comply with the following
  * specification:
@@ -47,7 +48,7 @@
 int fegetenv(fenv_t *envp)
 {
 
-#if __riscv_flen
+#if __RISCV_HARD_FLOAT
 
   /* Get the current environment (FCSR) */
 
diff --git a/newlib/libm/machine/riscv/fegetexceptflag.c b/newlib/libm/machine/riscv/fegetexceptflag.c
index ab1b8a66b..43d5543f7 100644
--- a/newlib/libm/machine/riscv/fegetexceptflag.c
+++ b/newlib/libm/machine/riscv/fegetexceptflag.c
@@ -32,6 +32,7 @@
 */
 
 #include <fenv.h>
+#include "riscv_math.h"
 
 /* This implementation is intended to comply with the following
  * specification:
@@ -48,7 +49,7 @@
 int fegetexceptflag(fexcept_t *flagp, int excepts)
 {
 
-#if __riscv_flen
+#if __RISCV_HARD_FLOAT
 
   /* Mask excepts to be sure only supported flag bits are set */
 
diff --git a/newlib/libm/machine/riscv/fegetround.c b/newlib/libm/machine/riscv/fegetround.c
index b4c0f2b19..6d553479b 100644
--- a/newlib/libm/machine/riscv/fegetround.c
+++ b/newlib/libm/machine/riscv/fegetround.c
@@ -32,6 +32,7 @@
 */
 
 #include <fenv.h>
+#include "riscv_math.h"
 
 /* This implementation is intended to comply with the following
  * specification:
@@ -45,7 +46,7 @@
 int fegetround()
 {
 
-#if __riscv_flen
+#ifdef __RISCV_HARD_FLOAT
 
   /* Get current rounding mode */
 
diff --git a/newlib/libm/machine/riscv/feholdexcept.c b/newlib/libm/machine/riscv/feholdexcept.c
index 9d726dabe..c83a09bc1 100644
--- a/newlib/libm/machine/riscv/feholdexcept.c
+++ b/newlib/libm/machine/riscv/feholdexcept.c
@@ -32,6 +32,7 @@
 */
 
 #include <fenv.h>
+#include "riscv_math.h"
 
 /* This implementation is intended to comply with the following
  * specification:
@@ -49,7 +50,7 @@
 int feholdexcept(fenv_t *envp)
 {
 
-#if __riscv_flen
+#ifdef __RISCV_HARD_FLOAT
 
   /* Store the current FP environment in envp*/
 
diff --git a/newlib/libm/machine/riscv/feraiseexcept.c b/newlib/libm/machine/riscv/feraiseexcept.c
index 6f28632d1..817fa6274 100644
--- a/newlib/libm/machine/riscv/feraiseexcept.c
+++ b/newlib/libm/machine/riscv/feraiseexcept.c
@@ -32,6 +32,7 @@
 */
 
 #include <fenv.h>
+#include "riscv_math.h"
 
 /* This implementation is intended to comply with the following
  * specification:
@@ -58,7 +59,7 @@ int feraiseexcept(int excepts)
 
   excepts &= FE_ALL_EXCEPT;
 
-#if __riscv_flen
+#ifdef __RISCV_HARD_FLOAT
 
   /* Set the requested exception flags */
 
diff --git a/newlib/libm/machine/riscv/fesetenv.c b/newlib/libm/machine/riscv/fesetenv.c
index 943b272b7..a752c45d6 100644
--- a/newlib/libm/machine/riscv/fesetenv.c
+++ b/newlib/libm/machine/riscv/fesetenv.c
@@ -32,6 +32,7 @@
 */
 
 #include <fenv.h>
+#include "riscv_math.h"
 
 /* This implementation is intended to comply with the following
  * specification:
@@ -54,7 +55,7 @@
 int fesetenv(const fenv_t *envp)
 {
 
-#if __riscv_flen
+#ifdef __RISCV_HARD_FLOAT
 
   /* Set environment (FCSR) */
 
diff --git a/newlib/libm/machine/riscv/fesetexceptflag.c b/newlib/libm/machine/riscv/fesetexceptflag.c
index 04400f4ff..8c70bbd00 100644
--- a/newlib/libm/machine/riscv/fesetexceptflag.c
+++ b/newlib/libm/machine/riscv/fesetexceptflag.c
@@ -32,6 +32,7 @@
 */
 
 #include <fenv.h>
+#include "riscv_math.h"
 
 /* This implementation is intended to comply with the following
  * specification:
@@ -53,7 +54,7 @@
 int fesetexceptflag(const fexcept_t *flagp, int excepts)
 {
 
-#if __riscv_flen
+#ifdef __RISCV_HARD_FLOAT
 
   /* Mask excepts to be sure only supported flag bits are set */
 
diff --git a/newlib/libm/machine/riscv/fesetround.c b/newlib/libm/machine/riscv/fesetround.c
index b2451c71b..76585261d 100644
--- a/newlib/libm/machine/riscv/fesetround.c
+++ b/newlib/libm/machine/riscv/fesetround.c
@@ -32,6 +32,7 @@
 */
 
 #include <fenv.h>
+#include "riscv_math.h"
 
 /* This implementation is intended to comply with the following
  * specification:
@@ -48,7 +49,7 @@
 int fesetround(int round)
 {
 
-#if __riscv_flen
+#ifdef __RISCV_HARD_FLOAT
 
   /* Mask round to be sure only valid rounding bits are set */
 
diff --git a/newlib/libm/machine/riscv/fetestexcept.c b/newlib/libm/machine/riscv/fetestexcept.c
index 55d880c99..8ed0d5ffa 100644
--- a/newlib/libm/machine/riscv/fetestexcept.c
+++ b/newlib/libm/machine/riscv/fetestexcept.c
@@ -32,6 +32,7 @@
 */
 
 #include <fenv.h>
+#include "riscv_math.h"
 
 /* This implementation is intended to comply with the following
  * specification:
@@ -47,7 +48,7 @@
 int fetestexcept(int excepts)
 {
 
-#if __riscv_flen
+#ifdef __RISCV_HARD_FLOAT
 
   /* Mask excepts to be sure only supported flag bits are set */
 
diff --git a/newlib/libm/machine/riscv/feupdateenv.c b/newlib/libm/machine/riscv/feupdateenv.c
index 737095c2b..90235d021 100644
--- a/newlib/libm/machine/riscv/feupdateenv.c
+++ b/newlib/libm/machine/riscv/feupdateenv.c
@@ -32,6 +32,7 @@
 */
 
 #include <fenv.h>
+#include "riscv_math.h"
 
 /* This implementation is intended to comply with the following
  * specification:
@@ -50,7 +51,7 @@
 int feupdateenv(const fenv_t *envp)
 {
 
-#if __riscv_flen
+#ifdef __RISCV_HARD_FLOAT
 
   /* Get current exception flags */
 
diff --git a/newlib/libm/machine/riscv/riscv_math.h b/newlib/libm/machine/riscv/riscv_math.h
index 38948ca12..31220ba0e 100644
--- a/newlib/libm/machine/riscv/riscv_math.h
+++ b/newlib/libm/machine/riscv/riscv_math.h
@@ -38,7 +38,13 @@
 
 
 
-#ifdef __riscv_flen
+#if defined(__riscv_flen) || defined(__riscv_zfinx)
+
+#if (__riscv_flen >= 64) || defined(__riscv_zdinx)
+#define __RISCV_HARD_FLOAT 64
+#else
+#define __RISCV_HARD_FLOAT 32
+#endif
 
 #define FCLASS_NEG_INF       (1 << 0)
 #define FCLASS_NEG_NORMAL    (1 << 1)
@@ -58,7 +64,7 @@
 #define FCLASS_SUBNORMAL     (FCLASS_NEG_SUBNORMAL | FCLASS_POS_SUBNORMAL)
 #define FCLASS_NAN           (FCLASS_SNAN | FCLASS_QNAN)
 
-#if __riscv_flen >= 64
+#if (__riscv_flen >= 64) || defined(__riscv_zdinx)
 static inline long _fclass_d(double x){
   long fclass;
   __asm __volatile ("fclass.d\t%0, %1" : "=r" (fclass) : "f" (x));
@@ -66,7 +72,7 @@ static inline long _fclass_d(double x){
 }
 #endif
 
-#if __riscv_flen >= 32
+#if (__riscv_flen >= 32) || defined(__riscv_zfinx)
 static inline long _fclass_f(float x){
   long fclass;
   __asm __volatile ("fclass.s\t%0, %1" : "=r" (fclass) : "f" (x));
diff --git a/newlib/libm/machine/riscv/s_copysign.c b/newlib/libm/machine/riscv/s_copysign.c
index 047535578..876e4a80e 100644
--- a/newlib/libm/machine/riscv/s_copysign.c
+++ b/newlib/libm/machine/riscv/s_copysign.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64
 
 double
 copysign (double x, double y)
diff --git a/newlib/libm/machine/riscv/s_fabs.c b/newlib/libm/machine/riscv/s_fabs.c
index abf7d2c0f..bb26d3d0a 100644
--- a/newlib/libm/machine/riscv/s_fabs.c
+++ b/newlib/libm/machine/riscv/s_fabs.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64
 
 double
 fabs (double x)
diff --git a/newlib/libm/machine/riscv/s_finite.c b/newlib/libm/machine/riscv/s_finite.c
index 1f1f2244d..d9ad888a4 100644
--- a/newlib/libm/machine/riscv/s_finite.c
+++ b/newlib/libm/machine/riscv/s_finite.c
@@ -38,8 +38,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64
 #include "riscv_math.h"
 int finite(double x)
 {
diff --git a/newlib/libm/machine/riscv/s_fmax.c b/newlib/libm/machine/riscv/s_fmax.c
index bc174d0a0..059b71c47 100644
--- a/newlib/libm/machine/riscv/s_fmax.c
+++ b/newlib/libm/machine/riscv/s_fmax.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64
 
 double
 fmax (double x, double y)
diff --git a/newlib/libm/machine/riscv/s_fmin.c b/newlib/libm/machine/riscv/s_fmin.c
index 13dbbf5dd..c62dd868d 100644
--- a/newlib/libm/machine/riscv/s_fmin.c
+++ b/newlib/libm/machine/riscv/s_fmin.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64
 
 double
 fmin (double x, double y)
diff --git a/newlib/libm/machine/riscv/s_fpclassify.c b/newlib/libm/machine/riscv/s_fpclassify.c
index 8112d4f78..42b4e9fcb 100644
--- a/newlib/libm/machine/riscv/s_fpclassify.c
+++ b/newlib/libm/machine/riscv/s_fpclassify.c
@@ -33,11 +33,10 @@
  * OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include <math.h>
-
-#if defined(__riscv_flen) && __riscv_flen >= 64
-
 #include "riscv_math.h"
 
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64
+
 int
 __fpclassifyd (double x)
 {
diff --git a/newlib/libm/machine/riscv/s_isinf.c b/newlib/libm/machine/riscv/s_isinf.c
index 3d6d685a3..2860b3f88 100644
--- a/newlib/libm/machine/riscv/s_isinf.c
+++ b/newlib/libm/machine/riscv/s_isinf.c
@@ -35,10 +35,10 @@
 
 #include <math.h>
 #include <ieeefp.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64
 
-#include "riscv_math.h"
 #undef isinf
 
 int
diff --git a/newlib/libm/machine/riscv/s_isnan.c b/newlib/libm/machine/riscv/s_isnan.c
index a0209729a..96185cd9a 100644
--- a/newlib/libm/machine/riscv/s_isnan.c
+++ b/newlib/libm/machine/riscv/s_isnan.c
@@ -35,10 +35,10 @@
 
 #include <math.h>
 #include <ieeefp.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64
 
-#include "riscv_math.h"
 #undef isnan
 
 int
diff --git a/newlib/libm/machine/riscv/s_llrint.c b/newlib/libm/machine/riscv/s_llrint.c
index 3f93e60b8..39aeb1dbf 100644
--- a/newlib/libm/machine/riscv/s_llrint.c
+++ b/newlib/libm/machine/riscv/s_llrint.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 64 && __riscv_xlen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64 && __riscv_xlen >= 64
 long long int
 llrint (double x)
 {
diff --git a/newlib/libm/machine/riscv/s_llround.c b/newlib/libm/machine/riscv/s_llround.c
index ff41394cf..538ae9a18 100644
--- a/newlib/libm/machine/riscv/s_llround.c
+++ b/newlib/libm/machine/riscv/s_llround.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 64 && __riscv_xlen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64 && __riscv_xlen >= 64
 long long int
 llround(double x)
 {
diff --git a/newlib/libm/machine/riscv/s_lrint.c b/newlib/libm/machine/riscv/s_lrint.c
index 0e9a9bc8b..9bed894ee 100644
--- a/newlib/libm/machine/riscv/s_lrint.c
+++ b/newlib/libm/machine/riscv/s_lrint.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64
 long int
 lrint (double x)
 {
diff --git a/newlib/libm/machine/riscv/s_lround.c b/newlib/libm/machine/riscv/s_lround.c
index 5be778834..8f15a0ad7 100644
--- a/newlib/libm/machine/riscv/s_lround.c
+++ b/newlib/libm/machine/riscv/s_lround.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 64
 long int
 lround (double x)
 {
diff --git a/newlib/libm/machine/riscv/sf_copysign.c b/newlib/libm/machine/riscv/sf_copysign.c
index 31b1321ad..88afbe2f8 100644
--- a/newlib/libm/machine/riscv/sf_copysign.c
+++ b/newlib/libm/machine/riscv/sf_copysign.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32
 
 float
 copysignf (float x, float y)
diff --git a/newlib/libm/machine/riscv/sf_fabs.c b/newlib/libm/machine/riscv/sf_fabs.c
index 1ca92d30d..ac7a4e0d8 100644
--- a/newlib/libm/machine/riscv/sf_fabs.c
+++ b/newlib/libm/machine/riscv/sf_fabs.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32
 
 float
 fabsf (float x)
diff --git a/newlib/libm/machine/riscv/sf_finite.c b/newlib/libm/machine/riscv/sf_finite.c
index a17b0fa36..690985567 100644
--- a/newlib/libm/machine/riscv/sf_finite.c
+++ b/newlib/libm/machine/riscv/sf_finite.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32
 
 #include "riscv_math.h"
 int finitef(float x)
diff --git a/newlib/libm/machine/riscv/sf_fmax.c b/newlib/libm/machine/riscv/sf_fmax.c
index 7b18f0062..e2d4ad774 100644
--- a/newlib/libm/machine/riscv/sf_fmax.c
+++ b/newlib/libm/machine/riscv/sf_fmax.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32
 
 float
 fmaxf (float x, float y)
diff --git a/newlib/libm/machine/riscv/sf_fmin.c b/newlib/libm/machine/riscv/sf_fmin.c
index 771613338..7387d46d3 100644
--- a/newlib/libm/machine/riscv/sf_fmin.c
+++ b/newlib/libm/machine/riscv/sf_fmin.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32
 
 float
 fminf (float x, float y)
diff --git a/newlib/libm/machine/riscv/sf_fpclassify.c b/newlib/libm/machine/riscv/sf_fpclassify.c
index dee9a7a25..9b1640853 100644
--- a/newlib/libm/machine/riscv/sf_fpclassify.c
+++ b/newlib/libm/machine/riscv/sf_fpclassify.c
@@ -33,8 +33,9 @@
  * OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32
 
 #include "riscv_math.h"
 
diff --git a/newlib/libm/machine/riscv/sf_isinf.c b/newlib/libm/machine/riscv/sf_isinf.c
index 0c60f33af..d66874694 100644
--- a/newlib/libm/machine/riscv/sf_isinf.c
+++ b/newlib/libm/machine/riscv/sf_isinf.c
@@ -35,10 +35,10 @@
 
 #include <math.h>
 #include <ieeefp.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32
 
-#include "riscv_math.h"
 #undef isinff
 
 int
diff --git a/newlib/libm/machine/riscv/sf_isnan.c b/newlib/libm/machine/riscv/sf_isnan.c
index e38abf4ab..75b17f151 100644
--- a/newlib/libm/machine/riscv/sf_isnan.c
+++ b/newlib/libm/machine/riscv/sf_isnan.c
@@ -35,10 +35,10 @@
 
 #include <math.h>
 #include <ieeefp.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32
 
-#include "riscv_math.h"
 #undef isnanf
 
 int
diff --git a/newlib/libm/machine/riscv/sf_llrint.c b/newlib/libm/machine/riscv/sf_llrint.c
index 58f2e5371..9be28402c 100644
--- a/newlib/libm/machine/riscv/sf_llrint.c
+++ b/newlib/libm/machine/riscv/sf_llrint.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32 && __riscv_xlen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32 && __riscv_xlen >= 64
 long long int
 llrintf (float x)
 {
diff --git a/newlib/libm/machine/riscv/sf_llround.c b/newlib/libm/machine/riscv/sf_llround.c
index 389da692e..c378eb0cb 100644
--- a/newlib/libm/machine/riscv/sf_llround.c
+++ b/newlib/libm/machine/riscv/sf_llround.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32 && __riscv_xlen >= 64
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32 && __riscv_xlen >= 64
 long long int
 llroundf (float x)
 {
diff --git a/newlib/libm/machine/riscv/sf_lrint.c b/newlib/libm/machine/riscv/sf_lrint.c
index 4f80a9339..13320eb15 100644
--- a/newlib/libm/machine/riscv/sf_lrint.c
+++ b/newlib/libm/machine/riscv/sf_lrint.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32
 long int
 lrintf (float x)
 {
diff --git a/newlib/libm/machine/riscv/sf_lround.c b/newlib/libm/machine/riscv/sf_lround.c
index dda6d984e..398dfd2d8 100644
--- a/newlib/libm/machine/riscv/sf_lround.c
+++ b/newlib/libm/machine/riscv/sf_lround.c
@@ -34,8 +34,9 @@
  */
 
 #include <math.h>
+#include "riscv_math.h"
 
-#if defined(__riscv_flen) && __riscv_flen >= 32
+#if defined(__RISCV_HARD_FLOAT) && __RISCV_HARD_FLOAT >= 32
 long int
 lroundf(float x)
 {
-- 
2.40.1


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

* Re: [PATCH] RISC-V: Support Zfinx/Zdinx extension.
  2023-07-26 10:03 [PATCH] RISC-V: Support Zfinx/Zdinx extension Kito Cheng
@ 2023-07-26 13:27 ` Corinna Vinschen
  2023-10-10  5:26 ` Sebastian Huber
  1 sibling, 0 replies; 3+ messages in thread
From: Corinna Vinschen @ 2023-07-26 13:27 UTC (permalink / raw)
  To: Kito Cheng; +Cc: newlib, kito.cheng, Jesse Huang

On Jul 26 18:03, Kito Cheng via Newlib wrote:
> Zfinx/Zdinx are new extensions ratified in 2022, it similar to F/D extensions,
> support hard float operation for single/double precision, but the difference
> between Zfinx/Zdinx and F/D is Zfinx/Zdinx is operating under general purpose
> registers rather than dedicated floating-point registers.
> 
> This patch improve the hard float support detection for RISC-V port, so
> that Zfinx/Zdinx can have better/right performance.
> 
> Co-authored-by: Jesse Huang <jesse.huang@sifive.com>
> ---
>  newlib/libc/include/machine/ieeefp.h        |  4 ++--
>  newlib/libc/machine/riscv/ieeefp.c          | 10 +++++-----
>  newlib/libc/machine/riscv/sys/fenv.h        |  2 +-
>  newlib/libm/common/math_config.h            |  6 ++++--
>  newlib/libm/machine/riscv/e_sqrt.c          |  2 +-
>  newlib/libm/machine/riscv/ef_sqrt.c         |  2 +-
>  newlib/libm/machine/riscv/feclearexcept.c   |  3 ++-
>  newlib/libm/machine/riscv/fegetenv.c        |  3 ++-
>  newlib/libm/machine/riscv/fegetexceptflag.c |  3 ++-
>  newlib/libm/machine/riscv/fegetround.c      |  3 ++-
>  newlib/libm/machine/riscv/feholdexcept.c    |  3 ++-
>  newlib/libm/machine/riscv/feraiseexcept.c   |  3 ++-
>  newlib/libm/machine/riscv/fesetenv.c        |  3 ++-
>  newlib/libm/machine/riscv/fesetexceptflag.c |  3 ++-
>  newlib/libm/machine/riscv/fesetround.c      |  3 ++-
>  newlib/libm/machine/riscv/fetestexcept.c    |  3 ++-
>  newlib/libm/machine/riscv/feupdateenv.c     |  3 ++-
>  newlib/libm/machine/riscv/riscv_math.h      | 12 +++++++++---
>  newlib/libm/machine/riscv/s_copysign.c      |  3 ++-
>  newlib/libm/machine/riscv/s_fabs.c          |  3 ++-
>  newlib/libm/machine/riscv/s_finite.c        |  3 ++-
>  newlib/libm/machine/riscv/s_fmax.c          |  3 ++-
>  newlib/libm/machine/riscv/s_fmin.c          |  3 ++-
>  newlib/libm/machine/riscv/s_fpclassify.c    |  5 ++---
>  newlib/libm/machine/riscv/s_isinf.c         |  4 ++--
>  newlib/libm/machine/riscv/s_isnan.c         |  4 ++--
>  newlib/libm/machine/riscv/s_llrint.c        |  3 ++-
>  newlib/libm/machine/riscv/s_llround.c       |  3 ++-
>  newlib/libm/machine/riscv/s_lrint.c         |  3 ++-
>  newlib/libm/machine/riscv/s_lround.c        |  3 ++-
>  newlib/libm/machine/riscv/sf_copysign.c     |  3 ++-
>  newlib/libm/machine/riscv/sf_fabs.c         |  3 ++-
>  newlib/libm/machine/riscv/sf_finite.c       |  3 ++-
>  newlib/libm/machine/riscv/sf_fmax.c         |  3 ++-
>  newlib/libm/machine/riscv/sf_fmin.c         |  3 ++-
>  newlib/libm/machine/riscv/sf_fpclassify.c   |  3 ++-
>  newlib/libm/machine/riscv/sf_isinf.c        |  4 ++--
>  newlib/libm/machine/riscv/sf_isnan.c        |  4 ++--
>  newlib/libm/machine/riscv/sf_llrint.c       |  3 ++-
>  newlib/libm/machine/riscv/sf_llround.c      |  3 ++-
>  newlib/libm/machine/riscv/sf_lrint.c        |  3 ++-
>  newlib/libm/machine/riscv/sf_lround.c       |  3 ++-
>  42 files changed, 93 insertions(+), 56 deletions(-)

Pushed.


Thanks,
Corinna


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

* Re: [PATCH] RISC-V: Support Zfinx/Zdinx extension.
  2023-07-26 10:03 [PATCH] RISC-V: Support Zfinx/Zdinx extension Kito Cheng
  2023-07-26 13:27 ` Corinna Vinschen
@ 2023-10-10  5:26 ` Sebastian Huber
  1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Huber @ 2023-10-10  5:26 UTC (permalink / raw)
  To: Kito Cheng, newlib, kito.cheng; +Cc: Jesse Huang

On 26.07.23 12:03, Kito Cheng via Newlib wrote:
> Zfinx/Zdinx are new extensions ratified in 2022, it similar to F/D 
> extensions, support hard float operation for single/double precision, 
> but the difference between Zfinx/Zdinx and F/D is Zfinx/Zdinx is 
> operating under general purpose registers rather than dedicated 
> floating-point registers. This patch improve the hard float support 
> detection for RISC-V port, so that Zfinx/Zdinx can have better/right 
> performance. Co-authored-by: Jesse Huang <jesse.huang@sifive.com>

This patch probably broke the RTEMS build of Newlib:

../../../../../gnu-mirror-gcc-d04fe55/newlib/libm/machine/riscv/fesetround.c: 
In function 'fesetround':
../../../../../gnu-mirror-gcc-d04fe55/newlib/libm/machine/riscv/fesetround.c:56:12: 
error: 'FE_RMODE_MASK' undeclared (first use in this function)
    56 |   round &= FE_RMODE_MASK;
       |            ^~~~~~~~~~~~~
../../../../../gnu-mirror-gcc-d04fe55/newlib/libm/machine/riscv/fesetround.c:56:12: 
note: each undeclared identifier is reported only once for each function 
it appears in
make[6]: *** [Makefile:48845: libm/machine/riscv/libm_a-fesetround.o] 
Error 1
make[6]: *** Waiting for unfinished jobs....
../../../../../gnu-mirror-gcc-d04fe55/newlib/libm/complex/cprojl.c: In 
function 'cprojl':
../../../../../gnu-mirror-gcc-d04fe55/newlib/libm/complex/cprojl.c:60:18: 
warning: implicit declaration of function 'copysignl'; did you mean 
'copysignf'? [-Wimplicit-function-declaration]
    60 |   IMAG_PART(w) = copysignl(0.0L, cimagl(z));
       |                  ^~~~~~~~~
       |                  copysignf
make[6]: Leaving directory 
'/tmp/sh/b-rsb/riscv-rtems6-gcc-d04fe55-newlib-fe5886a-x86_64-linux-gnu-1/build/riscv-rtems6/rv32imaf/ilp32f/newlib'

We have

#if defined(__riscv_f) || defined(__riscv_zfinx)

[...]

/* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA:
  * Version 2.1", Section 8.2, "Floating-Point Control and Status
  * Register":
  *
  * Rounding Mode  Mnemonic Meaning  Meaning
  * -------------  ----------------  -------
  * 000            RNE               Round to Nearest, ties to Even
  * 001            RTZ               Round towards Zero
  * 010            RDN               Round Down (towards −∞)
  * 011            RUP               Round Up (towards +∞)
  * 100            RMM               Round to Nearest, ties to Max Magnitude
  * 101                              Invalid. Reserved for future use.
  * 110                              Invalid. Reserved for future use.
  * 111                              In instruction’s rm field, selects 
dynamic rounding mode;
  *                                  In Rounding Mode register, Invalid
  */

#define FE_TONEAREST_MM 0x00000004
#define FE_UPWARD     	0x00000003
#define FE_DOWNWARD   	0x00000002
#define FE_TOWARDZERO 	0x00000001
#define FE_TONEAREST  	0x00000000

#define FE_RMODE_MASK   0x7

vs.

int fesetround(int round)
{

#ifdef __RISCV_HARD_FLOAT

   /* Mask round to be sure only valid rounding bits are set */

   round &= FE_RMODE_MASK;

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

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

end of thread, other threads:[~2023-10-10  5:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-26 10:03 [PATCH] RISC-V: Support Zfinx/Zdinx extension Kito Cheng
2023-07-26 13:27 ` Corinna Vinschen
2023-10-10  5:26 ` Sebastian Huber

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