From def8bd0c541252e7f606c9286912eb67d3ac5929 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 24 Jun 2014 16:39:06 +0200 Subject: Add unlikely() --- libcrystfel/src/geometry.c | 2 +- libcrystfel/src/utils.h | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libcrystfel/src/geometry.c b/libcrystfel/src/geometry.c index 6ccaf3d8..c1d433c8 100644 --- a/libcrystfel/src/geometry.c +++ b/libcrystfel/src/geometry.c @@ -185,7 +185,7 @@ static Reflection *check_reflection(struct image *image, Crystal *cryst, && (fabs(rlow) > pr) && (fabs(rhigh) > pr) ) return NULL; - if ( rlow < rhigh ) { + if ( unlikely(rlow < rhigh) ) { ERROR("Reflection with rlow < rhigh!\n"); ERROR("%3i %3i %3i rlow = %e, rhigh = %e\n", h, k, l, rlow, rhigh); diff --git a/libcrystfel/src/utils.h b/libcrystfel/src/utils.h index 4478f179..2f2009d6 100644 --- a/libcrystfel/src/utils.h +++ b/libcrystfel/src/utils.h @@ -228,7 +228,6 @@ static inline int within_tolerance(double a, double b, double percent) /* Photon energy (eV) to wavelength (m) */ #define ph_eV_to_lambda(a) ph_en_to_lambda(eV_to_J(a)) -#define UNUSED __attribute__((unused)) /* ------------------------------ Message macros ---------------------------- */ @@ -261,6 +260,19 @@ extern pthread_mutex_t stderr_lock; extern char *check_prefix(char *prefix); extern char *safe_basename(const char *in); + +/* ------------------------------ Useful stuff ------------------------------ */ + +#if __GNUC__ >= 3 +#define UNUSED __attribute__((unused)) +#define likely(x) __builtin_expect (!!(x), 1) +#define unlikely(x) __builtin_expect (!!(x), 0) +#else +#define UNUSED +#define likely(x) (x) +#define unlikely(x) (x) +#endif + #ifdef __cplusplus } #endif -- cgit v1.2.3