summaryrefslogtreecommitdiff
path: root/lib/replace
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2009-09-17 09:07:17 -0700
committerAndrew Tridgell <tridge@samba.org>2009-09-17 15:19:25 -0700
commit6dfd10f476e0b74c36f73bfe17a68ca309c4c5ac (patch)
tree527782a69289aebb57d29ac41dcee0b1eacf01e9 /lib/replace
parent9e49ad558eb9daaf4df13579211378d8ba01815e (diff)
downloadsamba-6dfd10f476e0b74c36f73bfe17a68ca309c4c5ac.tar.gz
samba-6dfd10f476e0b74c36f73bfe17a68ca309c4c5ac.tar.bz2
samba-6dfd10f476e0b74c36f73bfe17a68ca309c4c5ac.zip
libreplace: added likely()/unlikely() macros for gcc
These macros allow the compile to better optimise code that has a lot of if statements. I particularly want to use this for our low level generated NDR code.
Diffstat (limited to 'lib/replace')
-rw-r--r--lib/replace/replace.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index 2db6aa1226..6424d10c0f 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -704,4 +704,23 @@ char *ufc_crypt(const char *key, const char *salt);
#endif
#endif
+/* these macros gain us a few percent of speed on gcc */
+#if (__GNUC__ >= 3)
+/* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
+ as its first argument */
+#ifndef likely
+#define likely(x) __builtin_expect(!!(x), 1)
+#endif
+#ifndef unlikely
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#endif
+#else
+#ifndef likely
+#define likely(x) (x)
+#endif
+#ifndef unlikely
+#define unlikely(x) (x)
+#endif
+#endif
+
#endif /* _LIBREPLACE_REPLACE_H */