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