X-Git-Url: https://jxself.org/git/?p=linux-libre-firmware.git;a=blobdiff_plain;f=carl9170fw%2Finclude%2Flinux%2Fcompiler.h;h=e2656ae2cfc198270c956a8cdccdf1fb4139660b;hp=9ef76ec7311f25c79d9ed54d436501fe6f12b5b4;hb=e59761df994853121b5287a5bf7cef7911f0f146;hpb=b51695c17b7a86ca904192fb7e7d337fa36f4d56 diff --git a/carl9170fw/include/linux/compiler.h b/carl9170fw/include/linux/compiler.h index 9ef76ec..e2656ae 100644 --- a/carl9170fw/include/linux/compiler.h +++ b/carl9170fw/include/linux/compiler.h @@ -25,6 +25,9 @@ #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) @@ -101,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 */