summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Syrjälä <ville.syrjala@linux.intel.com>2018-01-18 19:33:40 +0200
committerVille Syrjälä <ville.syrjala@linux.intel.com>2018-03-16 18:37:50 +0200
commit2db6d5007fee63f6dceb0c9ee9d8cb4f77308841 (patch)
treeac5ea8632f18c3a7d5c7498175808bfbacf67e78
parent6bfb2ee9d47b45a979c53d0431fe4ef6828f6171 (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>
-rw-r--r--lib/igt_aux.h5
-rw-r--r--tests/kms_atomic_transition.c14
2 files changed, 11 insertions, 8 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 */
diff --git a/tests/kms_atomic_transition.c b/tests/kms_atomic_transition.c
index aa9a6f84..2fbd94bd 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]);