On Mon, Nov 04, 2019 at 01:30:58PM -0600, Eric Blake wrote:
On 11/2/19 4:24 PM, Richard W.M. Jones wrote:
For GCC only, define unlikely() macro. Use it on error paths to move code out of the hot path.
In the server only, use the debug() macro (don't call nbdkit_debug directly). This macro checks the verbose flag and moves the call to nbdkit_debug out of the hot path. ---
+++ b/server/internal.h @@ -45,6 +45,17 @@ #include "cleanup.h" #include "nbd-protocol.h" +/* Define unlikely macro, but only for GCC. These are used to move + * debug and error handling code out of hot paths. + */ +#if defined(__GNUC__) +#define unlikely(x) __builtin_expect (!!(x), 0) +#define if_verbose if (unlikely (verbose))
Doesn't clang define __GNUC__, at which point all of our supported compilers (since we require __attribute__((cleanup)) support) also have __builtin_expect?
+#else +#define unlikely(x) (x) +#define if_verbose if (verbose) +#endif
Or put another way, this #else may be dead code, and the #if may be unnecessary compared to just unconditionally defining unlikely() and if_verbose.
Yes ... https://bugs.llvm.org/show_bug.cgi?id=30446 However it seems to be fine in this particular case. I agree the other branch is dead code but it's probably best to keep it for future portability. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top