[igt-dev] [PATCH i-g-t v2 1/3] lib: Add igt_hweight()
Ville Syrjala
ville.syrjala at linux.intel.com
Tue Mar 13 18:29:47 UTC 2018
From: Ville Syrjälä <ville.syrjala at linux.intel.com>
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 at linux.intel.com>
---
lib/igt_aux.h | 5 +++++
tests/kms_atomic_transition.c | 14 ++++++--------
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 43dd15fe3b32..faddd478f0d1 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 */
diff --git a/tests/kms_atomic_transition.c b/tests/kms_atomic_transition.c
index aa9a6f8439ea..2fbd94bd2c57 100644
--- a/tests/kms_atomic_transition.c
+++ b/tests/kms_atomic_transition.c
@@ -44,8 +44,6 @@ struct plane_parms {
uint32_t width, height;
};
-#define hweight32 __builtin_popcount
-
/* globals for fence support */
int *timeline;
pthread_t *thread;
@@ -498,7 +496,7 @@ run_transition_test(igt_display_t *display, enum pipe pipe, igt_output_t *output
}
for (i = 0; i < iter_max; i++) {
- int n_enable_planes = hweight32(i);
+ int n_enable_planes = igt_hweight(i);
if (type == TRANSITION_MODESET_FAST &&
n_enable_planes > 1 &&
@@ -524,7 +522,7 @@ run_transition_test(igt_display_t *display, enum pipe pipe, igt_output_t *output
/* i -> i+1 will be done when i increases, can be skipped here */
for (j = iter_max - 1; j > i + 1; j--) {
- n_enable_planes = hweight32(j);
+ n_enable_planes = igt_hweight(j);
if (type == TRANSITION_MODESET_FAST &&
n_enable_planes > 1 &&
@@ -568,7 +566,7 @@ cleanup:
static void commit_display(igt_display_t *display, unsigned event_mask, bool nonblocking)
{
unsigned flags;
- int num_events = hweight32(event_mask);
+ int num_events = igt_hweight(event_mask);
ssize_t ret;
flags = DRM_MODE_ATOMIC_ALLOW_MODESET | DRM_MODE_PAGE_FLIP_EVENT;
@@ -735,7 +733,7 @@ static void run_modeset_tests(igt_display_t *display, int howmany, bool nonblock
igt_crc_t crcs[5][IGT_MAX_PIPES];
unsigned event_mask;
- if (hweight32(i) > howmany)
+ if (igt_hweight(i) > howmany)
continue;
event_mask = set_combinations(display, i, &fbs[0]);
@@ -747,10 +745,10 @@ static void run_modeset_tests(igt_display_t *display, int howmany, bool nonblock
collect_crcs_mask(pipe_crcs, i, crcs[0]);
for (j = iter_max - 1; j > i + 1; j--) {
- if (hweight32(j) > howmany)
+ if (igt_hweight(j) > howmany)
continue;
- if (hweight32(i) < howmany && hweight32(j) < howmany)
+ if (igt_hweight(i) < howmany && igt_hweight(j) < howmany)
continue;
event_mask = set_combinations(display, j, &fbs[1]);
--
2.16.1
More information about the igt-dev
mailing list