]> granicus.if.org Git - postgresql/commitdiff
Use isinf builtin for clang, for performance.
authorAndres Freund <andres@anarazel.de>
Wed, 28 Mar 2018 19:45:32 +0000 (12:45 -0700)
committerAndres Freund <andres@anarazel.de>
Wed, 28 Mar 2018 20:12:15 +0000 (13:12 -0700)
When compiling with clang glibc's definition of isinf() ends up
leading to and external libc function call. That's because there was a
bug in the builtin in an old gcc version, and clang claims
compatibility with an older version.  That causes clang to be
measurably slower for floating point heavy workloads than gcc.

To fix simply redirect isinf when using clang and clang confirms it
has __builtin_isinf().

src/include/port.h

index 3e528fa1725f94720cb2d9f68ae79581eb0d963e..a514ab758b5827cca2daf506ab437588ad2573c7 100644 (file)
@@ -343,7 +343,20 @@ extern int getpeereid(int sock, uid_t *uid, gid_t *gid);
 
 #ifndef HAVE_ISINF
 extern int     isinf(double x);
-#endif
+#else
+/*
+ * Glibc doesn't use the builtin for clang due to a *gcc* bug in a version
+ * newer than the gcc compatibility clang claims to have. This would cause a
+ * *lot* of superflous function calls, therefore revert when using clang.
+ */
+#ifdef __clang__
+/* needs to be separate to not confuse other compilers */
+#if __has_builtin(__builtin_isinf)
+#undef isinf
+#define isinf __builtin_isinf
+#endif                                                 /* __has_builtin(isinf) */
+#endif                                                 /* __clang__ */
+#endif                                                 /* !HAVE_ISINF */
 
 #ifndef HAVE_MKDTEMP
 extern char *mkdtemp(char *path);