diff options
author | Ville Syrjälä <ville.syrjala@linux.intel.com> | 2018-01-18 19:33:40 +0200 |
---|---|---|
committer | Ville Syrjälä <ville.syrjala@linux.intel.com> | 2018-03-16 18:37:50 +0200 |
commit | 2db6d5007fee63f6dceb0c9ee9d8cb4f77308841 (patch) | |
tree | ac5ea8632f18c3a7d5c7498175808bfbacf67e78 /lib/igt_aux.h | |
parent | 6bfb2ee9d47b45a979c53d0431fe4ef6828f6171 (diff) |
lib: Add igt_hweight()
Add the binary hamming weight helper to igt_aux.h.
v2: Add just the one macro that works for 64 and 32 bits (Chris)
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/igt_aux.h')
-rw-r--r-- | lib/igt_aux.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/igt_aux.h b/lib/igt_aux.h index 43dd15fe..faddd478 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -385,4 +385,9 @@ static inline bool igt_list_empty(const struct igt_list *list) &pos->member != (head); \ pos = tmp, tmp = igt_list_next_entry(pos, member)) +#define igt_hweight(x) \ + __builtin_choose_expr(sizeof(x) == 8, \ + __builtin_popcountll(x), \ + __builtin_popcount(x)) + #endif /* IGT_AUX_H */ |