linux内核宏之——-PERF_ALIGN

 

1 #define PERF_ALIGN(x, a)    __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)
2 #define __PERF_ALIGN_MASK(x, mask)    (((x)+(mask))&~(mask))

返回以a字节对齐需要的字节数,结果类似于roundup,例如:

PERF_ALIGN(9, 4) = 12;
PERF_ALIGN(11, 4) = 12;
PERF_ALIGN(6, 2) = 6;

1 #define roundup(x, y)                             \
2 (                                                \
3     {                                           \
4         const typeof(y) __y = y;                   \
5         (((x) + (__y - 1)) / __y) * __y;        \
6     }                                           \
7 )

 



posted @ 2013-12-27 10:40  ★行云流水★  阅读(296)  评论(0编辑  收藏  举报