[igt-dev] [PATCH i-g-t 1/3] lib: Add igt_hweight{32,64}

Ville Syrjala ville.syrjala at linux.intel.com
Mon Mar 12 20:42:22 UTC 2018


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

Add the binary hamming weight helpers to igt_aux.h.

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 lib/igt_aux.h                 |  3 +++
 tests/kms_atomic_transition.c | 14 ++++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 43dd15fe3b32..244b9317b509 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -385,4 +385,7 @@ 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_hweight32 __builtin_popcount
+#define igt_hweight64 __builtin_popcountll
+
 #endif /* IGT_AUX_H */
diff --git a/tests/kms_atomic_transition.c b/tests/kms_atomic_transition.c
index aa9a6f8439ea..fe749bb7a919 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_hweight32(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_hweight32(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_hweight32(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_hweight32(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_hweight32(j) > howmany)
 				continue;
 
-			if (hweight32(i) < howmany && hweight32(j) < howmany)
+			if (igt_hweight32(i) < howmany && igt_hweight32(j) < howmany)
 				continue;
 
 			event_mask = set_combinations(display, j, &fbs[1]);
-- 
2.16.1



More information about the igt-dev mailing list