From 1382e56627031315e4edb9e856848853b7d8079d Mon Sep 17 00:00:00 2001 From: Ville Syrjälä Date: Tue, 17 Jul 2018 19:16:39 +0300 Subject: lib: Add DIV_ROUND_UP() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add DIV_ROUND_UP() and replace some hand rolled versions with it. v2: Drop the duplicate from gem_render_copy() (Paulo) Signed-off-by: Ville Syrjälä Reviewed-by: Paulo Zanoni --- lib/igt_aux.h | 2 ++ lib/igt_fb.c | 4 ++-- tests/gem_render_copy.c | 2 -- tests/i915_query.c | 2 -- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/igt_aux.h b/lib/igt_aux.h index 192c3ad8..fb02c026 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -293,4 +293,6 @@ void igt_lsof(const char *dpath); #define roundup_power_of_two(x) ((x) != 0 ? 1 << igt_fls((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 21866e7d..f88d4067 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/gem_render_copy.c b/tests/gem_render_copy.c index 135375a9..17a66564 100644 --- a/tests/gem_render_copy.c +++ b/tests/gem_render_copy.c @@ -112,8 +112,6 @@ static void scratch_buf_write_to_png(data_t *data, struct igt_buf *buf, free(linear); } -#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) - static int scratch_buf_aux_width(const struct igt_buf *buf) { return DIV_ROUND_UP(igt_buf_width(buf), 1024) * 128; diff --git a/tests/i915_query.c b/tests/i915_query.c index c7de8cbd..08aabf94 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) -- cgit v1.2.3