Skip to content

Commit 8a934d6

Browse files
committed
Use isinf builtin for clang, for performance.
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().
1 parent 266b6ac commit 8a934d6

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/include/port.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,20 @@ extern int getpeereid(int sock, uid_t *uid, gid_t *gid);
343343

344344
#ifndef HAVE_ISINF
345345
extern int isinf(double x);
346-
#endif
346+
#else
347+
/*
348+
* Glibc doesn't use the builtin for clang due to a *gcc* bug in a version
349+
* newer than the gcc compatibility clang claims to have. This would cause a
350+
* *lot* of superflous function calls, therefore revert when using clang.
351+
*/
352+
#ifdef __clang__
353+
/* needs to be separate to not confuse other compilers */
354+
#if __has_builtin(__builtin_isinf)
355+
#undef isinf
356+
#define isinf __builtin_isinf
357+
#endif /* __has_builtin(isinf) */
358+
#endif /* __clang__ */
359+
#endif /* !HAVE_ISINF */
347360

348361
#ifndef HAVE_MKDTEMP
349362
extern char *mkdtemp(char *path);

0 commit comments

Comments
 (0)