src/macros.h
changeset 6010 3dfeb08abf4a
parent 6006 95b48e822a10
child 6083 53aedcdb9e90
equal deleted inserted replaced
6009:bbe756070082 6010:3dfeb08abf4a
    60 
    60 
    61 /* OPT: optimized into an unsigned comparison */
    61 /* OPT: optimized into an unsigned comparison */
    62 //#define IS_INSIDE_1D(x, base, size) ((x) >= (base) && (x) < (base) + (size))
    62 //#define IS_INSIDE_1D(x, base, size) ((x) >= (base) && (x) < (base) + (size))
    63 #define IS_INSIDE_1D(x, base, size) ( (uint)((x) - (base)) < ((uint)(size)) )
    63 #define IS_INSIDE_1D(x, base, size) ( (uint)((x) - (base)) < ((uint)(size)) )
    64 
    64 
       
    65 template <typename T>
       
    66 static inline bool HASBIT(T x, int y)
       
    67 {
       
    68 	return (x & (((T)1) << y)) != 0;
       
    69 }
    65 
    70 
    66 #define HASBIT(x,y)    (((x) & (1 << (y))) != 0)
    71 template <typename T>
    67 #define SETBIT(x,y)    ((x) |=  (1 << (y)))
    72 static inline T SETBIT(T& x, int y)
    68 #define CLRBIT(x,y)    ((x) &= ~(1 << (y)))
    73 {
    69 #define TOGGLEBIT(x,y) ((x) ^=  (1 << (y)))
    74 	return x |= (((T)1) << y);
       
    75 }
       
    76 
       
    77 template <typename T>
       
    78 static inline T CLRBIT(T& x, int y)
       
    79 {
       
    80 	return x &= ~(((T)1) << y);
       
    81 }
       
    82 
       
    83 template <typename T>
       
    84 static inline T TOGGLEBIT(T& x, int y)
       
    85 {
       
    86 	return x ^= (((T)1) << y);
       
    87 }
       
    88 
    70 
    89 
    71 // checking more bits. Maybe unneccessary, but easy to use
    90 // checking more bits. Maybe unneccessary, but easy to use
    72 #define HASBITS(x,y) ((x) & (y))
    91 #define HASBITS(x,y) ((x) & (y))
    73 #define SETBITS(x,y) ((x) |= (y))
    92 #define SETBITS(x,y) ((x) |= (y))
    74 #define CLRBITS(x,y) ((x) &= ~(y))
    93 #define CLRBITS(x,y) ((x) &= ~(y))