ieee80211: add TWT element definitions
[carl9170fw.git] / include / linux / compiler.h
index e40d8aec3c45f5ab284e03156bdcab93f31e97b5..e2656ae2cfc198270c956a8cdccdf1fb4139660b 100644 (file)
@@ -111,4 +111,35 @@ static inline unsigned int hweight8(unsigned int w)
         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 */