From 1a0378819557c75db5a2a659ff0b209739affd21 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Mon, 16 Aug 2021 22:41:24 +0200 Subject: [PATCH] gallium: avoid using float based conditions in loops Reviewed-by: Adam Jackson Part-of: --- src/gallium/auxiliary/vl/vl_matrix_filter.c | 19 ++++-- src/gallium/auxiliary/vl/vl_median_filter.c | 66 ++++++++++++++------- 2 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/gallium/auxiliary/vl/vl_matrix_filter.c b/src/gallium/auxiliary/vl/vl_matrix_filter.c index f3e3bd5c63d..1cc701b2167 100644 --- a/src/gallium/auxiliary/vl/vl_matrix_filter.c +++ b/src/gallium/auxiliary/vl/vl_matrix_filter.c @@ -138,8 +138,12 @@ vl_matrix_filter_init(struct vl_matrix_filter *filter, struct pipe_context *pipe struct pipe_blend_state blend; struct pipe_sampler_state sampler; struct pipe_vertex_element ve; - struct vertex2f *offsets, v, sizes; + struct vertex2f *offsets; unsigned i, num_offsets = matrix_width * matrix_height; + int x; + int y; + int size_x; + int size_y; assert(filter && pipe); assert(video_width && video_height); @@ -202,12 +206,15 @@ vl_matrix_filter_init(struct vl_matrix_filter *filter, struct pipe_context *pipe if (!offsets) goto error_offsets; - sizes.x = (float)(matrix_width - 1) / 2.0f; - sizes.y = (float)(matrix_height - 1) / 2.0f; + size_x = (matrix_width - 1) / 2; + size_y = (matrix_height - 1) / 2; - for (v.x = -sizes.x, i = 0; v.x <= sizes.x; v.x += 1.0f) - for (v.y = -sizes.y; v.y <= sizes.y; v.y += 1.0f) - offsets[i++] = v; + for (x = -size_x, i = 0; x <= size_x; x++) + for (y = -size_y; y <= size_y; y++) { + offsets[i].x = x; + offsets[i].y = y; + i++; + } for (i = 0; i < num_offsets; ++i) { offsets[i].x /= video_width; diff --git a/src/gallium/auxiliary/vl/vl_median_filter.c b/src/gallium/auxiliary/vl/vl_median_filter.c index ca935237b86..866babe84f1 100644 --- a/src/gallium/auxiliary/vl/vl_median_filter.c +++ b/src/gallium/auxiliary/vl/vl_median_filter.c @@ -165,7 +165,8 @@ generate_offsets(enum vl_median_filter_shape shape, unsigned size, { unsigned i = 0; int half_size; - struct vertex2f v; + int x; + int y; assert(offsets && num_offsets); @@ -199,41 +200,62 @@ generate_offsets(enum vl_median_filter_shape shape, unsigned size, switch(shape) { case VL_MEDIAN_FILTER_BOX: - for (v.x = -half_size; v.x <= half_size; ++v.x) - for (v.y = -half_size; v.y <= half_size; ++v.y) - (*offsets)[i++] = v; + for (x = -half_size; x <= half_size; ++x) + for (y = -half_size; y <= half_size; ++y) { + (*offsets)[i].x = x; + (*offsets)[i].y = y; + i++; + } break; case VL_MEDIAN_FILTER_CROSS: - v.y = 0.0f; - for (v.x = -half_size; v.x <= half_size; ++v.x) - (*offsets)[i++] = v; + y = 0; + for (x = -half_size; x <= half_size; ++x) { + (*offsets)[i].x = x; + (*offsets)[i].y = y; + i++; + } - v.x = 0.0f; - for (v.y = -half_size; v.y <= half_size; ++v.y) - if (v.y != 0.0f) - (*offsets)[i++] = v; + x = 0; + for (y = -half_size; y <= half_size; ++y) + if (y != 0) { + (*offsets)[i].x = x; + (*offsets)[i].y = y; + i++; + } break; case VL_MEDIAN_FILTER_X: - for (v.x = v.y = -half_size; v.x <= half_size; ++v.x, ++v.y) - (*offsets)[i++] = v; + for (x = y = -half_size; x <= half_size; ++x, ++y) { + (*offsets)[i].x = x; + (*offsets)[i].y = y; + i++; + } - for (v.x = -half_size, v.y = half_size; v.x <= half_size; ++v.x, --v.y) - if (v.y != 0.0f) - (*offsets)[i++] = v; + for (x = -half_size, y = half_size; x <= half_size; ++x, --y) + if (y != 0) { + (*offsets)[i].x = x; + (*offsets)[i].y = y; + i++; + } break; case VL_MEDIAN_FILTER_HORIZONTAL: - v.y = 0.0f; - for (v.x = -half_size; v.x <= half_size; ++v.x) - (*offsets)[i++] = v; + y = 0; + for (x = -half_size; x <= half_size; ++x) { + (*offsets)[i].x = x; + (*offsets)[i].y = y; + i++; + } break; case VL_MEDIAN_FILTER_VERTICAL: - v.x = 0.0f; - for (v.y = -half_size; v.y <= half_size; ++v.y) - (*offsets)[i++] = v; + x = 0; + for (y = -half_size; y <= half_size; ++y) { + (*offsets)[i].x = x; + (*offsets)[i].y = y; + i++; + } break; }