summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2014-11-16 16:10:45 +0100
committerNick Wellnhofer <wellnhofer@aevum.de>2014-11-16 22:17:35 +0100
commit627326bed4e58cf457e8c8f2c45b2e6d7c316a54 (patch)
tree90fb81020f409b82d55acd5ca58f1074e55bfd9d
parent485ef21b95e257e9d9cbcaa804c3c164f1f49a80 (diff)
Feature test for __builtin_expect
-rw-r--r--src/CMakeLists.txt9
-rw-r--r--src/config.h.in1
-rw-r--r--src/html/houdini.h10
3 files changed, 16 insertions, 4 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4b13dd7..691e268 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -93,8 +93,13 @@ install(FILES cmark.h ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h
DESTINATION include
)
-include (CheckIncludeFile)
-CHECK_INCLUDE_FILE (stdbool.h HAVE_STDBOOL_H)
+# Feature tests
+include(CheckIncludeFile)
+include(CheckCSourceCompiles)
+CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
+CHECK_C_SOURCE_COMPILES(
+ "int main() { __builtin_expect(0,0); return 0; }"
+ HAVE___BUILTIN_EXPECT)
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
diff --git a/src/config.h.in b/src/config.h.in
index 2165d03..bd39c4e 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -6,3 +6,4 @@
typedef char bool;
#endif
+#cmakedefine HAVE___BUILTIN_EXPECT
diff --git a/src/html/houdini.h b/src/html/houdini.h
index b8ed0d9..9e1200e 100644
--- a/src/html/houdini.h
+++ b/src/html/houdini.h
@@ -6,10 +6,16 @@ extern "C" {
#endif
#include <stdint.h>
+#include "config.h"
#include "buffer.h"
-#define likely(x) __builtin_expect((x),1)
-#define unlikely(x) __builtin_expect((x),0)
+#ifdef HAVE___BUILTIN_EXPECT
+# define likely(x) __builtin_expect((x),1)
+# define unlikely(x) __builtin_expect((x),0)
+#else
+# define likely(x) (x)
+# define unlikely(x) (x)
+#endif
#ifdef HOUDINI_USE_LOCALE
# define _isxdigit(c) isxdigit(c)