@@ -25,6 +25,11 @@
double
__ceil (double x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.d rounds to an integer with a static rounding mode
+ (rup for ceil) without raising the inexact exception. */
+ return __builtin_ceil (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -48,6 +53,7 @@ __ceil (double x)
}
return x;
+#endif
}
libm_alias_double (__ceil, ceil)
@@ -25,6 +25,11 @@
double
__floor (double x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.d rounds to an integer with a static rounding mode
+ (rdn for floor) without raising the inexact exception. */
+ return __builtin_floor (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -48,6 +53,7 @@ __floor (double x)
}
return x;
+#endif
}
libm_alias_double (__floor, floor)
@@ -24,6 +24,12 @@
double
__nearbyint (double x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.d rounds to an integer in the current rounding mode
+ without raising the inexact exception, matching nearbyint, and
+ handles NaN and out-of-range inputs in one instruction. */
+ return __builtin_nearbyint (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -47,6 +53,7 @@ __nearbyint (double x)
}
return x;
+#endif
}
libm_alias_double (__nearbyint, nearbyint)
@@ -25,6 +25,12 @@
double
__rint (double x)
{
+#ifdef __riscv_zfa
+ /* Zfa froundnx.d rounds to an integer in the current rounding mode,
+ raises the inexact exception for non-integer values, and handles
+ NaN and out-of-range inputs, implementing rint in one instruction. */
+ return __builtin_rint (x);
+#else
bool nan;
double mag;
@@ -48,6 +54,7 @@ __rint (double x)
}
return x;
+#endif
}
libm_alias_double (__rint, rint)
@@ -25,6 +25,12 @@
double
__round (double x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.d rounds to an integer with a static rounding mode
+ (rmm, round half away from zero, for round) without raising the
+ inexact exception. */
+ return __builtin_round (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -48,6 +54,7 @@ __round (double x)
}
return x;
+#endif
}
libm_alias_double (__round, round)
@@ -25,6 +25,12 @@
double
__roundeven (double x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.d rounds to an integer with a static rounding mode
+ (rne, round half to even, for roundeven) without raising the
+ inexact exception. */
+ return __builtin_roundeven (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -48,6 +54,7 @@ __roundeven (double x)
}
return x;
+#endif
}
libm_alias_double (__roundeven, roundeven)
@@ -25,6 +25,11 @@
double
__trunc (double x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.d rounds to an integer with a static rounding mode
+ (rtz for trunc) without raising the inexact exception. */
+ return __builtin_trunc (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -48,6 +53,7 @@ __trunc (double x)
}
return x;
+#endif
}
libm_alias_double (__trunc, trunc)
@@ -25,6 +25,11 @@
float
__ceilf (float x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.s rounds to an integer with a static rounding mode
+ (rup for ceil) without raising the inexact exception. */
+ return __builtin_ceilf (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -48,6 +53,7 @@ __ceilf (float x)
}
return x;
+#endif
}
libm_alias_float (__ceil, ceil)
@@ -25,6 +25,11 @@
float
__floorf (float x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.s rounds to an integer with a static rounding mode
+ (rdn for floor) without raising the inexact exception. */
+ return __builtin_floorf (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -48,6 +53,7 @@ __floorf (float x)
}
return x;
+#endif
}
libm_alias_float (__floor, floor)
@@ -24,6 +24,12 @@
float
__nearbyintf (float x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.s rounds to an integer in the current rounding mode
+ without raising the inexact exception, matching nearbyintf, and
+ handles NaN and out-of-range inputs in one instruction. */
+ return __builtin_nearbyintf (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -47,6 +53,7 @@ __nearbyintf (float x)
}
return x;
+#endif
}
libm_alias_float (__nearbyint, nearbyint)
@@ -25,6 +25,12 @@
float
__rintf (float x)
{
+#ifdef __riscv_zfa
+ /* Zfa froundnx.s rounds to an integer in the current rounding mode,
+ raises the inexact exception for non-integer values, and handles
+ NaN and out-of-range inputs, implementing rintf in one instruction. */
+ return __builtin_rintf (x);
+#else
bool nan;
float mag;
@@ -48,6 +54,7 @@ __rintf (float x)
}
return x;
+#endif
}
libm_alias_float (__rint, rint)
@@ -25,6 +25,12 @@
float
__roundevenf (float x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.s rounds to an integer with a static rounding mode
+ (rne, round half to even, for roundeven) without raising the
+ inexact exception. */
+ return __builtin_roundevenf (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -48,6 +54,7 @@ __roundevenf (float x)
}
return x;
+#endif
}
libm_alias_float (__roundeven, roundeven)
@@ -25,6 +25,12 @@
float
__roundf (float x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.s rounds to an integer with a static rounding mode
+ (rmm, round half away from zero, for round) without raising the
+ inexact exception. */
+ return __builtin_roundf (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -48,6 +54,7 @@ __roundf (float x)
}
return x;
+#endif
}
libm_alias_float (__round, round)
@@ -25,6 +25,11 @@
float
__truncf (float x)
{
+#ifdef __riscv_zfa
+ /* Zfa fround.s rounds to an integer with a static rounding mode
+ (rtz for trunc) without raising the inexact exception. */
+ return __builtin_truncf (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -48,6 +53,7 @@ __truncf (float x)
}
return x;
+#endif
}
libm_alias_float (__trunc, trunc)