Use GCC builtins for lrint functions if desired.

This patch is using the corresponding GCC builtin for lrintf, lrint,
lrintl and lrintf128 if the USE_FUNCTION_BUILTIN macros are defined to one
in math-use-builtins-function.h.

Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
This commit is contained in:
Xiaolin Tang 2022-11-23 11:44:56 +08:00 committed by caiyinyu
parent 948652e4f8
commit 2b23ab1fea
6 changed files with 43 additions and 17 deletions

View File

@ -0,0 +1,4 @@
#define USE_LRINT_BUILTIN 0
#define USE_LRINTF_BUILTIN 0
#define USE_LRINTL_BUILTIN 0
#define USE_LRINTF128_BUILTIN 0

View File

@ -37,5 +37,6 @@
#include <math-use-builtins-fmax.h>
#include <math-use-builtins-fmin.h>
#include <math-use-builtins-fabs.h>
#include <math-use-builtins-lrint.h>
#endif /* MATH_USE_BUILTINS_H */

View File

@ -25,17 +25,22 @@
#include <math_private.h>
#include <libm-alias-double.h>
#include <fix-fp-int-convert-overflow.h>
static const double two52[2] =
{
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
};
#include <math-use-builtins.h>
long int
__lrint (double x)
{
#if USE_LRINT_BUILTIN
return __builtin_lrint (x);
#else
/* Use generic implementation. */
static const double two52[2] =
{
4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
-4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
};
int32_t j0;
uint32_t i0, i1;
double w;
@ -119,6 +124,7 @@ __lrint (double x)
}
return sx ? -result : result;
#endif /* ! USE_LRINT_BUILTIN */
}
libm_alias_double (__lrint, lrint)

View File

@ -161,6 +161,8 @@
#define USE_COPYSIGNL_BUILTIN USE_COPYSIGNF128_BUILTIN
#undef USE_FMAL_BUILTIN
#define USE_FMAL_BUILTIN USE_FMAF128_BUILTIN
#undef USE_LRINTL_BUILTIN
#define USE_LRINTL_BUILTIN USE_LRINTF128_BUILTIN
/* IEEE function renames. */
#define __ieee754_acoshl __ieee754_acoshf128

View File

@ -25,17 +25,22 @@
#include <math_private.h>
#include <libm-alias-float.h>
#include <fix-fp-int-convert-overflow.h>
static const float two23[2] =
{
8.3886080000e+06, /* 0x4B000000 */
-8.3886080000e+06, /* 0xCB000000 */
};
#include <math-use-builtins.h>
long int
__lrintf (float x)
{
#if USE_LRINTF_BUILTIN
return __builtin_lrintf (x);
#else
/* Use generic implementation. */
static const float two23[2] =
{
8.3886080000e+06, /* 0x4B000000 */
-8.3886080000e+06, /* 0xCB000000 */
};
int32_t j0;
uint32_t i0;
float w;
@ -82,6 +87,7 @@ __lrintf (float x)
}
return sx ? -result : result;
#endif /* ! USE_LRINTF_BUILTIN */
}
libm_alias_float (__lrint, lrint)

View File

@ -24,16 +24,22 @@
#include <math_private.h>
#include <libm-alias-ldouble.h>
#include <fix-fp-int-convert-overflow.h>
#include <math-use-builtins.h>
static const _Float128 two112[2] =
{
L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
L(-5.19229685853482762853049632922009600E+33) /* 0xC06F000000000000, 0 */
};
long int
__lrintl (_Float128 x)
{
#if USE_LRINTL_BUILTIN
return __builtin_lrintl (x);
#else
/* Use generic implementation. */
static const _Float128 two112[2] =
{
L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
L(-5.19229685853482762853049632922009600E+33) /* 0xC06F000000000000, 0 */
};
int32_t j0;
uint64_t i0,i1;
_Float128 w;
@ -131,6 +137,7 @@ __lrintl (_Float128 x)
}
return sx ? -result : result;
#endif /* ! USE_LRINTL_BUILTIN */
}
libm_alias_ldouble (__lrint, lrint)