summaryrefslogtreecommitdiffstats
path: root/lib/msun
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>2008-02-22 14:11:03 +0000
committerbde <bde@FreeBSD.org>2008-02-22 14:11:03 +0000
commitaf1dfd5050193d3fca9fa2a2c4d96d20183fe15f (patch)
treeb84a97c8ced69438d49fa11ff0c9db93a3cf64f8 /lib/msun
parentd3a4e4141f36bdd5c9aaab68a7fb6cd09351b4ba (diff)
downloadFreeBSD-src-af1dfd5050193d3fca9fa2a2c4d96d20183fe15f.zip
FreeBSD-src-af1dfd5050193d3fca9fa2a2c4d96d20183fe15f.tar.gz
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.
Diffstat (limited to 'lib/msun')
-rw-r--r--lib/msun/src/math_private.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/msun/src/math_private.h b/lib/msun/src/math_private.h
index 1fcf14c..27c14bd 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
*
OpenPOWER on IntegriCloud