summaryrefslogtreecommitdiff
path: root/compiler.h
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-10 09:35:26 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-10 09:35:26 -0700
commit51997d3d44a9279508b16e9f3d5e2de173ece7c2 (patch)
treedfd4e490aa051890565126e945daa4618a4464e4 /compiler.h
parent8cc5aa78291843c10931ed3c738290df0b643279 (diff)
downloadnasm-51997d3d44a9279508b16e9f3d5e2de173ece7c2.tar.gz
Introduce likely/unlikely macros, use them in saa.c
Introduce the likely() and unlikely() macros, as used in Linux. They are compiler-dependent hints that a particular boolean expression is likely to be true or false, respectively. Currently only implemented for gcc.
Diffstat (limited to 'compiler.h')
-rw-r--r--compiler.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler.h b/compiler.h
index 01e11277..51f49838 100644
--- a/compiler.h
+++ b/compiler.h
@@ -110,4 +110,16 @@ char *strsep(char **, const char *);
# define X86_MEMORY 0
#endif
+/*
+ * Hints to the compiler that a particular branch of code is more or
+ * less likely to be taken.
+ */
+#if defined(__GNUC__) && __GNUC__ >= 3
+# define likely(x) __builtin_expect(!!(x), 1)
+# define unlikely(x) __builtin_expect(!!(x), 0)
+#else
+# define likely(x) (!!(x))
+# define unlikely(x) (!!(x))
+#endif
+
#endif /* NASM_COMPILER_H */