From 252999f6403d53252c642042a97ea13fa0e53891 Mon Sep 17 00:00:00 2001 From: Sebastian Frysztak Date: Fri, 4 Nov 2016 22:41:17 +0100 Subject: [PATCH] Slightly refactor border handling code. --- blur_simd.c | 74 +++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/blur_simd.c b/blur_simd.c index 6dc2ec3..194f55a 100644 --- a/blur_simd.c +++ b/blur_simd.c @@ -63,24 +63,25 @@ void blur_impl_horizontal_pass_sse2(uint32_t *src, uint32_t *dst, float *kernel, // handle borders int leftBorder = column < HALF_KERNEL; int rightBorder = column > width - HALF_KERNEL; - if (leftBorder || rightBorder) { - uint32_t _rgbaIn[KERNEL_SIZE] ALIGN16; - int i = 0; - if (leftBorder) { - // for kernel size 7x7 and column == 0, we have: - // x x x P0 P1 P2 P3 - // first loop mirrors P{0..3} to fill x's, - // second one loads P{0..3} - for (; i < HALF_KERNEL - column; i++) - _rgbaIn[i] = *(src + (HALF_KERNEL - i)); - for (; i < KERNEL_SIZE; i++) - _rgbaIn[i] = *(src - (HALF_KERNEL - i)); - } else { - for (; i < width - column; i++) - _rgbaIn[i] = *(src + i); - for (int k = 0; i < KERNEL_SIZE; i++, k++) - _rgbaIn[i] = *(src - k); - } + uint32_t _rgbaIn[KERNEL_SIZE] ALIGN16; + int i = 0; + if (leftBorder) { + // for kernel size 7x7 and column == 0, we have: + // x x x P0 P1 P2 P3 + // first loop mirrors P{0..3} to fill x's, + // second one loads P{0..3} + for (; i < HALF_KERNEL - column; i++) + _rgbaIn[i] = *(src + (HALF_KERNEL - i)); + for (; i < KERNEL_SIZE; i++) + _rgbaIn[i] = *(src - (HALF_KERNEL - i)); + + for (int k = 0; k < REGISTERS_CNT; k++) + rgbaIn[k] = _mm_load_si128((__m128i*)(_rgbaIn + 4*k)); + } else if (rightBorder) { + for (; i < width - column; i++) + _rgbaIn[i] = *(src + i); + for (int k = 0; i < KERNEL_SIZE; i++, k++) + _rgbaIn[i] = *(src - k); for (int k = 0; k < REGISTERS_CNT; k++) rgbaIn[k] = _mm_load_si128((__m128i*)(_rgbaIn + 4*k)); @@ -166,24 +167,25 @@ void blur_impl_horizontal_pass_avx(uint32_t *src, uint32_t *dst, float *kernel, // handle borders int leftBorder = column < HALF_KERNEL; int rightBorder = column > width - HALF_KERNEL; - if (leftBorder || rightBorder) { - uint32_t _rgbaIn[KERNEL_SIZE] ALIGN16; - int i = 0; - if (leftBorder) { - // for kernel size 7x7 and column == 0, we have: - // x x x P0 P1 P2 P3 - // first loop mirrors P{0..3} to fill x's, - // second one loads P{0..3} - for (; i < HALF_KERNEL - column; i++) - _rgbaIn[i] = *(src + (HALF_KERNEL - i)); - for (; i < KERNEL_SIZE; i++) - _rgbaIn[i] = *(src - (HALF_KERNEL - i)); - } else { - for (; i < width - column; i++) - _rgbaIn[i] = *(src + i); - for (int k = 0; i < KERNEL_SIZE; i++, k++) - _rgbaIn[i] = *(src - k); - } + uint32_t _rgbaIn[KERNEL_SIZE] ALIGN16; + int i = 0; + if (leftBorder) { + // for kernel size 7x7 and column == 0, we have: + // x x x P0 P1 P2 P3 + // first loop mirrors P{0..3} to fill x's, + // second one loads P{0..3} + for (; i < HALF_KERNEL - column; i++) + _rgbaIn[i] = *(src + (HALF_KERNEL - i)); + for (; i < KERNEL_SIZE; i++) + _rgbaIn[i] = *(src - (HALF_KERNEL - i)); + + for (int k = 0; k < REGISTERS_CNT; k++) + rgbaIn[k] = _mm_load_si128((__m128i*)(_rgbaIn + 4*k)); + } else if (rightBorder) { + for (; i < width - column; i++) + _rgbaIn[i] = *(src + i); + for (int k = 0; i < KERNEL_SIZE; i++, k++) + _rgbaIn[i] = *(src - k); for (int k = 0; k < REGISTERS_CNT; k++) rgbaIn[k] = _mm_load_si128((__m128i*)(_rgbaIn + 4*k));