path: root/src
diff options
authorSzabolcs Nagy <>2018-11-29 23:33:40 +0000
committerRich Felker <>2019-04-17 13:12:08 -0400
commit3c3763fc529114e209aea08336a420c5d5be4dc2 (patch)
tree6ab36f16fb49fa0b92c433b5a9fe080237326f1a /src
parent4f8acf953ccf1a978a3378db7fb1e8d5a7afbca1 (diff)
math: add macros for static branch prediction hints
These don't have an effectw with -Os so not useful with default settings other than documenting the expectation. With --enable-optimize=internal,malloc,string,math the code size increases by 18K on x86_64 and performance varies in -2% .. +10%.
Diffstat (limited to 'src')
1 files changed, 9 insertions, 0 deletions
diff --git a/src/internal/libm.h b/src/internal/libm.h
index 62da4bdb..28537603 100644
--- a/src/internal/libm.h
+++ b/src/internal/libm.h
@@ -59,6 +59,15 @@ union ldshape {
#error Unsupported long double representation
+/* Helps static branch prediction so hot path can be better optimized. */
+#ifdef __GNUC__
+#define predict_true(x) __builtin_expect(!!(x), 1)
+#define predict_false(x) __builtin_expect(x, 0)
+#define predict_true(x) (x)
+#define predict_false(x) (x)
/* Evaluate an expression as the specified type. With standard excess
precision handling a type cast or assignment is enough (with
-ffloat-store an assignment is required, in old compilers argument