00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef MACROS_H
00014 #define MACROS_H
00015
00016
00017 #define MIN_VAL(t) (((t)(-1) > 0) ? (t)( 0) : (t)(((1L<<(sizeof(t)*8-1)) )))
00018 #define MAX_VAL(t) (((t)(-1) > 0) ? (t)(-1) : (t)(((1L<<(sizeof(t)*8-1))-1)))
00019
00020
00021 #if !defined(MIN)
00022 #if defined(__HIGHC__)
00023 #define MIN(x,y) _min(x,y)
00024 #define MAX(x,y) _max(x,y)
00025 #endif
00026
00027
00028 #if defined(__GNUG__)
00029 #define MIN(A,B) ((A) <? (B))
00030 #define MAX(A,B) ((A) >? (B))
00031 #endif
00032
00033
00034
00035 #if !defined(MIN)
00036 #define MIN(A,B) ((A) < (B)?(A):(B))
00037 #define MAX(A,B) ((A) > (B)?(A):(B))
00038 #endif
00039 #endif
00040
00041
00042
00043 #define _bound(a,b,c) MIN(c,MAX(b,a))
00044 #define _boundv(a,b,c) b = _bound(a,b,c)
00045 #define ABS(a) (((a) < (0)) ?-(a) : (a))
00046
00047
00048
00049 #define _count(a) (sizeof(a)/sizeof(a[0]))
00050
00051
00052 #define FLAG(f) (1L << (f))
00053 #define SETFLAG(v,f) ((v) |= FLAG(f))
00054 #define CLRFLAG(v,f) ((v) &=~FLAG(f))
00055 #define CHKFLAG(v,f) ((v) & FLAG(f) ? true : false)
00056
00057
00058 #if __GNUC__ >= 3
00059 #define __must_check __attribute__ ((warn_unused_result))
00060 #define __deprecated __attribute__ ((deprecated))
00061 #define __attrib_const __attribute__ ((__const__))
00062
00063
00064 #define likely(x) __builtin_expect (!!(x), 1)
00065 #define unlikely(x) __builtin_expect (!!(x), 0)
00066 #else
00067 #define __must_check
00068 #define __deprecated
00069 #define __attrib_const
00070 #define likely(x) (x)
00071 #define unlikely(x) (x)
00072 #endif
00073
00074
00075 #if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
00076 #define __cold __attribute__ ((__cold__))
00077 #define __hot __attribute__ ((__hot__))
00078 #else
00079 #define __cold
00080 #define __hot
00081 #endif
00082
00083 #ifdef __GNUG__
00084
00085 #define __like_printf(n) __attribute__((format(printf, n, n + 1)))
00086 #else
00087 #define __like_printf(n)
00088 #endif
00089
00090 #endif