From 0ddfa46b4443abfc6131ac8304a2209ac2b0f302 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Fri, 22 Feb 2008 14:11:03 +0000 Subject: [PATCH] Add an irint() function in inline asm for amd64 and i386. irint() is the same as lrint() except it returns int instead of long. Though the extern lrint() is fairly fast on these arches, it still takes about 12 cycles longer than the inline version, and 12 cycles is a lot in applications where [li]rint() is used to avoid slow conversions that are only a couple of times slower. This is only for internal use. The libm versions of *rint*() should also be inline, but that would take would take more header engineering. Implementing irint() instead of lrint() also avoids a conflict with the extern declaration of the latter. --- lib/msun/src/math_private.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/msun/src/math_private.h b/lib/msun/src/math_private.h index 1fcf14c68c3b..27c14bd795f9 100644 --- a/lib/msun/src/math_private.h +++ b/lib/msun/src/math_private.h @@ -221,6 +221,36 @@ cpackl(long double x, long double y) } #endif /* _COMPLEX_H */ +#ifdef __GNUCLIKE_ASM + +/* Asm versions of some functions. */ + +#ifdef __amd64__ +static __inline int +irint(double x) +{ + int n; + + asm("cvtsd2si %1,%0" : "=r" (n) : "Y" (x)); + return (n); +} +#define HAVE_EFFICIENT_IRINT +#endif + +#ifdef __i386__ +static __inline int +irint(double x) +{ + int n; + + asm("fistl %0" : "=m" (n) : "t" (x)); + return (n); +} +#define HAVE_EFFICIENT_IRINT +#endif + +#endif /* __GNUCLIKE_ASM */ + /* * ieee style elementary functions *