diff options
author | Paul B Mahol <onemda@gmail.com> | 2020-08-09 17:47:34 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2020-08-26 21:13:38 +0200 |
commit | 389cc142fb00c23ac1a8d2ba95a9db5d8be473cd (patch) | |
tree | 52bcdee8e98d51e4e240d883a806fcc8df32f761 /libavcodec/cfhddsp.c | |
parent | b9ea493afe8576efe3de60f8c6723f9f155de0d8 (diff) | |
download | ffmpeg-389cc142fb00c23ac1a8d2ba95a9db5d8be473cd.tar.gz |
avcodec/cfhd: add x86 SIMD
Overall speed changes for 1920x1080, yuv422p10le, 60fps from: 0.19x to 0.343x
Diffstat (limited to 'libavcodec/cfhddsp.c')
-rw-r--r-- | libavcodec/cfhddsp.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/libavcodec/cfhddsp.c b/libavcodec/cfhddsp.c new file mode 100644 index 0000000000..4028263f7a --- /dev/null +++ b/libavcodec/cfhddsp.c @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2015-2016 Kieran Kunhya <kieran@kunhya.com> + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/attributes.h" +#include "libavutil/common.h" +#include "libavutil/avassert.h" + +#include "cfhddsp.h" + +static av_always_inline void filter(int16_t *output, ptrdiff_t out_stride, + const int16_t *low, ptrdiff_t low_stride, + const int16_t *high, ptrdiff_t high_stride, + int len, int clip) +{ + int16_t tmp; + int i; + + tmp = (11*low[0*low_stride] - 4*low[1*low_stride] + low[2*low_stride] + 4) >> 3; + output[(2*0+0)*out_stride] = (tmp + high[0*high_stride]) >> 1; + if (clip) + output[(2*0+0)*out_stride] = av_clip_uintp2_c(output[(2*0+0)*out_stride], clip); + + tmp = ( 5*low[0*low_stride] + 4*low[1*low_stride] - low[2*low_stride] + 4) >> 3; + output[(2*0+1)*out_stride] = (tmp - high[0*high_stride]) >> 1; + if (clip) + output[(2*0+1)*out_stride] = av_clip_uintp2_c(output[(2*0+1)*out_stride], clip); + + for (i = 1; i < len - 1; i++) { + tmp = (low[(i-1)*low_stride] - low[(i+1)*low_stride] + 4) >> 3; + output[(2*i+0)*out_stride] = (tmp + low[i*low_stride] + high[i*high_stride]) >> 1; + if (clip) + output[(2*i+0)*out_stride] = av_clip_uintp2_c(output[(2*i+0)*out_stride], clip); + + tmp = (low[(i+1)*low_stride] - low[(i-1)*low_stride] + 4) >> 3; + output[(2*i+1)*out_stride] = (tmp + low[i*low_stride] - high[i*high_stride]) >> 1; + if (clip) + output[(2*i+1)*out_stride] = av_clip_uintp2_c(output[(2*i+1)*out_stride], clip); + } + + tmp = ( 5*low[i*low_stride] + 4*low[(i-1)*low_stride] - low[(i-2)*low_stride] + 4) >> 3; + output[(2*i+0)*out_stride] = (tmp + high[i*high_stride]) >> 1; + if (clip) + output[(2*i+0)*out_stride] = av_clip_uintp2_c(output[(2*i+0)*out_stride], clip); + + tmp = (11*low[i*low_stride] - 4*low[(i-1)*low_stride] + low[(i-2)*low_stride] + 4) >> 3; + output[(2*i+1)*out_stride] = (tmp - high[i*high_stride]) >> 1; + if (clip) + output[(2*i+1)*out_stride] = av_clip_uintp2_c(output[(2*i+1)*out_stride], clip); +} + +static void vert_filter(int16_t *output, ptrdiff_t out_stride, + const int16_t *low, ptrdiff_t low_stride, + const int16_t *high, ptrdiff_t high_stride, + int width, int height) +{ + for (int i = 0; i < width; i++) { + filter(output, out_stride, low, low_stride, high, high_stride, height, 0); + low++; + high++; + output++; + } +} + +static void horiz_filter(int16_t *output, ptrdiff_t ostride, + const int16_t *low, ptrdiff_t lstride, + const int16_t *high, ptrdiff_t hstride, + int width, int height) +{ + for (int i = 0; i < height; i++) { + filter(output, 1, low, 1, high, 1, width, 0); + low += lstride; + high += hstride; + output += ostride * 2; + } +} + +static void horiz_filter_clip(int16_t *output, const int16_t *low, const int16_t *high, + int width, int clip) +{ + filter(output, 1, low, 1, high, 1, width, clip); +} + +static void horiz_filter_clip_bayer(int16_t *output, const int16_t *low, const int16_t *high, + int width, int clip) +{ + filter(output, 2, low, 1, high, 1, width, clip); +} + +av_cold void ff_cfhddsp_init(CFHDDSPContext *c, int depth, int bayer) +{ + c->horiz_filter = horiz_filter; + c->vert_filter = vert_filter; + + if (bayer) + c->horiz_filter_clip = horiz_filter_clip_bayer; + else + c->horiz_filter_clip = horiz_filter_clip; + + if (ARCH_X86) + ff_cfhddsp_init_x86(c, depth, bayer); +} |