From: compudj Date: Wed, 14 Sep 2005 16:40:20 +0000 (+0000) Subject: add guint32_before and after X-Git-Tag: v0.12.20~2307 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2ac312e383c680ae87e8c4945c9d411b288d4bf7;p=lttv.git add guint32_before and after git-svn-id: http://ltt.polymtl.ca/svn@1182 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/ltt/compiler.h b/ltt/branches/poly/ltt/compiler.h index cef7a476..1ab188f8 100644 --- a/ltt/branches/poly/ltt/compiler.h +++ b/ltt/branches/poly/ltt/compiler.h @@ -23,4 +23,30 @@ #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) + +/* + * Check at compile time that something is of a particular type. + * Always evaluates to 1 so you may use it easily in comparisons. + */ +#define typecheck(type,x) \ +({ type __dummy; \ + typeof(x) __dummy2; \ + (void)(&__dummy == &__dummy2); \ + 1; \ +}) + +/* Deal with 32 wrap correctly */ +#define guint32_after(a,b) \ + (typecheck(guint32, a) && \ + typecheck(guint32, b) && \ + ((gint32)(b) - (gint32)(a) < 0)) +#define guint32_before(a,b) guint32_after(b,a) + +#define guint32_after_eq(a,b) \ + (typecheck(guint32, a) && \ + typecheck(guint32, b) && \ + ((gint32)(b) - (gint32)(a) <= 0)) +#define guint32_before_eq(a,b) guint32_after_eq(b,a) + + #endif //COMPILER_H