[igt-dev] [PATCH i-g-t 07/25] lib: Add DIV_ROUND_UP()

Ville Syrjala ville.syrjala at linux.intel.com
Thu Jul 19 15:03:57 UTC 2018


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

Add DIV_ROUND_UP() and replace some hand rolled versions with it.

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

diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index ef89faa9bd30..01c0be382f1a 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -287,4 +287,6 @@ void igt_lsof(const char *dpath);
 
 #define is_power_of_two(x)  (((x) & ((x)-1)) == 0)
 
+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
 #endif /* IGT_AUX_H */
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 6748357ad16b..324cb624144b 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -193,7 +193,7 @@ void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp,
 static unsigned planar_width(struct format_desc_struct *format, unsigned width, int plane)
 {
 	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
-		return (width + 1) / 2;
+		return DIV_ROUND_UP(width, 2);
 
 	return width;
 }
@@ -208,7 +208,7 @@ static unsigned planar_stride(struct format_desc_struct *format, unsigned width,
 static unsigned planar_height(struct format_desc_struct *format, unsigned height, int plane)
 {
 	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
-		return (height + 1) / 2;
+		return DIV_ROUND_UP(height, 2);
 
 	return height;
 }
diff --git a/tests/i915_query.c b/tests/i915_query.c
index c7de8cbd8371..08aabf946788 100644
--- a/tests/i915_query.c
+++ b/tests/i915_query.c
@@ -242,8 +242,6 @@ static void test_query_topology_unsupported(int fd)
 	igt_assert_eq(item.length, -ENODEV);
 }
 
-#define DIV_ROUND_UP(val, div) (ALIGN(val, div) / div)
-
 static bool
 slice_available(const struct drm_i915_query_topology_info *topo_info,
 		int s)
-- 
2.16.4



More information about the igt-dev mailing list