Merge branch 'master' into dev

Conflicts:
	include/ucore/utils.h
This commit is contained in:
Nils O. Selåsdal
2013-04-01 23:50:07 +02:00
+47 -1
View File
@@ -50,15 +50,27 @@
typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (void *)__mptr - offsetof(type, member) ); })
/** Align a value.
* @param val value to align
* @param align alignment, must be power of 2
* @return the aligned val
*/
#define UC_ALIGN(val,align) (((val)+(align)-1UL)&~((align)-1UL))
/**
* Test if x is a power of 2
*
* @param x value
* @return 1 if x is a power of 20, 0 if it is not
*/
#define UC_IS_POW2(x) ((x) && !((x) & (x) - 1))
/**
* * Expands @x and turns it into a string.
* */
#define UC_STRINGIFY(x) UC_STRINGIFY_HLP(x)
#define UC_STRINGIFY_HLP(x) #x
/**
* assert() that is not affected by NDEBUG define
*/
@@ -70,5 +82,39 @@ if (!(expr) ) {\
abort();\
} while (0)
/**
* Macro for asserting code that should not be reached,
* terminates the program if executed
*/
#define UC_NOT_REACED() abort()
/**
* Round up X / y
*
* @param x numerator, must be positive
* @param y denominator
* @return x/y rounded up
*/
#define UC_DIV_ROUND_UP(x, y) (((x) + ((y) - 1))/(y))
/**
* Round x down to nearest multiple of y
*
* @param x numerator, must be positive
* @param y denominator
* @return x rounded to nearest multiple of y
*/
#define UC_ROUND_UP(x, y) (((x) / (y)) * (y))
/**
* Round x up to nearest multiple of y
*
* @param x numerator, must be positive
* @param y denominator
* @return x rounded to nearest multiple of y
*/
#define UC_ROUND_UP(x, y) (UC_DIV_ROUND_UP((x),(y)) * (y))
#endif