From 2db6d5007fee63f6dceb0c9ee9d8cb4f77308841 Mon Sep 17 00:00:00 2001 From: Ville Syrjälä Date: Thu, 18 Jan 2018 19:33:40 +0200 Subject: lib: Add igt_hweight() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ä Reviewed-by: Chris Wilson --- lib/igt_aux.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/igt_aux.h') 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 */ -- cgit v1.2.3