X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Fcompiler.h;h=1ab188f871a4e21ba5fd370c7b39e7c4ed4b7df2;hb=2ac312e383c680ae87e8c4945c9d411b288d4bf7;hp=cef7a476d67f85f6a1e1334ce038c413eca040b3;hpb=540066bf56eb40ee393684212caf4c1fe0bd0b64;p=lttv.git 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