X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=include%2Flinux%2Fcompiler.h;h=e2656ae2cfc198270c956a8cdccdf1fb4139660b;hb=2cc794206920a0337c4f48b7717c22f3fe0d0974;hp=ec4edf7f66dde9c378cad379c021f4d2173ba5a9;hpb=0eb34487ee8e70ecb8e4ee2ed5092b2788eb7f26;p=carl9170fw.git diff --git a/include/linux/compiler.h b/include/linux/compiler.h index ec4edf7..e2656ae 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -17,15 +17,16 @@ #ifndef __SHARED_COMPILER_H #define __SHARED_COMPILER_H -#define __noinline __attribute__((noinline)) #define __noreturn __attribute__((noreturn)) #define __inline __attribute__((always_inline)) #define __hot __attribute__((hot)) #define __cold __attribute__((cold)) -#define __unused __attribute__((unused)) #define __force __attribute__((force)) -#define __section(s) __attribute__((section("." # s))) -#define __packed __attribute__((packed)) +#define __in_section(s) __attribute__((section("." # s))) +#define __visible __attribute__((externally_visible)) + +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) + #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) #define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1) @@ -77,7 +78,7 @@ #define container_of(ptr, type, member) ({ \ const typeof(((type *)0)->member) * __mptr = (ptr); \ - (type *)((char *)__mptr - offsetof(type, member)); }) + (type *)(((unsigned long)__mptr - offsetof(type, member))); }) #define MAX_ERRNO 4095 @@ -103,4 +104,42 @@ static inline long IS_ERR_OR_NULL(const void *ptr) return !ptr || IS_ERR_VALUE((unsigned long)ptr); } +static inline unsigned int hweight8(unsigned int w) +{ + unsigned int res = w - ((w >> 1) & 0x55); + res = (res & 0x33) + ((res >> 2) & 0x33); + return (res + (res >> 4)) & 0x0F; +} + +static inline unsigned int hweight16(unsigned int w) +{ + unsigned int res = w - ((w >> 1) & 0x5555); + res = (res & 0x3333) + ((res >> 2) & 0x3333); + res = (res + (res >> 4)) & 0x0F0F; + return (res + (res >> 8)) & 0x00FF; +} + +/** + * DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union + * + * @TYPE: The type of each flexible array element + * @NAME: The name of the flexible array member + * + * In order to have a flexible array member in a union or alone in a + * struct, it needs to be wrapped in an anonymous struct with at least 1 + * named member, but that member can be empty. + */ +#define DECLARE_FLEX_ARRAY(TYPE, NAME) \ + struct { \ + struct { } __empty_ ## NAME; \ + TYPE NAME[]; \ + } + +#define __bf_shf(x) (__builtin_ffsll(x) - 1) + +#define FIELD_MAX(_mask) \ + ({ \ + (typeof(_mask))((_mask) >> __bf_shf(_mask)); \ + }) + #endif /* __SHARED_COMPILER_H */