#include<linux/module.h>
#include<linux/init.h>
#include<linux/moduleparam.h>
#include<linux/stat.h>
#include<linux/log2.h>
#include<linux/kernel.h>
static int __init test_init(void)
{
int i = ALIGN(8,16);
printk("i = %d\n", i);
int j = ilog2(16); 2^x = 16, x=4
printk("j = %d\n", j);
int x = roundup_pow_of_two(10);
printk("x = %d\n", x);
int y = order_base_2(3);
printk("y = %d\n", y);
return 0;
}
static void __exit test_exit(void)
{
return;
}
MODULE_LICENSE("GPL");
module_init(test_init);
module_exit(test_exit);
#define order_base_2(n) \
( \
__builtin_constant_p(n) ? ( \
((n) == 0 || (n) == 1) ? 0 : \
ilog2((n) - 1) + 1) : \
__order_base_2(n) \
)
展开:
int __order_base_2(unsigned long n)
{
return n > 1 ? ilog2(n - 1) + 1 : 0;
}
__builtin_constant_p(n) ? ( ((n) == 0 || (n) == 1) ? 0 : ilog2((n) - 1) + 1) : __order_base_2(n)