上传完整项目文件

This commit is contained in:
xhgit committed 2026-06-21 14:26:15 +08:00
1 parent e63d58df8d
commit aa0dd45839
8663 files changed
+2393125

No files matched your search

+88
View File
@@ -0,0 +1,88 @@
OBJS-$(CONFIG_SCENE_SAD) += x86/scene_sad_init.o
OBJS-$(CONFIG_AFIR_FILTER) += x86/af_afir_init.o
OBJS-$(CONFIG_ANLMDN_FILTER) += x86/af_anlmdn_init.o
OBJS-$(CONFIG_ATADENOISE_FILTER) += x86/vf_atadenoise_init.o
OBJS-$(CONFIG_BLEND_FILTER) += x86/vf_blend_init.o
OBJS-$(CONFIG_BWDIF_FILTER) += x86/vf_bwdif_init.o
OBJS-$(CONFIG_COLORSPACE_FILTER) += x86/colorspacedsp_init.o
OBJS-$(CONFIG_CONVOLUTION_FILTER) += x86/vf_convolution_init.o
OBJS-$(CONFIG_EQ_FILTER) += x86/vf_eq_init.o
OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp_init.o
OBJS-$(CONFIG_GBLUR_FILTER) += x86/vf_gblur_init.o
OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun_init.o
OBJS-$(CONFIG_FRAMERATE_FILTER) += x86/vf_framerate_init.o
OBJS-$(CONFIG_HALDCLUT_FILTER) += x86/vf_lut3d_init.o
OBJS-$(CONFIG_HFLIP_FILTER) += x86/vf_hflip_init.o
OBJS-$(CONFIG_HQDN3D_FILTER) += x86/vf_hqdn3d_init.o
OBJS-$(CONFIG_IDET_FILTER) += x86/vf_idet_init.o
OBJS-$(CONFIG_INTERLACE_FILTER) += x86/vf_tinterlace_init.o
OBJS-$(CONFIG_LIMITER_FILTER) += x86/vf_limiter_init.o
OBJS-$(CONFIG_LUT3D_FILTER) += x86/vf_lut3d_init.o
OBJS-$(CONFIG_MASKEDCLAMP_FILTER) += x86/vf_maskedclamp_init.o
OBJS-$(CONFIG_MASKEDMERGE_FILTER) += x86/vf_maskedmerge_init.o
OBJS-$(CONFIG_NLMEANS_FILTER) += x86/vf_nlmeans_init.o
OBJS-$(CONFIG_NOISE_FILTER) += x86/vf_noise.o
OBJS-$(CONFIG_OVERLAY_FILTER) += x86/vf_overlay_init.o
OBJS-$(CONFIG_PP7_FILTER) += x86/vf_pp7_init.o
OBJS-$(CONFIG_PSNR_FILTER) += x86/vf_psnr_init.o
OBJS-$(CONFIG_PULLUP_FILTER) += x86/vf_pullup_init.o
OBJS-$(CONFIG_REMOVEGRAIN_FILTER) += x86/vf_removegrain_init.o
OBJS-$(CONFIG_SHOWCQT_FILTER) += x86/avf_showcqt_init.o
OBJS-$(CONFIG_SOBEL_FILTER) += x86/vf_convolution_init.o
OBJS-$(CONFIG_SPP_FILTER) += x86/vf_spp.o
OBJS-$(CONFIG_SSIM_FILTER) += x86/vf_ssim_init.o
OBJS-$(CONFIG_STEREO3D_FILTER) += x86/vf_stereo3d_init.o
OBJS-$(CONFIG_TBLEND_FILTER) += x86/vf_blend_init.o
OBJS-$(CONFIG_THRESHOLD_FILTER) += x86/vf_threshold_init.o
OBJS-$(CONFIG_TINTERLACE_FILTER) += x86/vf_tinterlace_init.o
OBJS-$(CONFIG_TRANSPOSE_FILTER) += x86/vf_transpose_init.o
OBJS-$(CONFIG_VOLUME_FILTER) += x86/af_volume_init.o
OBJS-$(CONFIG_V360_FILTER) += x86/vf_v360_init.o
OBJS-$(CONFIG_W3FDIF_FILTER) += x86/vf_w3fdif_init.o
OBJS-$(CONFIG_XPSNR_FILTER) += x86/vf_xpsnr_init.o
OBJS-$(CONFIG_YADIF_FILTER) += x86/vf_yadif_init.o
X86ASM-OBJS-$(CONFIG_SCENE_SAD) += x86/scene_sad.o
X86ASM-OBJS-$(CONFIG_AFIR_FILTER) += x86/af_afir.o
X86ASM-OBJS-$(CONFIG_ANLMDN_FILTER) += x86/af_anlmdn.o
X86ASM-OBJS-$(CONFIG_ATADENOISE_FILTER) += x86/vf_atadenoise.o
X86ASM-OBJS-$(CONFIG_BLEND_FILTER) += x86/vf_blend.o
X86ASM-OBJS-$(CONFIG_BWDIF_FILTER) += x86/vf_bwdif.o
X86ASM-OBJS-$(CONFIG_COLORSPACE_FILTER) += x86/colorspacedsp.o
X86ASM-OBJS-$(CONFIG_CONVOLUTION_FILTER) += x86/vf_convolution.o
X86ASM-OBJS-$(CONFIG_EQ_FILTER) += x86/vf_eq.o
X86ASM-OBJS-$(CONFIG_FRAMERATE_FILTER) += x86/vf_framerate.o
X86ASM-OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp.o
X86ASM-OBJS-$(CONFIG_GBLUR_FILTER) += x86/vf_gblur.o
X86ASM-OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun.o
X86ASM-OBJS-$(CONFIG_HALDCLUT_FILTER) += x86/vf_lut3d.o
X86ASM-OBJS-$(CONFIG_HFLIP_FILTER) += x86/vf_hflip.o
X86ASM-OBJS-$(CONFIG_HQDN3D_FILTER) += x86/vf_hqdn3d.o
X86ASM-OBJS-$(CONFIG_IDET_FILTER) += x86/vf_idet.o
X86ASM-OBJS-$(CONFIG_INTERLACE_FILTER) += x86/vf_interlace.o
X86ASM-OBJS-$(CONFIG_LIMITER_FILTER) += x86/vf_limiter.o
X86ASM-OBJS-$(CONFIG_LUT3D_FILTER) += x86/vf_lut3d.o
X86ASM-OBJS-$(CONFIG_MASKEDCLAMP_FILTER) += x86/vf_maskedclamp.o
X86ASM-OBJS-$(CONFIG_MASKEDMERGE_FILTER) += x86/vf_maskedmerge.o
X86ASM-OBJS-$(CONFIG_NLMEANS_FILTER) += x86/vf_nlmeans.o
X86ASM-OBJS-$(CONFIG_OVERLAY_FILTER) += x86/vf_overlay.o
X86ASM-OBJS-$(CONFIG_PP7_FILTER) += x86/vf_pp7.o
X86ASM-OBJS-$(CONFIG_PSNR_FILTER) += x86/vf_psnr.o
X86ASM-OBJS-$(CONFIG_PULLUP_FILTER) += x86/vf_pullup.o
ifdef CONFIG_GPL
X86ASM-OBJS-$(CONFIG_REMOVEGRAIN_FILTER) += x86/vf_removegrain.o
endif
X86ASM-OBJS-$(CONFIG_SHOWCQT_FILTER) += x86/avf_showcqt.o
X86ASM-OBJS-$(CONFIG_SOBEL_FILTER) += x86/vf_convolution.o
X86ASM-OBJS-$(CONFIG_SSIM_FILTER) += x86/vf_ssim.o
X86ASM-OBJS-$(CONFIG_STEREO3D_FILTER) += x86/vf_stereo3d.o
X86ASM-OBJS-$(CONFIG_TBLEND_FILTER) += x86/vf_blend.o
X86ASM-OBJS-$(CONFIG_THRESHOLD_FILTER) += x86/vf_threshold.o
X86ASM-OBJS-$(CONFIG_TINTERLACE_FILTER) += x86/vf_interlace.o
X86ASM-OBJS-$(CONFIG_TRANSPOSE_FILTER) += x86/vf_transpose.o
X86ASM-OBJS-$(CONFIG_VOLUME_FILTER) += x86/af_volume.o
X86ASM-OBJS-$(CONFIG_V360_FILTER) += x86/vf_v360.o
X86ASM-OBJS-$(CONFIG_W3FDIF_FILTER) += x86/vf_w3fdif.o
X86ASM-OBJS-$(CONFIG_YADIF_FILTER) += x86/vf_yadif.o x86/yadif-16.o x86/yadif-10.o
+96
View File
@@ -0,0 +1,96 @@
;*****************************************************************************
;* x86-optimized functions for afir filter
;* Copyright (c) 2017 Paul B Mahol
;*
;* 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/x86/x86util.asm"
SECTION .text
;------------------------------------------------------------------------------
; void ff_fcmul_add(float *sum, const float *t, const float *c, int len)
;------------------------------------------------------------------------------
%macro FCMUL_ADD 0
cglobal fcmul_add, 4,4,6, sum, t, c, len
shl lend, 3
add tq, lenq
add cq, lenq
add sumq, lenq
neg lenq
ALIGN 16
.loop:
movsldup m0, [tq + lenq]
movsldup m3, [tq + lenq+mmsize]
movaps m1, [cq + lenq]
movaps m4, [cq + lenq+mmsize]
mulps m0, m0, m1
mulps m3, m3, m4
shufps m1, m1, m1, 0xb1
shufps m4, m4, m4, 0xb1
movshdup m2, [tq + lenq]
movshdup m5, [tq + lenq+mmsize]
mulps m2, m2, m1
mulps m5, m5, m4
addsubps m0, m0, m2
addsubps m3, m3, m5
addps m0, m0, [sumq + lenq]
addps m3, m3, [sumq + lenq+mmsize]
movaps [sumq + lenq], m0
movaps [sumq + lenq+mmsize], m3
add lenq, mmsize*2
jl .loop
movss xm0, [tq + lenq]
mulss xm0, [cq + lenq]
addss xm0, [sumq + lenq]
movss [sumq + lenq], xm0
RET
%endmacro
INIT_XMM sse3
FCMUL_ADD
INIT_YMM avx
FCMUL_ADD
%if HAVE_FMA3_EXTERNAL
INIT_YMM fma3
cglobal fcmul_add, 4,4,4, sum, t, c, len
shl lend, 3
add tq, lenq
add cq, lenq
add sumq, lenq
neg lenq
.loop:
movaps m0, [tq + lenq]
movaps m1, [cq + lenq]
vpermilps m3, m0, 177
vpermilps m2, m1, 160
vpermilps m1, m1, 245
mulps m1, m1, m3
vfmaddsub132ps m0, m1, m2
addps m0, m0, [sumq + lenq]
movaps [sumq + lenq], m0
add lenq, mmsize
jl .loop
movss xm0, [tq + lenq]
mulss xm0, [cq + lenq]
addss xm0, [sumq + lenq]
movss [sumq + lenq], xm0
RET
%endif
+45
View File
@@ -0,0 +1,45 @@
/*
* 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 "config.h"
#include "libavutil/attributes.h"
#include "libavutil/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/af_afirdsp.h"
void ff_fcmul_add_sse3(float *sum, const float *t, const float *c,
ptrdiff_t len);
void ff_fcmul_add_avx(float *sum, const float *t, const float *c,
ptrdiff_t len);
void ff_fcmul_add_fma3(float *sum, const float *t, const float *c,
ptrdiff_t len);
av_cold void ff_afir_init_x86(AudioFIRDSPContext *s)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE3(cpu_flags)) {
s->fcmul_add = ff_fcmul_add_sse3;
}
if (EXTERNAL_AVX_FAST(cpu_flags)) {
s->fcmul_add = ff_fcmul_add_avx;
}
if (EXTERNAL_FMA3_FAST(cpu_flags)) {
s->fcmul_add = ff_fcmul_add_fma3;
}
}
+80
View File
@@ -0,0 +1,80 @@
;*****************************************************************************
;* x86-optimized functions for anlmdn filter
;* Copyright (c) 2017 Paul B Mahol
;*
;* 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/x86/x86util.asm"
SECTION .text
;------------------------------------------------------------------------------
; float ff_compute_distance_ssd(float *f1, const float *f2, ptrdiff_t len)
;------------------------------------------------------------------------------
INIT_XMM sse
cglobal compute_distance_ssd, 3,5,3, f1, f2, len, r, x
mov xq, lenq
shl xq, 2
neg xq
add f1q, xq
add f2q, xq
xor xq, xq
shl lenq, 1
add lenq, 1
shl lenq, 2
mov rq, lenq
and rq, mmsize - 1
xorps m0, m0
cmp lenq, mmsize
jl .loop1
sub lenq, rq
ALIGN 16
.loop0:
movups m1, [f1q + xq]
movups m2, [f2q + xq]
subps m1, m2
mulps m1, m1
addps m0, m1
add xq, mmsize
cmp xq, lenq
jl .loop0
movhlps xmm1, xmm0
addps xmm0, xmm1
movss xmm1, xmm0
shufps xmm0, xmm0, 1
addss xmm0, xmm1
cmp rq, 0
je .end
add lenq, rq
.loop1:
movss xm1, [f1q + xq]
subss xm1, [f2q + xq]
mulss xm1, xm1
addss xm0, xm1
add xq, 4
cmp xq, lenq
jl .loop1
.end:
%if ARCH_X86_64 == 0
movss r0m, xm0
fld dword r0m
%endif
RET
+35
View File
@@ -0,0 +1,35 @@
/*
* 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 "config.h"
#include "libavutil/attributes.h"
#include "libavutil/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/af_anlmdndsp.h"
float ff_compute_distance_ssd_sse(const float *f1, const float *f2,
ptrdiff_t len);
av_cold void ff_anlmdn_init_x86(AudioNLMDNDSPContext *s)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE(cpu_flags)) {
s->compute_distance_ssd = ff_compute_distance_ssd_sse;
}
}
+140
View File
@@ -0,0 +1,140 @@
;*****************************************************************************
;* x86-optimized functions for volume filter
;* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.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/x86/x86util.asm"
SECTION_RODATA 32
pd_1_256: times 4 dq 0x3F70000000000000
pd_int32_max: times 4 dq 0x41DFFFFFFFC00000
pw_1: times 8 dw 1
pw_128: times 8 dw 128
pq_128: times 2 dq 128
SECTION .text
;------------------------------------------------------------------------------
; void ff_scale_samples_s16(uint8_t *dst, const uint8_t *src, int len,
; int volume)
;------------------------------------------------------------------------------
INIT_XMM sse2
cglobal scale_samples_s16, 4,4,4, dst, src, len, volume
movd m0, volumem
pshuflw m0, m0, 0
punpcklwd m0, [pw_1]
mova m1, [pw_128]
lea lenq, [lend*2-mmsize]
.loop:
; dst[i] = av_clip_int16((src[i] * volume + 128) >> 8);
mova m2, [srcq+lenq]
punpcklwd m3, m2, m1
punpckhwd m2, m1
pmaddwd m3, m0
pmaddwd m2, m0
psrad m3, 8
psrad m2, 8
packssdw m3, m2
mova [dstq+lenq], m3
sub lenq, mmsize
jge .loop
RET
;------------------------------------------------------------------------------
; void ff_scale_samples_s32(uint8_t *dst, const uint8_t *src, int len,
; int volume)
;------------------------------------------------------------------------------
%macro SCALE_SAMPLES_S32 0
cglobal scale_samples_s32, 4,4,4, dst, src, len, volume
%if ARCH_X86_32 && cpuflag(avx)
vbroadcastss xmm2, volumem
%else
movd xmm2, volumed
pshufd xmm2, xmm2, 0
%endif
CVTDQ2PD m2, xmm2
mulpd m2, m2, [pd_1_256]
mova m3, [pd_int32_max]
lea lenq, [lend*4-mmsize]
.loop:
CVTDQ2PD m0, [srcq+lenq ]
CVTDQ2PD m1, [srcq+lenq+mmsize/2]
mulpd m0, m0, m2
mulpd m1, m1, m2
minpd m0, m0, m3
minpd m1, m1, m3
cvtpd2dq xmm0, m0
cvtpd2dq xmm1, m1
%if cpuflag(avx)
vmovdqa [dstq+lenq ], xmm0
vmovdqa [dstq+lenq+mmsize/2], xmm1
%else
movq [dstq+lenq ], xmm0
movq [dstq+lenq+mmsize/2], xmm1
%endif
sub lenq, mmsize
jge .loop
RET
%endmacro
INIT_XMM sse2
%define CVTDQ2PD cvtdq2pd
SCALE_SAMPLES_S32
%if HAVE_AVX_EXTERNAL
%define CVTDQ2PD vcvtdq2pd
INIT_YMM avx
SCALE_SAMPLES_S32
%endif
%undef CVTDQ2PD
; NOTE: This is not bit-identical with the C version because it clips to
; [-INT_MAX, INT_MAX] instead of [INT_MIN, INT_MAX]
INIT_XMM ssse3, atom
cglobal scale_samples_s32, 4,4,8, dst, src, len, volume
movd m4, volumem
pshufd m4, m4, 0
mova m5, [pq_128]
pxor m6, m6
lea lenq, [lend*4-mmsize]
.loop:
; src[i] = av_clipl_int32((src[i] * volume + 128) >> 8);
mova m7, [srcq+lenq]
pabsd m3, m7
pshufd m0, m3, q0100
pshufd m1, m3, q0302
pmuludq m0, m4
pmuludq m1, m4
paddq m0, m5
paddq m1, m5
psrlq m0, 7
psrlq m1, 7
shufps m2, m0, m1, q3131
shufps m0, m0, m1, q2020
pcmpgtd m2, m6
por m0, m2
psrld m0, 1
psignd m0, m7
mova [dstq+lenq], m0
sub lenq, mmsize
jge .loop
RET
+60
View File
@@ -0,0 +1,60 @@
/*
* 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 "config.h"
#include "libavutil/attributes.h"
#include "libavutil/cpu.h"
#include "libavutil/samplefmt.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/af_volume.h"
void ff_scale_samples_s16_sse2(uint8_t *dst, const uint8_t *src, int len,
int volume);
void ff_scale_samples_s32_sse2(uint8_t *dst, const uint8_t *src, int len,
int volume);
void ff_scale_samples_s32_ssse3_atom(uint8_t *dst, const uint8_t *src, int len,
int volume);
void ff_scale_samples_s32_avx(uint8_t *dst, const uint8_t *src, int len,
int volume);
av_cold void ff_volume_init_x86(VolumeContext *vol)
{
int cpu_flags = av_get_cpu_flags();
enum AVSampleFormat sample_fmt = av_get_packed_sample_fmt(vol->sample_fmt);
if (sample_fmt == AV_SAMPLE_FMT_S16) {
if (EXTERNAL_SSE2(cpu_flags) && vol->volume_i < 32768) {
vol->scale_samples = ff_scale_samples_s16_sse2;
vol->samples_align = 8;
}
} else if (sample_fmt == AV_SAMPLE_FMT_S32) {
if (EXTERNAL_SSE2(cpu_flags)) {
vol->scale_samples = ff_scale_samples_s32_sse2;
vol->samples_align = 4;
}
if (EXTERNAL_SSSE3(cpu_flags) && cpu_flags & AV_CPU_FLAG_ATOM) {
vol->scale_samples = ff_scale_samples_s32_ssse3_atom;
vol->samples_align = 4;
}
if (EXTERNAL_AVX_FAST(cpu_flags)) {
vol->scale_samples = ff_scale_samples_s32_avx;
vol->samples_align = 8;
}
}
}
+192
View File
@@ -0,0 +1,192 @@
;*****************************************************************************
;* x86-optimized functions for showcqt filter
;*
;* Copyright (C) 2016 Muhammad Faiz <mfcc64@gmail.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/x86/x86util.asm"
%if ARCH_X86_64
%define pointer resq
%else
%define pointer resd
%endif
struc Coeffs
.val: pointer 1
.start: resd 1
.len: resd 1
.sizeof:
endstruc
%macro CQT_CALC 9
; %1 = a_re, %2 = a_im, %3 = b_re, %4 = b_im
; %5 = m_re, %6 = m_im, %7 = tmp, %8 = coeffval, %9 = coeffsq_offset
mov id, xd
add id, [coeffsq + Coeffs.start + %9]
movaps m%5, [srcq + 8 * iq]
movaps m%7, [srcq + 8 * iq + mmsize]
shufps m%6, m%5, m%7, q3131
shufps m%5, m%5, m%7, q2020
sub id, fft_lend
FMULADD_PS m%2, m%6, m%8, m%2, m%6
neg id
FMULADD_PS m%1, m%5, m%8, m%1, m%5
movups m%5, [srcq + 8 * iq - mmsize + 8]
movups m%7, [srcq + 8 * iq - 2*mmsize + 8]
%if mmsize == 32
vperm2f128 m%5, m%5, m%5, 1
vperm2f128 m%7, m%7, m%7, 1
%endif
shufps m%6, m%5, m%7, q1313
shufps m%5, m%5, m%7, q0202
FMULADD_PS m%4, m%6, m%8, m%4, m%6
FMULADD_PS m%3, m%5, m%8, m%3, m%5
%endmacro ; CQT_CALC
%macro CQT_SEPARATE 6 ; a_re, a_im, b_re, b_im, tmp, tmp2
addps m%5, m%4, m%2
subps m%6, m%3, m%1
addps m%1, m%1, m%3
subps m%2, m%2, m%4
HADDPS m%5, m%6, m%3
HADDPS m%1, m%2, m%3
HADDPS m%1, m%5, m%2
%if mmsize == 32
vextractf128 xmm%2, m%1, 1
addps xmm%1, xmm%2
%endif
%endmacro ; CQT_SEPARATE
%macro DECLARE_CQT_CALC 0
; ff_showcqt_cqt_calc_*(dst, src, coeffs, len, fft_len)
%if ARCH_X86_64
cglobal showcqt_cqt_calc, 5, 10, 12, dst, src, coeffs, len, fft_len, x, coeffs_val, coeffs_val2, i, coeffs_len
align 16
.loop_k:
mov xd, [coeffsq + Coeffs.len]
xorps m0, m0, m0
movaps m1, m0
movaps m2, m0
mov coeffs_lend, [coeffsq + Coeffs.len + Coeffs.sizeof]
movaps m3, m0
movaps m8, m0
cmp coeffs_lend, xd
movaps m9, m0
movaps m10, m0
movaps m11, m0
cmova coeffs_lend, xd
xor xd, xd
test coeffs_lend, coeffs_lend
jz .check_loop_b
mov coeffs_valq, [coeffsq + Coeffs.val]
mov coeffs_val2q, [coeffsq + Coeffs.val + Coeffs.sizeof]
align 16
.loop_ab:
movaps m7, [coeffs_valq + 4 * xq]
CQT_CALC 0, 1, 2, 3, 4, 5, 6, 7, 0
movaps m7, [coeffs_val2q + 4 * xq]
CQT_CALC 8, 9, 10, 11, 4, 5, 6, 7, Coeffs.sizeof
add xd, mmsize/4
cmp xd, coeffs_lend
jb .loop_ab
.check_loop_b:
cmp xd, [coeffsq + Coeffs.len + Coeffs.sizeof]
jae .check_loop_a
align 16
.loop_b:
movaps m7, [coeffs_val2q + 4 * xq]
CQT_CALC 8, 9, 10, 11, 4, 5, 6, 7, Coeffs.sizeof
add xd, mmsize/4
cmp xd, [coeffsq + Coeffs.len + Coeffs.sizeof]
jb .loop_b
.loop_end:
CQT_SEPARATE 0, 1, 2, 3, 4, 5
CQT_SEPARATE 8, 9, 10, 11, 4, 5
mulps xmm0, xmm0
mulps xmm8, xmm8
HADDPS xmm0, xmm8, xmm1
movaps [dstq], xmm0
sub lend, 2
lea dstq, [dstq + 16]
lea coeffsq, [coeffsq + 2*Coeffs.sizeof]
jnz .loop_k
RET
align 16
.check_loop_a:
cmp xd, [coeffsq + Coeffs.len]
jae .loop_end
align 16
.loop_a:
movaps m7, [coeffs_valq + 4 * xq]
CQT_CALC 0, 1, 2, 3, 4, 5, 6, 7, 0
add xd, mmsize/4
cmp xd, [coeffsq + Coeffs.len]
jb .loop_a
jmp .loop_end
%else
cglobal showcqt_cqt_calc, 4, 7, 8, dst, src, coeffs, len, x, coeffs_val, i
%define fft_lend r4m
align 16
.loop_k:
mov xd, [coeffsq + Coeffs.len]
xorps m0, m0, m0
movaps m1, m0
movaps m2, m0
movaps m3, m0
test xd, xd
jz .store
mov coeffs_valq, [coeffsq + Coeffs.val]
xor xd, xd
align 16
.loop_x:
movaps m7, [coeffs_valq + 4 * xq]
CQT_CALC 0, 1, 2, 3, 4, 5, 6, 7, 0
add xd, mmsize/4
cmp xd, [coeffsq + Coeffs.len]
jb .loop_x
CQT_SEPARATE 0, 1, 2, 3, 4, 5
mulps xmm0, xmm0
HADDPS xmm0, xmm0, xmm1
.store:
movlps [dstq], xmm0
sub lend, 1
lea dstq, [dstq + 8]
lea coeffsq, [coeffsq + Coeffs.sizeof]
jnz .loop_k
RET
%endif ; ARCH_X86_64
%endmacro ; DECLARE_CQT_CALC
INIT_XMM sse
DECLARE_CQT_CALC
INIT_XMM sse3
DECLARE_CQT_CALC
%if HAVE_AVX_EXTERNAL
INIT_YMM avx
DECLARE_CQT_CALC
%endif
%if HAVE_FMA3_EXTERNAL
INIT_YMM fma3
DECLARE_CQT_CALC
%endif
%if HAVE_FMA4_EXTERNAL
INIT_XMM fma4
DECLARE_CQT_CALC
%endif
+63
View File
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2016 Muhammad Faiz <mfcc64@gmail.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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/avf_showcqt.h"
#define DECLARE_CQT_CALC(type) \
void ff_showcqt_cqt_calc_##type(AVComplexFloat *dst, const AVComplexFloat *src, \
const Coeffs *coeffs, int len, int fft_len)
DECLARE_CQT_CALC(sse);
DECLARE_CQT_CALC(sse3);
DECLARE_CQT_CALC(avx);
DECLARE_CQT_CALC(fma3);
DECLARE_CQT_CALC(fma4);
#define permute_coeffs_0 NULL
static void permute_coeffs_01452367(float *v, int len)
{
int k;
for (k = 0; k < len; k += 8) {
FFSWAP(float, v[k+2], v[k+4]);
FFSWAP(float, v[k+3], v[k+5]);
}
}
av_cold void ff_showcqt_init_x86(ShowCQTContext *s)
{
int cpuflags = av_get_cpu_flags();
#define SELECT_CQT_CALC(type, TYPE, align, perm) \
if (EXTERNAL_##TYPE(cpuflags)) { \
s->cqt_calc = ff_showcqt_cqt_calc_##type; \
s->cqt_align = align; \
s->permute_coeffs = permute_coeffs_##perm; \
}
SELECT_CQT_CALC(sse, SSE, 4, 0);
SELECT_CQT_CALC(sse3, SSE3_FAST, 4, 0);
SELECT_CQT_CALC(fma4, FMA4, 4, 0); // using xmm
SELECT_CQT_CALC(avx, AVX_FAST, 8, 01452367);
SELECT_CQT_CALC(fma3, FMA3_FAST, 8, 01452367);
}
File diff suppressed because it is too large. Load diff
+119
View File
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2016 Ronald S. Bultje <rsbultje@gmail.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/x86/cpu.h"
#include "libavfilter/colorspacedsp.h"
#define decl_yuv2yuv_fn(t) \
void ff_yuv2yuv_##t##_sse2(uint8_t *yuv_out[3], const ptrdiff_t yuv_out_stride[3], \
uint8_t *yuv_in[3], const ptrdiff_t yuv_in_stride[3], \
int w, int h, const int16_t yuv2yuv_coeffs[3][3][8], \
const int16_t yuv_offset[2][8])
#define decl_yuv2yuv_fns(ss) \
decl_yuv2yuv_fn(ss##p8to8); \
decl_yuv2yuv_fn(ss##p10to8); \
decl_yuv2yuv_fn(ss##p12to8); \
decl_yuv2yuv_fn(ss##p8to10); \
decl_yuv2yuv_fn(ss##p10to10); \
decl_yuv2yuv_fn(ss##p12to10); \
decl_yuv2yuv_fn(ss##p8to12); \
decl_yuv2yuv_fn(ss##p10to12); \
decl_yuv2yuv_fn(ss##p12to12)
decl_yuv2yuv_fns(420);
decl_yuv2yuv_fns(422);
decl_yuv2yuv_fns(444);
#define decl_yuv2rgb_fn(t) \
void ff_yuv2rgb_##t##_sse2(int16_t *rgb_out[3], ptrdiff_t rgb_stride, \
uint8_t *yuv_in[3], const ptrdiff_t yuv_stride[3], \
int w, int h, const int16_t coeff[3][3][8], \
const int16_t yuv_offset[8])
#define decl_yuv2rgb_fns(ss) \
decl_yuv2rgb_fn(ss##p8); \
decl_yuv2rgb_fn(ss##p10); \
decl_yuv2rgb_fn(ss##p12)
decl_yuv2rgb_fns(420);
decl_yuv2rgb_fns(422);
decl_yuv2rgb_fns(444);
#define decl_rgb2yuv_fn(t) \
void ff_rgb2yuv_##t##_sse2(uint8_t *yuv_out[3], const ptrdiff_t yuv_stride[3], \
int16_t *rgb_in[3], ptrdiff_t rgb_stride, \
int w, int h, const int16_t coeff[3][3][8], \
const int16_t yuv_offset[8])
#define decl_rgb2yuv_fns(ss) \
decl_rgb2yuv_fn(ss##p8); \
decl_rgb2yuv_fn(ss##p10); \
decl_rgb2yuv_fn(ss##p12)
decl_rgb2yuv_fns(420);
decl_rgb2yuv_fns(422);
decl_rgb2yuv_fns(444);
void ff_multiply3x3_sse2(int16_t *data[3], ptrdiff_t stride, int w, int h,
const int16_t coeff[3][3][8]);
void ff_colorspacedsp_x86_init(ColorSpaceDSPContext *dsp)
{
int cpu_flags = av_get_cpu_flags();
if (ARCH_X86_64 && EXTERNAL_SSE2(cpu_flags)) {
#define assign_yuv2yuv_fns(ss) \
dsp->yuv2yuv[BPP_8 ][BPP_8 ][SS_##ss] = ff_yuv2yuv_##ss##p8to8_sse2; \
dsp->yuv2yuv[BPP_8 ][BPP_10][SS_##ss] = ff_yuv2yuv_##ss##p8to10_sse2; \
dsp->yuv2yuv[BPP_8 ][BPP_12][SS_##ss] = ff_yuv2yuv_##ss##p8to12_sse2; \
dsp->yuv2yuv[BPP_10][BPP_8 ][SS_##ss] = ff_yuv2yuv_##ss##p10to8_sse2; \
dsp->yuv2yuv[BPP_10][BPP_10][SS_##ss] = ff_yuv2yuv_##ss##p10to10_sse2; \
dsp->yuv2yuv[BPP_10][BPP_12][SS_##ss] = ff_yuv2yuv_##ss##p10to12_sse2; \
dsp->yuv2yuv[BPP_12][BPP_8 ][SS_##ss] = ff_yuv2yuv_##ss##p12to8_sse2; \
dsp->yuv2yuv[BPP_12][BPP_10][SS_##ss] = ff_yuv2yuv_##ss##p12to10_sse2; \
dsp->yuv2yuv[BPP_12][BPP_12][SS_##ss] = ff_yuv2yuv_##ss##p12to12_sse2
assign_yuv2yuv_fns(420);
assign_yuv2yuv_fns(422);
assign_yuv2yuv_fns(444);
#define assign_yuv2rgb_fns(ss) \
dsp->yuv2rgb[BPP_8 ][SS_##ss] = ff_yuv2rgb_##ss##p8_sse2; \
dsp->yuv2rgb[BPP_10][SS_##ss] = ff_yuv2rgb_##ss##p10_sse2; \
dsp->yuv2rgb[BPP_12][SS_##ss] = ff_yuv2rgb_##ss##p12_sse2
assign_yuv2rgb_fns(420);
assign_yuv2rgb_fns(422);
assign_yuv2rgb_fns(444);
#define assign_rgb2yuv_fns(ss) \
dsp->rgb2yuv[BPP_8 ][SS_##ss] = ff_rgb2yuv_##ss##p8_sse2; \
dsp->rgb2yuv[BPP_10][SS_##ss] = ff_rgb2yuv_##ss##p10_sse2; \
dsp->rgb2yuv[BPP_12][SS_##ss] = ff_rgb2yuv_##ss##p12_sse2
assign_rgb2yuv_fns(420);
assign_rgb2yuv_fns(422);
assign_rgb2yuv_fns(444);
dsp->multiply3x3 = ff_multiply3x3_sse2;
}
}
+74
View File
@@ -0,0 +1,74 @@
;*****************************************************************************
;* x86-optimized functions for scene SAD
;*
;* Copyright (C) 2018 Marton Balint
;*
;* Based on vf_blend.asm, Copyright (C) 2015 Paul B Mahol
;*
;* 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/x86/x86util.asm"
SECTION .text
%macro SAD_INIT 0
cglobal scene_sad, 6, 7, 2, src1, stride1, src2, stride2, width, end, x
add src1q, widthq
add src2q, widthq
neg widthq
pxor m1, m1
%endmacro
%macro SAD_LOOP 0
.nextrow:
mov xq, widthq
.loop:
movu m0, [src1q + xq]
psadbw m0, [src2q + xq]
paddq m1, m0
add xq, mmsize
jl .loop
add src1q, stride1q
add src2q, stride2q
sub endd, 1
jg .nextrow
mov r0q, r6mp
movu [r0q], m1 ; sum
RET
%endmacro
%macro SAD_FRAMES 0
SAD_INIT
SAD_LOOP
%endmacro
INIT_XMM sse2
SAD_FRAMES
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
SAD_FRAMES
%endif
+60
View File
@@ -0,0 +1,60 @@
/*
* 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/scene_sad.h"
#define SCENE_SAD_FUNC(FUNC_NAME, ASM_FUNC_NAME, MMSIZE) \
void ASM_FUNC_NAME(SCENE_SAD_PARAMS); \
\
static void FUNC_NAME(SCENE_SAD_PARAMS) { \
uint64_t sad[MMSIZE / 8] = {0}; \
ptrdiff_t awidth = width & ~(MMSIZE - 1); \
*sum = 0; \
ASM_FUNC_NAME(src1, stride1, src2, stride2, awidth, height, sad); \
for (int i = 0; i < MMSIZE / 8; i++) \
*sum += sad[i]; \
ff_scene_sad_c(src1 + awidth, stride1, \
src2 + awidth, stride2, \
width - awidth, height, sad); \
*sum += sad[0]; \
}
#if HAVE_X86ASM
SCENE_SAD_FUNC(scene_sad_sse2, ff_scene_sad_sse2, 16)
#if HAVE_AVX2_EXTERNAL
SCENE_SAD_FUNC(scene_sad_avx2, ff_scene_sad_avx2, 32)
#endif
#endif
ff_scene_sad_fn ff_scene_sad_get_fn_x86(int depth)
{
#if HAVE_X86ASM
int cpu_flags = av_get_cpu_flags();
if (depth == 8) {
#if HAVE_AVX2_EXTERNAL
if (EXTERNAL_AVX2_FAST(cpu_flags))
return scene_sad_avx2;
#endif
if (EXTERNAL_SSE2(cpu_flags))
return scene_sad_sse2;
}
#endif
return NULL;
}
+279
View File
@@ -0,0 +1,279 @@
;*****************************************************************************
;* x86-optimized functions for atadenoise filter
;*
;* Copyright (C) 2019 Paul B Mahol
;*
;* 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
;******************************************************************************
%if ARCH_X86_64
%include "libavutil/x86/x86util.asm"
SECTION_RODATA
pw_one: times 8 dw 1
pw_ones: times 8 dw 65535
SECTION .text
;------------------------------------------------------------------------------
; void ff_filter_row(const uint8_t *src, uint8_t *dst,
; const uint8_t **srcf,
; int w, int mid, int size,
; int thra, int thrb)
;------------------------------------------------------------------------------
INIT_XMM sse4
cglobal atadenoise_filter_row8, 8,10,13, src, dst, srcf, w, mid, size, i, j, srcfx, x
movsxdifnidn wq, wd
movsxdifnidn midq, midd
movsxdifnidn sizeq, sized
add srcq, wq
add dstq, wq
mov xq, wq
dec sizeq
neg xq
movd m4, r6m
SPLATW m4, m4
movd m5, r7m
SPLATW m5, m5
pxor m2, m2
mova m10, [pw_ones]
.loop:
mov iq, midq
mov jq, midq
pxor m3, m3
pxor m11, m11
movu m0, [srcq + xq]
punpcklbw m0, m2
mova m7, m0
mova m8, [pw_one]
mova m12, [pw_ones]
.loop0:
inc iq
dec jq
mov srcfxq, [srcfq + jq * 8]
add srcfxq, wq
movu m1, [srcfxq + xq]
punpcklbw m1, m2
mova m9, m1
psubw m1, m0
pabsw m1, m1
paddw m11, m1
pcmpgtw m1, m4
mova m6, m11
pcmpgtw m6, m5
por m6, m1
pxor m6, m10
pand m12, m6
pand m9, m12
paddw m7, m9
mova m6, m12
psrlw m6, 15
paddw m8, m6
mov srcfxq, [srcfq + iq * 8]
add srcfxq, wq
movu m1, [srcfxq + xq]
punpcklbw m1, m2
mova m9, m1
psubw m1, m0
pabsw m1, m1
paddw m3, m1
pcmpgtw m1, m4
mova m6, m3
pcmpgtw m6, m5
por m6, m1
pxor m6, m10
pand m12, m6
pand m9, m12
paddw m7, m9
mova m6, m12
psrlw m6, 15
paddw m8, m6
ptest m12, m12
jz .finish
cmp iq, sizeq
jl .loop0
.finish:
mova m9, m8
psrlw m9, 1
paddw m7, m9
mova m1, m7
mova m6, m8
punpcklwd m7, m2
punpcklwd m8, m2
cvtdq2ps m7, m7
cvtdq2ps m8, m8
divps m7, m8
cvttps2dq m7, m7
packssdw m7, m7
packuswb m7, m7
movd [dstq + xq], m7
punpckhwd m1, m2
punpckhwd m6, m2
cvtdq2ps m1, m1
cvtdq2ps m6, m6
divps m1, m6
cvttps2dq m1, m1
packssdw m1, m1
packuswb m1, m1
movd [dstq + xq + 4], m1
add xq, mmsize/2
jl .loop
RET
INIT_XMM sse4
cglobal atadenoise_filter_row8_serial, 8,10,13, src, dst, srcf, w, mid, size, i, j, srcfx, x
movsxdifnidn wq, wd
movsxdifnidn midq, midd
movsxdifnidn sizeq, sized
add srcq, wq
add dstq, wq
mov xq, wq
dec sizeq
neg xq
movd m4, r6m
SPLATW m4, m4
movd m5, r7m
SPLATW m5, m5
pxor m2, m2
mova m10, [pw_ones]
.loop:
mov iq, midq
mov jq, midq
pxor m3, m3
pxor m11, m11
movu m0, [srcq + xq]
punpcklbw m0, m2
mova m7, m0
mova m8, [pw_one]
mova m12, [pw_ones]
.loop0:
dec jq
mov srcfxq, [srcfq + jq * 8]
add srcfxq, wq
movu m1, [srcfxq + xq]
punpcklbw m1, m2
mova m9, m1
psubw m1, m0
pabsw m1, m1
paddw m11, m1
pcmpgtw m1, m4
mova m6, m11
pcmpgtw m6, m5
por m6, m1
pxor m6, m10
pand m12, m6
pand m9, m12
paddw m7, m9
mova m6, m12
psrlw m6, 15
paddw m8, m6
ptest m12, m12
jz .end_loop0
cmp jq, 0
jg .loop0
.end_loop0:
mova m12, [pw_ones]
.loop1:
inc iq
mov srcfxq, [srcfq + iq * 8]
add srcfxq, wq
movu m1, [srcfxq + xq]
punpcklbw m1, m2
mova m9, m1
psubw m1, m0
pabsw m1, m1
paddw m3, m1
pcmpgtw m1, m4
mova m6, m3
pcmpgtw m6, m5
por m6, m1
pxor m6, m10
pand m12, m6
pand m9, m12
paddw m7, m9
mova m6, m12
psrlw m6, 15
paddw m8, m6
ptest m12, m12
jz .finish
cmp iq, sizeq
jl .loop1
.finish:
mova m9, m8
psrlw m9, 1
paddw m7, m9
mova m1, m7
mova m6, m8
punpcklwd m7, m2
punpcklwd m8, m2
cvtdq2ps m7, m7
cvtdq2ps m8, m8
divps m7, m8
cvttps2dq m7, m7
packssdw m7, m7
packuswb m7, m7
movd [dstq + xq], m7
punpckhwd m1, m2
punpckhwd m6, m2
cvtdq2ps m1, m1
cvtdq2ps m6, m6
divps m1, m6
cvttps2dq m1, m1
packssdw m1, m1
packuswb m1, m1
movd [dstq + xq + 4], m1
add xq, mmsize/2
jl .loop
RET
%endif
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2019 Paul B Mahol
*
* 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/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/atadenoise.h"
void ff_atadenoise_filter_row8_sse4(const uint8_t *src, uint8_t *dst,
const uint8_t **srcf,
int w, int mid, int size,
int thra, int thrb, const float *weights);
void ff_atadenoise_filter_row8_serial_sse4(const uint8_t *src, uint8_t *dst,
const uint8_t **srcf,
int w, int mid, int size,
int thra, int thrb, const float *weights);
av_cold void ff_atadenoise_init_x86(ATADenoiseDSPContext *dsp, int depth, int algorithm, const float *sigma)
{
int cpu_flags = av_get_cpu_flags();
for (int p = 0; p < 4; p++) {
if (ARCH_X86_64 && EXTERNAL_SSE4(cpu_flags) && depth <= 8 && algorithm == PARALLEL && sigma[p] == INT16_MAX) {
dsp->filter_row[p] = ff_atadenoise_filter_row8_sse4;
}
if (ARCH_X86_64 && EXTERNAL_SSE4(cpu_flags) && depth <= 8 && algorithm == SERIAL && sigma[p] == INT16_MAX) {
dsp->filter_row[p] = ff_atadenoise_filter_row8_serial_sse4;
}
}
}
+498
View File
@@ -0,0 +1,498 @@
;*****************************************************************************
;* x86-optimized functions for blend filter
;*
;* Copyright (C) 2015 Paul B Mahol
;* Copyright (C) 2018 Henrik Gramner
;* Copyright (C) 2018 Jokyo Images
;*
;* 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/x86/x86util.asm"
SECTION_RODATA
ps_255: times 4 dd 255.0
pd_32768 : times 4 dd 32768
pd_65535 : times 4 dd 65535
pw_1: times 8 dw 1
pw_128: times 8 dw 128
pw_255: times 8 dw 255
pb_127: times 16 db 127
pb_128: times 16 db 128
pb_255: times 16 db 255
SECTION .text
%macro BLEND_INIT 2-3 0
%if ARCH_X86_64
cglobal blend_%1, 6, 9, %2, top, top_linesize, bottom, bottom_linesize, dst, dst_linesize, width, end, x
mov widthd, dword widthm
%if %3; is 16 bit
add widthq, widthq ; doesn't compile on x86_32
%endif
%else
cglobal blend_%1, 5, 7, %2, top, top_linesize, bottom, bottom_linesize, dst, end, x
%define dst_linesizeq r5mp
%define widthq r6mp
%endif
mov endd, dword r7m
add topq, widthq
add bottomq, widthq
add dstq, widthq
neg widthq
%endmacro
%macro BLEND_END 0
add topq, top_linesizeq
add bottomq, bottom_linesizeq
add dstq, dst_linesizeq
sub endd, 1
jg .nextrow
RET
%endmacro
%macro BLEND_SIMPLE 2-3 0
BLEND_INIT %1, 2, %3
.nextrow:
mov xq, widthq
.loop:
movu m0, [topq + xq]
movu m1, [bottomq + xq]
p%2 m0, m1
movu [dstq + xq], m0
add xq, mmsize
jl .loop
BLEND_END
%endmacro
; %1 name , %2 src (b or w), %3 inter (w or d), %4 (1 if 16bit, not set if 8 bit)
%macro GRAINEXTRACT 3-4 0
BLEND_INIT %1, 6, %4
pxor m4, m4
%if %4 ; 16 bit
VBROADCASTI128 m5, [pd_32768]
%else
VBROADCASTI128 m5, [pw_128]
%endif
.nextrow:
mov xq, widthq
.loop:
movu m1, [topq + xq]
movu m3, [bottomq + xq]
punpckl%2%3 m0, m1, m4
punpckh%2%3 m1, m4
punpckl%2%3 m2, m3, m4
punpckh%2%3 m3, m4
padd%3 m0, m5
padd%3 m1, m5
psub%3 m0, m2
psub%3 m1, m3
packus%3%2 m0, m1
movu [dstq + xq], m0
add xq, mmsize
jl .loop
BLEND_END
%endmacro
%macro MULTIPLY 3 ; a, b, pw_1
pmullw %1, %2 ; xxxxxxxx a * b
paddw %1, %3
psrlw %2, %1, 8
paddw %1, %2
psrlw %1, 8 ; 00xx00xx a * b / 255
%endmacro
%macro SCREEN 4 ; a, b, pw_1, pw_255
pxor %1, %4 ; 00xx00xx 255 - a
pxor %2, %4
MULTIPLY %1, %2, %3
pxor %1, %4 ; 00xx00xx 255 - x / 255
%endmacro
%macro BLEND_MULTIPLY 0
BLEND_INIT multiply, 6
pxor m4, m4
VBROADCASTI128 m5, [pw_1]
.nextrow:
mov xq, widthq
.loop:
movu m1, [topq + xq]
movu m3, [bottomq + xq]
punpcklbw m0, m1, m4
punpckhbw m1, m4
punpcklbw m2, m3, m4
punpckhbw m3, m4
MULTIPLY m0, m2, m5
MULTIPLY m1, m3, m5
packuswb m0, m1
movu [dstq + xq], m0
add xq, mmsize
jl .loop
BLEND_END
%endmacro
%macro BLEND_SCREEN 0
BLEND_INIT screen, 7
pxor m4, m4
VBROADCASTI128 m5, [pw_1]
VBROADCASTI128 m6, [pw_255]
.nextrow:
mov xq, widthq
.loop:
movu m1, [topq + xq]
movu m3, [bottomq + xq]
punpcklbw m0, m1, m4
punpckhbw m1, m4
punpcklbw m2, m3, m4
punpckhbw m3, m4
SCREEN m0, m2, m5, m6
SCREEN m1, m3, m5, m6
packuswb m0, m1
movu [dstq + xq], m0
add xq, mmsize
jl .loop
BLEND_END
%endmacro
;%1 name, %2 (b or w), %3 (set if 16 bit)
%macro AVERAGE 2-3 0
BLEND_INIT %1, 3, %3
pcmpeqb m2, m2
.nextrow:
mov xq, widthq
.loop:
movu m0, [topq + xq]
movu m1, [bottomq + xq]
pxor m0, m2
pxor m1, m2
pavg%2 m0, m1
pxor m0, m2
movu [dstq + xq], m0
add xq, mmsize
jl .loop
BLEND_END
%endmacro
; %1 name , %2 src (b or w), %3 inter (w or d), %4 (1 if 16bit, not set if 8 bit)
%macro GRAINMERGE 3-4 0
BLEND_INIT %1, 6, %4
pxor m4, m4
%if %4 ; 16 bit
VBROADCASTI128 m5, [pd_32768]
%else
VBROADCASTI128 m5, [pw_128]
%endif
.nextrow:
mov xq, widthq
.loop:
movu m1, [topq + xq]
movu m3, [bottomq + xq]
punpckl%2%3 m0, m1, m4
punpckh%2%3 m1, m4
punpckl%2%3 m2, m3, m4
punpckh%2%3 m3, m4
padd%3 m0, m2
padd%3 m1, m3
psub%3 m0, m5
psub%3 m1, m5
packus%3%2 m0, m1
movu [dstq + xq], m0
add xq, mmsize
jl .loop
BLEND_END
%endmacro
%macro HARDMIX 0
BLEND_INIT hardmix, 5
VBROADCASTI128 m2, [pb_255]
VBROADCASTI128 m3, [pb_128]
VBROADCASTI128 m4, [pb_127]
.nextrow:
mov xq, widthq
.loop:
movu m0, [topq + xq]
movu m1, [bottomq + xq]
pxor m1, m4
pxor m0, m3
pcmpgtb m1, m0
pxor m1, m2
movu [dstq + xq], m1
add xq, mmsize
jl .loop
BLEND_END
%endmacro
%macro DIVIDE 0
BLEND_INIT divide, 4
pxor m2, m2
mova m3, [ps_255]
.nextrow:
mov xq, widthq
.loop:
movd m0, [topq + xq] ; 000000xx
movd m1, [bottomq + xq]
punpcklbw m0, m2 ; 00000x0x
punpcklbw m1, m2
punpcklwd m0, m2 ; 000x000x
punpcklwd m1, m2
cvtdq2ps m0, m0
cvtdq2ps m1, m1
divps m0, m1 ; a / b
mulps m0, m3 ; a / b * 255
minps m0, m3
cvttps2dq m0, m0
packssdw m0, m0 ; 00000x0x
packuswb m0, m0 ; 000000xx
movd [dstq + xq], m0
add xq, mmsize / 4
jl .loop
BLEND_END
%endmacro
%macro PHOENIX 2-3 0
; %1 name, %2 b or w, %3 (opt) 1 if 16 bit
BLEND_INIT %1, 4, %3
VBROADCASTI128 m3, [pb_255]
.nextrow:
mov xq, widthq
.loop:
movu m0, [topq + xq]
movu m1, [bottomq + xq]
mova m2, m0
pminu%2 m0, m1
pmaxu%2 m1, m2
mova m2, m3
psubus%2 m2, m1
paddus%2 m2, m0
movu [dstq + xq], m2
add xq, mmsize
jl .loop
BLEND_END
%endmacro
; %1 name , %2 src (b or w), %3 inter (w or d), %4 (1 if 16bit, not set if 8 bit)
%macro DIFFERENCE 3-4 0
BLEND_INIT %1, 5, %4
pxor m2, m2
.nextrow:
mov xq, widthq
.loop:
movu m0, [topq + xq]
movu m1, [bottomq + xq]
punpckh%2%3 m3, m0, m2
punpckl%2%3 m0, m2
punpckh%2%3 m4, m1, m2
punpckl%2%3 m1, m2
psub%3 m0, m1
psub%3 m3, m4
%if %4; 16 bit
pabsd m0, m0
pabsd m3, m3
%else
ABS2 m0, m3, m1, m4
%endif
packus%3%2 m0, m3
movu [dstq + xq], m0
add xq, mmsize
jl .loop
BLEND_END
%endmacro
; %1 name , %2 src (b or w), %3 inter (w or d), %4 (1 if 16bit, not set if 8 bit)
%macro EXTREMITY 3-4 0
BLEND_INIT %1, 8, %4
pxor m2, m2
%if %4; 16 bit
VBROADCASTI128 m4, [pd_65535]
%else
VBROADCASTI128 m4, [pw_255]
%endif
.nextrow:
mov xq, widthq
.loop:
movu m0, [topq + xq]
movu m1, [bottomq + xq]
punpckh%2%3 m5, m0, m2
punpckl%2%3 m0, m2
punpckh%2%3 m6, m1, m2
punpckl%2%3 m1, m2
psub%3 m3, m4, m0
psub%3 m7, m4, m5
psub%3 m3, m1
psub%3 m7, m6
%if %4; 16 bit
pabsd m3, m3
pabsd m7, m7
%else
ABS2 m3, m7, m1, m6
%endif
packus%3%2 m3, m7
movu [dstq + xq], m3
add xq, mmsize
jl .loop
BLEND_END
%endmacro
%macro NEGATION 3-4 0
BLEND_INIT %1, 8, %4
pxor m2, m2
%if %4; 16 bit
VBROADCASTI128 m4, [pd_65535]
%else
VBROADCASTI128 m4, [pw_255]
%endif
.nextrow:
mov xq, widthq
.loop:
movu m0, [topq + xq]
movu m1, [bottomq + xq]
punpckh%2%3 m5, m0, m2
punpckl%2%3 m0, m2
punpckh%2%3 m6, m1, m2
punpckl%2%3 m1, m2
psub%3 m3, m4, m0
psub%3 m7, m4, m5
psub%3 m3, m1
psub%3 m7, m6
%if %4; 16 bit
pabsd m3, m3
pabsd m7, m7
%else
ABS2 m3, m7, m1, m6
%endif
psub%3 m0, m4, m3
psub%3 m1, m4, m7
packus%3%2 m0, m1
movu [dstq + xq], m0
add xq, mmsize
jl .loop
BLEND_END
%endmacro
INIT_XMM sse2
BLEND_SIMPLE xor, xor
BLEND_SIMPLE or, or
BLEND_SIMPLE and, and
BLEND_SIMPLE addition, addusb
BLEND_SIMPLE subtract, subusb
BLEND_SIMPLE darken, minub
BLEND_SIMPLE lighten, maxub
GRAINEXTRACT grainextract, b, w
BLEND_MULTIPLY
BLEND_SCREEN
AVERAGE average, b
GRAINMERGE grainmerge, b, w
HARDMIX
PHOENIX phoenix, b
DIFFERENCE difference, b, w
DIVIDE
EXTREMITY extremity, b, w
NEGATION negation, b, w
%if ARCH_X86_64
BLEND_SIMPLE addition_16, addusw, 1
BLEND_SIMPLE and_16, and, 1
BLEND_SIMPLE or_16, or, 1
BLEND_SIMPLE subtract_16, subusw, 1
BLEND_SIMPLE xor_16, xor, 1
AVERAGE average_16, w, 1
%endif
INIT_XMM ssse3
DIFFERENCE difference, b, w
EXTREMITY extremity, b, w
NEGATION negation, b, w
INIT_XMM sse4
%if ARCH_X86_64
BLEND_SIMPLE darken_16, minuw, 1
BLEND_SIMPLE lighten_16, maxuw, 1
GRAINEXTRACT grainextract_16, w, d, 1
GRAINMERGE grainmerge_16, w, d, 1
PHOENIX phoenix_16, w, 1
DIFFERENCE difference_16, w, d, 1
EXTREMITY extremity_16, w, d, 1
NEGATION negation_16, w, d, 1
%endif
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
BLEND_SIMPLE xor, xor
BLEND_SIMPLE or, or
BLEND_SIMPLE and, and
BLEND_SIMPLE addition, addusb
BLEND_SIMPLE subtract, subusb
BLEND_SIMPLE darken, minub
BLEND_SIMPLE lighten, maxub
GRAINEXTRACT grainextract, b, w
BLEND_MULTIPLY
BLEND_SCREEN
AVERAGE average, b
GRAINMERGE grainmerge, b, w
HARDMIX
PHOENIX phoenix, b
DIFFERENCE difference, b, w
EXTREMITY extremity, b, w
NEGATION negation, b, w
%if ARCH_X86_64
BLEND_SIMPLE addition_16, addusw, 1
BLEND_SIMPLE and_16, and, 1
BLEND_SIMPLE darken_16, minuw, 1
BLEND_SIMPLE lighten_16, maxuw, 1
BLEND_SIMPLE or_16, or, 1
BLEND_SIMPLE subtract_16, subusw, 1
BLEND_SIMPLE xor_16, xor, 1
GRAINEXTRACT grainextract_16, w, d, 1
AVERAGE average_16, w, 1
GRAINMERGE grainmerge_16, w, d, 1
PHOENIX phoenix_16, w, 1
DIFFERENCE difference_16, w, d, 1
EXTREMITY extremity_16, w, d, 1
NEGATION negation_16, w, d, 1
%endif
%endif
+203
View File
@@ -0,0 +1,203 @@
/*
* Copyright (c) 2015 Paul B Mahol
*
* 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/blend.h"
#define BLEND_FUNC(name, opt) \
void ff_blend_##name##_##opt(const uint8_t *top, ptrdiff_t top_linesize, \
const uint8_t *bottom, ptrdiff_t bottom_linesize, \
uint8_t *dst, ptrdiff_t dst_linesize, \
ptrdiff_t width, ptrdiff_t height, \
FilterParams *param, SliceParams *sliceparam);
BLEND_FUNC(addition, sse2)
BLEND_FUNC(addition, avx2)
BLEND_FUNC(grainmerge, sse2)
BLEND_FUNC(grainmerge, avx2)
BLEND_FUNC(average, sse2)
BLEND_FUNC(average, avx2)
BLEND_FUNC(and, sse2)
BLEND_FUNC(and, avx2)
BLEND_FUNC(darken, sse2)
BLEND_FUNC(darken, avx2)
BLEND_FUNC(grainextract, sse2)
BLEND_FUNC(grainextract, avx2)
BLEND_FUNC(multiply, sse2)
BLEND_FUNC(multiply, avx2)
BLEND_FUNC(screen, sse2)
BLEND_FUNC(screen, avx2)
BLEND_FUNC(hardmix, sse2)
BLEND_FUNC(hardmix, avx2)
BLEND_FUNC(divide, sse2)
BLEND_FUNC(lighten, sse2)
BLEND_FUNC(lighten, avx2)
BLEND_FUNC(or, sse2)
BLEND_FUNC(or, avx2)
BLEND_FUNC(phoenix, sse2)
BLEND_FUNC(phoenix, avx2)
BLEND_FUNC(subtract, sse2)
BLEND_FUNC(subtract, avx2)
BLEND_FUNC(xor, sse2)
BLEND_FUNC(xor, avx2)
BLEND_FUNC(difference, sse2)
BLEND_FUNC(difference, ssse3)
BLEND_FUNC(difference, avx2)
BLEND_FUNC(extremity, sse2)
BLEND_FUNC(extremity, ssse3)
BLEND_FUNC(extremity, avx2)
BLEND_FUNC(negation, sse2)
BLEND_FUNC(negation, ssse3)
BLEND_FUNC(negation, avx2)
#if ARCH_X86_64
BLEND_FUNC(addition_16, sse2)
BLEND_FUNC(addition_16, avx2)
BLEND_FUNC(grainmerge_16, sse4)
BLEND_FUNC(grainmerge_16, avx2)
BLEND_FUNC(average_16, sse2)
BLEND_FUNC(average_16, avx2)
BLEND_FUNC(and_16, sse2)
BLEND_FUNC(and_16, avx2)
BLEND_FUNC(darken_16, sse4)
BLEND_FUNC(darken_16, avx2)
BLEND_FUNC(grainextract_16, sse4)
BLEND_FUNC(grainextract_16, avx2)
BLEND_FUNC(difference_16, sse4)
BLEND_FUNC(difference_16, avx2)
BLEND_FUNC(extremity_16, sse4)
BLEND_FUNC(extremity_16, avx2)
BLEND_FUNC(negation_16, sse4)
BLEND_FUNC(negation_16, avx2)
BLEND_FUNC(lighten_16, sse4)
BLEND_FUNC(lighten_16, avx2)
BLEND_FUNC(or_16, sse2)
BLEND_FUNC(or_16, avx2)
BLEND_FUNC(phoenix_16, sse4)
BLEND_FUNC(phoenix_16, avx2)
BLEND_FUNC(subtract_16, sse2)
BLEND_FUNC(subtract_16, avx2)
BLEND_FUNC(xor_16, sse2)
BLEND_FUNC(xor_16, avx2)
#endif /* ARCH_X86_64 */
av_cold void ff_blend_init_x86(FilterParams *param, int depth)
{
int cpu_flags = av_get_cpu_flags();
if (depth == 8) {
if (EXTERNAL_SSE2(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_ADDITION: param->blend = ff_blend_addition_sse2; break;
case BLEND_GRAINMERGE: param->blend = ff_blend_grainmerge_sse2; break;
case BLEND_AND: param->blend = ff_blend_and_sse2; break;
case BLEND_AVERAGE: param->blend = ff_blend_average_sse2; break;
case BLEND_DARKEN: param->blend = ff_blend_darken_sse2; break;
case BLEND_GRAINEXTRACT: param->blend = ff_blend_grainextract_sse2; break;
case BLEND_DIVIDE: param->blend = ff_blend_divide_sse2; break;
case BLEND_HARDMIX: param->blend = ff_blend_hardmix_sse2; break;
case BLEND_LIGHTEN: param->blend = ff_blend_lighten_sse2; break;
case BLEND_MULTIPLY: param->blend = ff_blend_multiply_sse2; break;
case BLEND_OR: param->blend = ff_blend_or_sse2; break;
case BLEND_PHOENIX: param->blend = ff_blend_phoenix_sse2; break;
case BLEND_SCREEN: param->blend = ff_blend_screen_sse2; break;
case BLEND_SUBTRACT: param->blend = ff_blend_subtract_sse2; break;
case BLEND_XOR: param->blend = ff_blend_xor_sse2; break;
case BLEND_DIFFERENCE: param->blend = ff_blend_difference_sse2; break;
case BLEND_EXTREMITY: param->blend = ff_blend_extremity_sse2; break;
case BLEND_NEGATION: param->blend = ff_blend_negation_sse2; break;
}
}
if (EXTERNAL_SSSE3(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_DIFFERENCE: param->blend = ff_blend_difference_ssse3; break;
case BLEND_EXTREMITY: param->blend = ff_blend_extremity_ssse3; break;
case BLEND_NEGATION: param->blend = ff_blend_negation_ssse3; break;
}
}
if (EXTERNAL_AVX2_FAST(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_ADDITION: param->blend = ff_blend_addition_avx2; break;
case BLEND_GRAINMERGE: param->blend = ff_blend_grainmerge_avx2; break;
case BLEND_AND: param->blend = ff_blend_and_avx2; break;
case BLEND_AVERAGE: param->blend = ff_blend_average_avx2; break;
case BLEND_DARKEN: param->blend = ff_blend_darken_avx2; break;
case BLEND_GRAINEXTRACT: param->blend = ff_blend_grainextract_avx2; break;
case BLEND_HARDMIX: param->blend = ff_blend_hardmix_avx2; break;
case BLEND_LIGHTEN: param->blend = ff_blend_lighten_avx2; break;
case BLEND_MULTIPLY: param->blend = ff_blend_multiply_avx2; break;
case BLEND_OR: param->blend = ff_blend_or_avx2; break;
case BLEND_PHOENIX: param->blend = ff_blend_phoenix_avx2; break;
case BLEND_SCREEN: param->blend = ff_blend_screen_avx2; break;
case BLEND_SUBTRACT: param->blend = ff_blend_subtract_avx2; break;
case BLEND_XOR: param->blend = ff_blend_xor_avx2; break;
case BLEND_DIFFERENCE: param->blend = ff_blend_difference_avx2; break;
case BLEND_EXTREMITY: param->blend = ff_blend_extremity_avx2; break;
case BLEND_NEGATION: param->blend = ff_blend_negation_avx2; break;
}
}
} else if (depth == 16) {
#if ARCH_X86_64
if (EXTERNAL_SSE2(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_ADDITION: param->blend = ff_blend_addition_16_sse2; break;
case BLEND_AND: param->blend = ff_blend_and_16_sse2; break;
case BLEND_AVERAGE: param->blend = ff_blend_average_16_sse2; break;
case BLEND_OR: param->blend = ff_blend_or_16_sse2; break;
case BLEND_SUBTRACT: param->blend = ff_blend_subtract_16_sse2; break;
case BLEND_XOR: param->blend = ff_blend_xor_16_sse2; break;
}
}
if (EXTERNAL_SSE4(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_GRAINMERGE: param->blend = ff_blend_grainmerge_16_sse4; break;
case BLEND_DARKEN: param->blend = ff_blend_darken_16_sse4; break;
case BLEND_GRAINEXTRACT: param->blend = ff_blend_grainextract_16_sse4; break;
case BLEND_DIFFERENCE: param->blend = ff_blend_difference_16_sse4; break;
case BLEND_EXTREMITY: param->blend = ff_blend_extremity_16_sse4; break;
case BLEND_NEGATION: param->blend = ff_blend_negation_16_sse4; break;
case BLEND_LIGHTEN: param->blend = ff_blend_lighten_16_sse4; break;
case BLEND_PHOENIX: param->blend = ff_blend_phoenix_16_sse4; break;
}
}
if (EXTERNAL_AVX2_FAST(cpu_flags) && param->opacity == 1) {
switch (param->mode) {
case BLEND_ADDITION: param->blend = ff_blend_addition_16_avx2; break;
case BLEND_GRAINMERGE: param->blend = ff_blend_grainmerge_16_avx2; break;
case BLEND_AND: param->blend = ff_blend_and_16_avx2; break;
case BLEND_AVERAGE: param->blend = ff_blend_average_16_avx2; break;
case BLEND_DARKEN: param->blend = ff_blend_darken_16_avx2; break;
case BLEND_GRAINEXTRACT: param->blend = ff_blend_grainextract_16_avx2; break;
case BLEND_DIFFERENCE: param->blend = ff_blend_difference_16_avx2; break;
case BLEND_EXTREMITY: param->blend = ff_blend_extremity_16_avx2; break;
case BLEND_NEGATION: param->blend = ff_blend_negation_16_avx2; break;
case BLEND_LIGHTEN: param->blend = ff_blend_lighten_16_avx2; break;
case BLEND_OR: param->blend = ff_blend_or_16_avx2; break;
case BLEND_PHOENIX: param->blend = ff_blend_phoenix_16_avx2; break;
case BLEND_SUBTRACT: param->blend = ff_blend_subtract_16_avx2; break;
case BLEND_XOR: param->blend = ff_blend_xor_16_avx2; break;
}
}
#endif /* ARCH_X86_64 */
}
}
+285
View File
@@ -0,0 +1,285 @@
;*****************************************************************************
;* x86-optimized functions for bwdif filter
;*
;* Copyright (C) 2016 Thomas Mundt <loudmax@yahoo.de>
;*
;* Based on yadif simd code
;* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
;* 2013 Daniel Kang <daniel.d.kang@gmail.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/x86/x86util.asm"
SECTION_RODATA 32
pw_coefhf: times 8 dw 1016, 5570
pw_coefhf1: times 16 dw -3801
pw_coefsp: times 8 dw 5077, -981
pw_splfdif: times 8 dw -768, 768
SECTION .text
%macro LOAD8 2
%if mmsize == 32
pmovzxbw %1, %2
%else
movh %1, %2
punpcklbw %1, m7
%endif
%endmacro
%macro LOAD12 2
movu %1, %2
%endmacro
%macro DISP8 0
%if mmsize == 32
vextracti128 xm1, m2, 1
packuswb xm2, xm1
movu [dstq], xm2
%else
packuswb m2, m2
movh [dstq], m2
%endif
%endmacro
%macro DISP12 0
CLIPW m2, m7, m12
movu [dstq], m2
%endmacro
%macro FILTER 5
pxor m7, m7
.loop%1:
LOAD%4 m0, [curq+t0*%5]
LOAD%4 m1, [curq+t1*%5]
LOAD%4 m2, [%2]
LOAD%4 m3, [%3]
mova m4, m3
paddw m3, m2
psubw m2, m4
ABS1 m2, m4
mova m8, m3
mova m9, m2
LOAD%4 m3, [prevq+t0*%5]
LOAD%4 m4, [prevq+t1*%5]
psubw m3, m0
psubw m4, m1
ABS2 m3, m4, m5, m6
paddw m3, m4
psrlw m2, 1
psrlw m3, 1
pmaxsw m2, m3
LOAD%4 m3, [nextq+t0*%5]
LOAD%4 m4, [nextq+t1*%5]
psubw m3, m0
psubw m4, m1
ABS2 m3, m4, m5, m6
paddw m3, m4
psrlw m3, 1
pmaxsw m2, m3
LOAD%4 m3, [%2+t0*2*%5]
LOAD%4 m4, [%3+t0*2*%5]
LOAD%4 m5, [%2+t1*2*%5]
LOAD%4 m6, [%3+t1*2*%5]
paddw m3, m4
paddw m5, m6
mova m6, m3
paddw m6, m5
mova m10, m6
psrlw m3, 1
psrlw m5, 1
psubw m3, m0
psubw m5, m1
mova m6, m3
pminsw m3, m5
pmaxsw m5, m6
mova m4, m8
psraw m4, 1
mova m6, m4
psubw m6, m0
psubw m4, m1
pmaxsw m3, m6
pminsw m5, m6
pmaxsw m3, m4
pminsw m5, m4
mova m6, m7
psubw m6, m3
pmaxsw m6, m5
mova m3, m2
pcmpgtw m3, m7
pand m6, m3
pmaxsw m2, m6
mova m11, m2
LOAD%4 m2, [%2+t0*4*%5]
LOAD%4 m3, [%3+t0*4*%5]
LOAD%4 m4, [%2+t1*4*%5]
LOAD%4 m5, [%3+t1*4*%5]
paddw m2, m3
paddw m4, m5
paddw m2, m4
mova m3, m2
punpcklwd m2, m8
punpckhwd m3, m8
pmaddwd m2, [pw_coefhf]
pmaddwd m3, [pw_coefhf]
mova m4, m10
mova m6, m4
pmullw m4, [pw_coefhf1]
pmulhw m6, [pw_coefhf1]
mova m5, m4
punpcklwd m4, m6
punpckhwd m5, m6
paddd m2, m4
paddd m3, m5
psrad m2, 2
psrad m3, 2
mova m4, m0
paddw m0, m1
%if ARCH_X86_64
LOAD%4 m5, [curq+t2*%5]
LOAD%4 m6, [curq+t3*%5]
%else
mov r4, prefs3mp
mov r5, mrefs3mp
LOAD%4 m5, [curq+t0*%5]
LOAD%4 m6, [curq+t1*%5]
mov r4, prefsmp
mov r5, mrefsmp
%endif
paddw m6, m5
psubw m1, m4
ABS1 m1, m4
pcmpgtw m1, m9
mova m4, m1
punpcklwd m1, m4
punpckhwd m4, m4
pand m2, m1
pand m3, m4
mova m5, [pw_splfdif]
mova m7, m5
pand m5, m1
pand m7, m4
paddw m5, [pw_coefsp]
paddw m7, [pw_coefsp]
mova m4, m0
punpcklwd m0, m6
punpckhwd m4, m6
pmaddwd m0, m5
pmaddwd m4, m7
paddd m2, m0
paddd m3, m4
psrad m2, 13
psrad m3, 13
packssdw m2, m3
mova m4, m8
psraw m4, 1
mova m0, m11
mova m3, m4
psubw m4, m0
paddw m3, m0
CLIPW m2, m4, m3
pxor m7, m7
DISP%4
add dstq, STEP
add prevq, STEP
add curq, STEP
add nextq, STEP
sub DWORD wm, mmsize/2
jg .loop%1
%endmacro
%macro PROC 2
%if ARCH_X86_64
movsxd r5, DWORD prefsm
movsxd r6, DWORD mrefsm
movsxd r7, DWORD prefs3m
movsxd r8, DWORD mrefs3m
DECLARE_REG_TMP 5, 6, 7, 8
%else
%define m8 [rsp+ 0]
%define m9 [rsp+16]
%define m10 [rsp+32]
%define m11 [rsp+48]
mov r4, prefsmp
mov r5, mrefsmp
DECLARE_REG_TMP 4, 5
%endif
cmp DWORD paritym, 0
je .parity0
FILTER 1, prevq, curq, %1, %2
jmp .ret
.parity0:
FILTER 0, curq, nextq, %1, %2
.ret:
RET
%endmacro
%macro BWDIF 0
%if ARCH_X86_64
cglobal bwdif_filter_line, 4, 9, 12, 0, dst, prev, cur, next, w, prefs, \
mrefs, prefs2, mrefs2, prefs3, mrefs3, \
prefs4, mrefs4, parity, clip_max
%else
cglobal bwdif_filter_line, 4, 6, 8, 64, dst, prev, cur, next, w, prefs, \
mrefs, prefs2, mrefs2, prefs3, mrefs3, \
prefs4, mrefs4, parity, clip_max
%endif
%define STEP mmsize/2
PROC 8, 1
%if ARCH_X86_64
cglobal bwdif_filter_line_12bit, 4, 9, 13, 0, dst, prev, cur, next, w, \
prefs, mrefs, prefs2, mrefs2, \
prefs3, mrefs3, prefs4, \
mrefs4, parity, clip_max
%if mmsize == 32
vpbroadcastw m12, WORD clip_maxm
%else
movd m12, DWORD clip_maxm
SPLATW m12, m12, 0
%endif
%else
cglobal bwdif_filter_line_12bit, 4, 6, 8, 80, dst, prev, cur, next, w, \
prefs, mrefs, prefs2, mrefs2, \
prefs3, mrefs3, prefs4, \
mrefs4, parity, clip_max
%define m12 [rsp+64]
movd m0, DWORD clip_maxm
SPLATW m0, m0, 0
mova m12, m0
%endif
%define STEP mmsize
PROC 12, 2
%endmacro
INIT_XMM ssse3
BWDIF
INIT_XMM sse2
BWDIF
%if HAVE_AVX2_EXTERNAL && ARCH_X86_64
INIT_YMM avx2
BWDIF
%endif
+72
View File
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2016 Thomas Mundt <loudmax@yahoo.de>
*
* 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/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/bwdifdsp.h"
void ff_bwdif_filter_line_sse2(void *dst, const void *prev, const void *cur, const void *next,
int w, int prefs, int mrefs, int prefs2,
int mrefs2, int prefs3, int mrefs3, int prefs4,
int mrefs4, int parity, int clip_max);
void ff_bwdif_filter_line_ssse3(void *dst, const void *prev, const void *cur, const void *next,
int w, int prefs, int mrefs, int prefs2,
int mrefs2, int prefs3, int mrefs3, int prefs4,
int mrefs4, int parity, int clip_max);
void ff_bwdif_filter_line_avx2(void *dst, const void *prev, const void *cur, const void *next,
int w, int prefs, int mrefs, int prefs2,
int mrefs2, int prefs3, int mrefs3, int prefs4,
int mrefs4, int parity, int clip_max);
void ff_bwdif_filter_line_12bit_sse2(void *dst, const void *prev, const void *cur, const void *next,
int w, int prefs, int mrefs, int prefs2,
int mrefs2, int prefs3, int mrefs3, int prefs4,
int mrefs4, int parity, int clip_max);
void ff_bwdif_filter_line_12bit_ssse3(void *dst, const void *prev, const void *cur, const void *next,
int w, int prefs, int mrefs, int prefs2,
int mrefs2, int prefs3, int mrefs3, int prefs4,
int mrefs4, int parity, int clip_max);
void ff_bwdif_filter_line_12bit_avx2(void *dst, const void *prev, const void *cur, const void *next,
int w, int prefs, int mrefs, int prefs2,
int mrefs2, int prefs3, int mrefs3, int prefs4,
int mrefs4, int parity, int clip_max);
av_cold void ff_bwdif_init_x86(BWDIFDSPContext *bwdif, int bit_depth)
{
int cpu_flags = av_get_cpu_flags();
if (bit_depth <= 8) {
if (EXTERNAL_SSE2(cpu_flags))
bwdif->filter_line = ff_bwdif_filter_line_sse2;
if (EXTERNAL_SSSE3(cpu_flags))
bwdif->filter_line = ff_bwdif_filter_line_ssse3;
if (ARCH_X86_64 && EXTERNAL_AVX2_FAST(cpu_flags))
bwdif->filter_line = ff_bwdif_filter_line_avx2;
} else if (bit_depth <= 12) {
if (EXTERNAL_SSE2(cpu_flags))
bwdif->filter_line = ff_bwdif_filter_line_12bit_sse2;
if (EXTERNAL_SSSE3(cpu_flags))
bwdif->filter_line = ff_bwdif_filter_line_12bit_ssse3;
if (ARCH_X86_64 && EXTERNAL_AVX2_FAST(cpu_flags))
bwdif->filter_line = ff_bwdif_filter_line_12bit_avx2;
}
}
+304
View File
@@ -0,0 +1,304 @@
;*****************************************************************************
;* x86-optimized functions for convolution filter
;*
;* 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/x86/x86util.asm"
SECTION_RODATA
half: dd 0.5
data_p1: dd 1
data_n1: dd -1
data_p2: dd 2
data_n2: dd -2
ALIGN 64
sobel_perm: db 0, 16, 32, 48, 1, 17, 33, 49, 2, 18, 34, 50, 3, 19, 35, 51
db 4, 20, 36, 52, 5, 21, 37, 53, 6, 22, 38, 54, 7, 23, 39, 55
db 8, 24, 40, 56, 9, 25, 41, 57, 10, 26, 42, 58, 11, 27, 43, 59
db 12, 28, 44, 60, 13, 29, 45, 61, 14, 30, 46, 62, 15, 31, 47, 63
sobel_mulA: db -1, 1, -2, 2
sobel_mulB: db 1, -1, 2, -2
SECTION .text
; void filter_3x3_sse4(uint8_t *dst, int width,
; float rdiv, float bias, const int *const matrix,
; const uint8_t *c[], int peak, int radius,
; int dstride, int stride)
%macro PROCESS_V 1
movss m2, [matrixq + 4 * %1]
VBROADCASTSS m2, m2
movss m3, [c%1q + xq]
punpcklbw m3, m6
punpcklwd m3, m6
pmulld m2, m3
paddd m4, m2
%endmacro
%macro PROCESS_S 1
movzx ptrd, byte [c%1q + xq]
imul ptrd, [matrixq + 4 * %1]
add rd, ptrd
%endmacro
%macro FILTER_3X3 0
%if UNIX64
cglobal filter_3x3, 4, 15, 7, dst, width, matrix, ptr, c0, c1, c2, c3, c4, c5, c6, c7, c8, r, x
%else
cglobal filter_3x3, 4, 15, 7, dst, width, rdiv, bias, matrix, ptr, c0, c1, c2, c3, c4, c5, c6, c7, c8, r, x
%endif
%if WIN64
SWAP m0, m2
SWAP m1, m3
mov r2q, matrixmp
mov r3q, ptrmp
DEFINE_ARGS dst, width, matrix, ptr, c0, c1, c2, c3, c4, c5, c6, c7, c8, r, x
%endif
movsxdifnidn widthq, widthd
VBROADCASTSS m0, m0
VBROADCASTSS m1, m1
pxor m6, m6
movss m5, [half]
VBROADCASTSS m5, m5
mov c0q, [ptrq + 0*gprsize]
mov c1q, [ptrq + 1*gprsize]
mov c2q, [ptrq + 2*gprsize]
mov c3q, [ptrq + 3*gprsize]
mov c4q, [ptrq + 4*gprsize]
mov c5q, [ptrq + 5*gprsize]
mov c6q, [ptrq + 6*gprsize]
mov c7q, [ptrq + 7*gprsize]
mov c8q, [ptrq + 8*gprsize]
xor xq, xq
cmp widthq, mmsize/4
jl .loop2
mov rq, widthq
and rq, mmsize/4-1
sub widthq, rq
.loop1:
pxor m4, m4 ; sum = 0;
PROCESS_V 0
PROCESS_V 1
PROCESS_V 2
PROCESS_V 3
PROCESS_V 4
PROCESS_V 5
PROCESS_V 6
PROCESS_V 7
PROCESS_V 8
cvtdq2ps m4, m4
mulps m4, m0 ; sum *= rdiv
addps m4, m1 ; sum += bias
addps m4, m5 ; sum += 0.5
cvttps2dq m4, m4
packssdw m4, m4
packuswb m4, m4
movss [dstq + xq], m4
add xq, mmsize/4
cmp xq, widthq
jl .loop1
add widthq, rq
cmp xq, widthq
jge .end
.loop2:
; reuse r to hold sum, init with zero
xor rd, rd
PROCESS_S 0
PROCESS_S 1
PROCESS_S 2
PROCESS_S 3
PROCESS_S 4
PROCESS_S 5
PROCESS_S 6
PROCESS_S 7
PROCESS_S 8
pxor m4, m4
cvtsi2ss m4, rd
mulss m4, m0 ; sum *= rdiv
addss m4, m1 ; sum += bias
addss m4, m5 ; sum += 0.5
; we don't have simple scalar instructions to convert
; from 32bit to 8bit with saturation, so here
; just use packed version SSE instructions for simplicity.
cvttps2dq m4, m4 ; trunc to integer
packssdw m4, m4
packuswb m4, m4
movd rd, m4
mov [dstq + xq], rb
add xq, 1
cmp xq, widthq
jl .loop2
.end:
RET
%endmacro
%if ARCH_X86_64
INIT_XMM sse4
FILTER_3X3
%endif
%macro SOBEL_MUL 2
movzx ptrd, byte [c%1q + xq]
imul ptrd, [%2]
add rd, ptrd
%endmacro
%macro SOBEL_ADD 1
movzx ptrd, byte [c%1q + xq]
add rd, ptrd
%endmacro
; void filter_sobel_avx512(uint8_t *dst, int width,
; float scale, float delta, const int *const matrix,
; const uint8_t *c[], int peak, int radius,
; int dstride, int stride)
%macro FILTER_SOBEL 0
%if UNIX64
cglobal filter_sobel, 4, 15, 7, dst, width, matrix, ptr, c0, c1, c2, c3, c4, c5, c6, c7, c8, r, x
%else
cglobal filter_sobel, 4, 15, 7, dst, width, rdiv, bias, matrix, ptr, c0, c1, c2, c3, c4, c5, c6, c7, c8, r, x
%endif
%if WIN64
VBROADCASTSS m0, xmm2
VBROADCASTSS m1, xmm3
mov r2q, matrixmp
mov r3q, ptrmp
DEFINE_ARGS dst, width, matrix, ptr, c0, c1, c2, c3, c4, c5, c6, c7, c8, r, x
%else
VBROADCASTSS m0, xmm0
VBROADCASTSS m1, xmm1
%endif
movsxdifnidn widthq, widthd
pxor m6, m6
mov c0q, [ptrq + 0*gprsize]
mov c1q, [ptrq + 1*gprsize]
mov c2q, [ptrq + 2*gprsize]
mov c3q, [ptrq + 3*gprsize]
mov c4q, [ptrq + 4*gprsize]
mov c5q, [ptrq + 5*gprsize]
mov c6q, [ptrq + 6*gprsize]
mov c7q, [ptrq + 7*gprsize]
mov c8q, [ptrq + 8*gprsize]
xor xq, xq
cmp widthq, mmsize/4
jl .loop2
mov rq, widthq
and rq, mmsize/4-1
sub widthq, rq
mova m6, [sobel_perm]
.loop1:
movu xm3, [c2q + xq]
pmovzxbd m5, [c0q + xq]
vinserti32x4 ym3, [c6q + xq], 1
pmovzxbd m4, [c8q + xq]
vinserti32x4 m2, m3, [c1q + xq], 2
vinserti32x4 m3, [c5q + xq], 2
vinserti32x4 m2, [c7q + xq], 3
vinserti32x4 m3, [c3q + xq], 3
vpermb m2, m6, m2
psubd m4, m5
vpermb m3, m6, m3
mova m5, m4
vpdpbusd m4, m2, [sobel_mulA] {1to16}
vpdpbusd m5, m3, [sobel_mulB] {1to16}
cvtdq2ps m4, m4
mulps m4, m4
cvtdq2ps m5, m5
VFMADD231PS m4, m5, m5
sqrtps m4, m4
fmaddps m4, m4, m0, m1
cvttps2dq m4, m4
vpmovusdb [dstq + xq], m4
add xq, mmsize/4
cmp xq, widthq
jl .loop1
add widthq, rq
cmp xq, widthq
jge .end
.loop2:
xor rd, rd
pxor m4, m4
;Gx
SOBEL_MUL 0, data_n1
SOBEL_MUL 1, data_n2
SOBEL_MUL 2, data_n1
SOBEL_ADD 6
SOBEL_MUL 7, data_p2
SOBEL_ADD 8
cvtsi2ss xmm4, rd
mulss xmm4, xmm4
xor rd, rd
;Gy
SOBEL_MUL 0, data_n1
SOBEL_ADD 2
SOBEL_MUL 3, data_n2
SOBEL_MUL 5, data_p2
SOBEL_MUL 6, data_n1
SOBEL_ADD 8
cvtsi2ss xmm5, rd
fmaddss xmm4, xmm5, xmm5, xmm4
sqrtps xmm4, xmm4
fmaddss xmm4, xmm4, xm0, xm1 ;sum = sum * rdiv + bias
cvttps2dq xmm4, xmm4 ; trunc to integer
packssdw xmm4, xmm4
packuswb xmm4, xmm4
movd rd, xmm4
mov [dstq + xq], rb
add xq, 1
cmp xq, widthq
jl .loop2
.end:
RET
%endmacro
%if ARCH_X86_64
%if HAVE_AVX512ICL_EXTERNAL
INIT_ZMM avx512icl
FILTER_SOBEL
%endif
%endif
@@ -0,0 +1,64 @@
/*
*
* 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 "config.h"
#include "libavutil/attributes.h"
#include "libavutil/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/convolution.h"
void ff_filter_3x3_sse4(uint8_t *dst, int width,
float rdiv, float bias, const int *const matrix,
const uint8_t *c[], int peak, int radius,
int dstride, int stride, int size);
void ff_filter_sobel_avx512icl(uint8_t *dst, int width,
float scale, float delta, const int *const matrix,
const uint8_t *c[], int peak, int radius,
int dstride, int stride, int size);
av_cold void ff_convolution_init_x86(ConvolutionContext *s)
{
#if ARCH_X86_64
int i;
int cpu_flags = av_get_cpu_flags();
for (i = 0; i < 4; i++) {
if (s->mode[i] == MATRIX_SQUARE) {
if (s->matrix_length[i] == 9 && s->depth == 8) {
if (EXTERNAL_SSE4(cpu_flags))
s->filter[i] = ff_filter_3x3_sse4;
}
}
}
#endif
}
av_cold void ff_sobel_init_x86(ConvolutionContext *s, int depth, int nb_planes)
{
#if ARCH_X86_64
int cpu_flags = av_get_cpu_flags();
for (int i = 0; i < nb_planes; i++) {
if (depth == 8) {
if (EXTERNAL_AVX512ICL(cpu_flags))
s->filter[i] = ff_filter_sobel_avx512icl;
}
}
#endif
}
+82
View File
@@ -0,0 +1,82 @@
;*****************************************************************************
;* x86-optimized functions for eq filter
;*
;* Original MPlayer filters by Richard Felker.
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg is free software; you can redistribute it and/or modify
;* it under the terms of the GNU General Public License as published by
;* the Free Software Foundation; either version 2 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 General Public License for more details.
;*
;* You should have received a copy of the GNU 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/x86/x86util.asm"
SECTION .text
INIT_XMM sse2
cglobal process_one_line, 5, 7, 5, src, dst, contrast, brightness, w
movd m3, contrastd
movd m4, brightnessd
movsx r5d, contrastw
movsx r6d, brightnessw
SPLATW m3, m3, 0
SPLATW m4, m4, 0
DEFINE_ARGS src, dst, tmp, scalar, w
xor tmpd, tmpd
pxor m0, m0
pxor m1, m1
mov scalard, wd
and scalard, mmsize-1
sar wd, 4
cmp wd, 1
jl .loop1
.loop0:
movu m1, [srcq]
mova m2, m1
punpcklbw m1, m0
punpckhbw m2, m0
psllw m1, 4
psllw m2, 4
pmulhw m1, m3
pmulhw m2, m3
paddw m1, m4
paddw m2, m4
packuswb m1, m2
movu [dstq], m1
add srcq, mmsize
add dstq, mmsize
sub wd, 1
cmp wd, 0
jne .loop0
.loop1:
cmp scalard, 0
je .end
movzx tmpd, byte [srcq]
imul tmpd, r5d
sar tmpd, 12
add tmpd, r6d
movd m1, tmpd
packuswb m1, m0
movd tmpd, m1
mov [dstq], tmpb
inc srcq
inc dstq
dec scalard
jmp .loop1
.end:
RET
+55
View File
@@ -0,0 +1,55 @@
/*
*
* Original MPlayer filters by Richard Felker.
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavfilter/vf_eq.h"
extern void ff_process_one_line_sse2(const uint8_t *src, uint8_t *dst, short contrast,
short brightness, int w);
#if HAVE_X86ASM
static void process_sse2(EQParameters *param, uint8_t *dst, int dst_stride,
const uint8_t *src, int src_stride, int w, int h)
{
short contrast = (short) (param->contrast * 256 * 16);
short brightness = ((short) (100.0 * param->brightness + 100.0) * 511)
/ 200 - 128 - contrast / 32;
while (h--) {
ff_process_one_line_sse2(src, dst, contrast, brightness, w);
src += src_stride;
dst += dst_stride;
}
}
#endif
av_cold void ff_eq_init_x86(EQContext *eq)
{
#if HAVE_X86ASM
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE2(cpu_flags)) {
eq->process = process_sse2;
}
#endif
}
+134
View File
@@ -0,0 +1,134 @@
;*****************************************************************************
;* x86-optimized functions for framerate filter
;*
;* Copyright (C) 2018 Marton Balint
;*
;* Based on vf_blend.asm, Copyright (C) 2015 Paul B Mahol
;*
;* 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/x86/x86util.asm"
SECTION .text
%macro XSPLAT 3
%if cpuflag(avx2)
vpbroadcast%3 %1, %2
%else
movd %1, %2
%ifidn %3, d
SPLATD %1
%else
SPLATW %1, %1
%endif
%endif
%endmacro
%macro BLEND_INIT 0-1
%if ARCH_X86_64
cglobal blend_frames%1, 6, 9, 5, src1, src1_linesize, src2, src2_linesize, dst, dst_linesize, width, end, x
mov widthd, dword widthm
%else
cglobal blend_frames%1, 5, 7, 5, src1, src1_linesize, src2, src2_linesize, dst, end, x
%define dst_linesizeq r5mp
%define widthq r6mp
%endif
mov endd, dword r7m
add src1q, widthq
add src2q, widthq
add dstq, widthq
neg widthq
%endmacro
%macro BLEND_LOOP 4
.nextrow:
mov xq, widthq
.loop:
movu m0, [src1q + xq]
movu m1, [src2q + xq]
SBUTTERFLY %1%2, 0, 1, 4 ; aAbBcCdD
; eEfFgGhH
pmadd%3 m0, m2
pmadd%3 m1, m2
padd%2 m0, m3
padd%2 m1, m3
psrl%2 m0, %4 ; 0A0B0C0D
psrl%2 m1, %4 ; 0E0F0G0H
packus%2%1 m0, m1 ; ABCDEFGH
movu [dstq + xq], m0
add xq, mmsize
jl .loop
add src1q, src1_linesizeq
add src2q, src2_linesizeq
add dstq, dst_linesizeq
sub endd, 1
jg .nextrow
RET
%endmacro
%macro BLEND_FRAMES 0
BLEND_INIT
XSPLAT m2, r8m, w ; factor1
XSPLAT m3, r9m, w ; factor2
psllw m3, 8
por m2, m3 ; interleaved factors
XSPLAT m3, r10m, w ; half
BLEND_LOOP b, w, ubsw, 7
%endmacro
%macro BLEND_FRAMES16 0
BLEND_INIT 16
XSPLAT m2, r8m, d ; factor1
XSPLAT m3, r9m, d ; factor2
pslld m3, 16
por m2, m3 ; interleaved factors
XSPLAT m3, r10m, d ; half
BLEND_LOOP w, d, wd, 15
%endmacro
INIT_XMM ssse3
BLEND_FRAMES
INIT_XMM sse4
BLEND_FRAMES16
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
BLEND_FRAMES
BLEND_FRAMES16
%endif
@@ -0,0 +1,42 @@
/*
* 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/framerate.h"
void ff_blend_frames_ssse3(BLEND_FUNC_PARAMS);
void ff_blend_frames_avx2(BLEND_FUNC_PARAMS);
void ff_blend_frames16_sse4(BLEND_FUNC_PARAMS);
void ff_blend_frames16_avx2(BLEND_FUNC_PARAMS);
void ff_framerate_init_x86(FrameRateContext *s)
{
int cpu_flags = av_get_cpu_flags();
if (s->bitdepth == 8) {
if (EXTERNAL_AVX2_FAST(cpu_flags))
s->blend = ff_blend_frames_avx2;
else if (EXTERNAL_SSSE3(cpu_flags))
s->blend = ff_blend_frames_ssse3;
} else {
if (EXTERNAL_AVX2_FAST(cpu_flags))
s->blend = ff_blend_frames16_avx2;
else if (EXTERNAL_SSE4(cpu_flags))
s->blend = ff_blend_frames16_sse4;
}
}
+727
View File
@@ -0,0 +1,727 @@
;*****************************************************************************
;* x86-optimized functions for fspp filter
;*
;* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
;* Copyright (C) 2005 Nikolaj Poroshin <porosh3@psu.ru>
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg is free software; you can redistribute it and/or modify
;* it under the terms of the GNU General Public License as published by
;* the Free Software Foundation; either version 2 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 General Public License for more details.
;*
;* You should have received a copy of the GNU 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/x86/x86util.asm"
SECTION_RODATA
pb_dither: db 0, 48, 12, 60, 3, 51, 15, 63, 32, 16, 44, 28, 35, 19, 47, 31, \
8, 56, 4, 52, 11, 59, 7, 55, 40, 24, 36, 20, 43, 27, 39, 23, \
2, 50, 14, 62, 1, 49, 13, 61, 34, 18, 46, 30, 33, 17, 45, 29, \
10, 58, 6, 54, 9, 57, 5, 53, 42, 26, 38, 22, 41, 25, 37, 21
pw_187E: times 4 dw 0x187E ; FIX64(0.382683433, 14)
pw_22A3: times 4 dw 0x22A3 ; FIX64(1.082392200, 13)
pw_2D41: times 4 dw 0x2D41 ; FIX64(1.414213562, 13)
pw_539F: times 4 dw 0x539F ; FIX64(1.306562965, 14)
pw_5A82: times 4 dw 0x5A82 ; FIX64(1.414213562, 14)
pw_3B21: times 4 dw 0x3B21 ; FIX64(1.847759065, 13)
pw_AC62: times 4 dw 0xAC62 ; FIX64(-2.613125930, 13)
pw_3642: times 4 dw 0x3642 ; FIX64(0.847759065, 14)
pw_2441: times 4 dw 0x2441 ; FIX64(0.566454497, 14)
pw_0CBB: times 4 dw 0x0CBB ; FIX64(0.198912367, 14)
pw_4: times 4 dw 4
pw_2: times 4 dw 2
SECTION .text
%define DCTSIZE 8
INIT_MMX mmx
;void ff_store_slice_mmx(uint8_t *dst, int16_t *src,
; ptrdiff_t dst_stride, ptrdiff_t src_stride,
; ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale)
%if ARCH_X86_64
cglobal store_slice, 7, 9, 0, dst, src, dst_stride, src_stride, width, dither_height, dither, tmp, tmp2
%else
cglobal store_slice, 2, 7, 0, dst, src, width, dither_height, dither, tmp, tmp2
%define dst_strideq r2m
%define src_strideq r3m
mov widthq, r4m
mov dither_heightq, r5m
mov ditherq, r6m ; log2_scale
%endif
add widthq, 7
mov tmpq, src_strideq
and widthq, ~7
sub dst_strideq, widthq
movd m5, ditherd ; log2_scale
xor ditherq, -1 ; log2_scale
mov tmp2q, tmpq
add ditherq, 7 ; log2_scale
neg tmpq
sub tmp2q, widthq
movd m2, ditherd ; log2_scale
add tmp2q, tmp2q
lea ditherq, [pb_dither]
mov src_strideq, tmp2q
shl tmpq, 4
lea dither_heightq, [ditherq+dither_heightq*8]
pxor m7, m7
.loop_height:
movq m3, [ditherq]
movq m4, m3
punpcklbw m3, m7
punpckhbw m4, m7
mov tmp2q, widthq
psraw m3, m5
psraw m4, m5
.loop_width:
movq [srcq+tmpq], m7
movq m0, [srcq]
movq m1, [srcq+8]
movq [srcq+tmpq+8], m7
paddw m0, m3
paddw m1, m4
movq [srcq], m7
psraw m0, m2
psraw m1, m2
movq [srcq+8], m7
packuswb m0, m1
add srcq, 16
movq [dstq], m0
add dstq, 8
sub tmp2q, 8
jg .loop_width
add srcq, src_strideq
add ditherq, 8
add dstq, dst_strideq
cmp ditherq, dither_heightq
jl .loop_height
RET
;void ff_store_slice2_mmx(uint8_t *dst, int16_t *src,
; ptrdiff_t dst_stride, ptrdiff_t src_stride,
; ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale)
%if ARCH_X86_64
cglobal store_slice2, 7, 9, 0, dst, src, dst_stride, src_stride, width, dither_height, dither, tmp, tmp2
%else
cglobal store_slice2, 0, 7, 0, dst, src, width, dither_height, dither, tmp, tmp2
%define dst_strideq r2m
%define src_strideq r3m
mov dstq, dstm
mov srcq, srcm
mov widthq, r4m
mov dither_heightq, r5m
mov ditherq, r6m ; log2_scale
%endif
add widthq, 7
mov tmpq, src_strideq
and widthq, ~7
sub dst_strideq, widthq
movd m5, ditherd ; log2_scale
xor ditherq, -1 ; log2_scale
mov tmp2q, tmpq
add ditherq, 7 ; log2_scale
sub tmp2q, widthq
movd m2, ditherd ; log2_scale
add tmp2q, tmp2q
lea ditherq, [pb_dither]
mov src_strideq, tmp2q
shl tmpq, 5
lea dither_heightq, [ditherq+dither_heightq*8]
pxor m7, m7
.loop_height:
movq m3, [ditherq]
movq m4, m3
punpcklbw m3, m7
punpckhbw m4, m7
mov tmp2q,widthq
psraw m3, m5
psraw m4, m5
.loop_width:
movq m0, [srcq]
movq m1, [srcq+8]
paddw m0, m3
paddw m0, [srcq+tmpq]
paddw m1, m4
movq m6, [srcq+tmpq+8]
movq [srcq+tmpq], m7
psraw m0, m2
paddw m1, m6
movq [srcq+tmpq+8], m7
psraw m1, m2
packuswb m0, m1
movq [dstq], m0
add srcq, 16
add dstq, 8
sub tmp2q, 8
jg .loop_width
add srcq, src_strideq
add ditherq, 8
add dstq, dst_strideq
cmp ditherq, dither_heightq
jl .loop_height
RET
;void ff_mul_thrmat_mmx(int16_t *thr_adr_noq, int16_t *thr_adr, int q);
cglobal mul_thrmat, 3, 3, 0, thrn, thr, q
movd m7, qd
movq m0, [thrnq]
punpcklwd m7, m7
movq m1, [thrnq+8]
punpckldq m7, m7
pmullw m0, m7
movq m2, [thrnq+8*2]
pmullw m1, m7
movq m3, [thrnq+8*3]
pmullw m2, m7
movq [thrq], m0
movq m4, [thrnq+8*4]
pmullw m3, m7
movq [thrq+8], m1
movq m5, [thrnq+8*5]
pmullw m4, m7
movq [thrq+8*2], m2
movq m6, [thrnq+8*6]
pmullw m5, m7
movq [thrq+8*3], m3
movq m0, [thrnq+8*7]
pmullw m6, m7
movq [thrq+8*4], m4
movq m1, [thrnq+8*7+8]
pmullw m0, m7
movq [thrq+8*5], m5
movq m2, [thrnq+8*7+8*2]
pmullw m1, m7
movq [thrq+8*6], m6
movq m3, [thrnq+8*7+8*3]
pmullw m2, m7
movq [thrq+8*7], m0
movq m4, [thrnq+8*7+8*4]
pmullw m3, m7
movq [thrq+8*7+8], m1
movq m5, [thrnq+8*7+8*5]
pmullw m4, m7
movq [thrq+8*7+8*2], m2
movq m6, [thrnq+8*7+8*6]
pmullw m5, m7
movq [thrq+8*7+8*3], m3
movq m0, [thrnq+14*8]
pmullw m6, m7
movq [thrq+8*7+8*4], m4
movq m1, [thrnq+14*8+8]
pmullw m0, m7
movq [thrq+8*7+8*5], m5
pmullw m1, m7
movq [thrq+8*7+8*6], m6
movq [thrq+14*8], m0
movq [thrq+14*8+8], m1
RET
%macro COLUMN_FDCT 1-3 0, 0
movq m1, [srcq+DCTSIZE*0*2]
movq m7, [srcq+DCTSIZE*3*2]
movq m0, m1
paddw m1, [srcq+DCTSIZE*7*2]
movq m3, m7
paddw m7, [srcq+DCTSIZE*4*2]
movq m5, m1
movq m6, [srcq+DCTSIZE*1*2]
psubw m1, m7
movq m2, [srcq+DCTSIZE*2*2]
movq m4, m6
paddw m6, [srcq+DCTSIZE*6*2]
paddw m5, m7
paddw m2, [srcq+DCTSIZE*5*2]
movq m7, m6
paddw m6, m2
psubw m7, m2
movq m2, m5
paddw m5, m6
psubw m2, m6
paddw m7, m1
movq m6, [thrq+4*16+%2]
psllw m7, 2
psubw m5, [thrq+%2]
psubw m2, m6
paddusw m5, [thrq+%2]
paddusw m2, m6
pmulhw m7, [pw_2D41]
paddw m5, [thrq+%2]
paddw m2, m6
psubusw m5, [thrq+%2]
psubusw m2, m6
paddw m5, [pw_2]
movq m6, m2
paddw m2, m5
psubw m5, m6
movq m6, m1
paddw m1, m7
psubw m1, [thrq+2*16+%2]
psubw m6, m7
movq m7, [thrq+6*16+%2]
psraw m5, 2
paddusw m1, [thrq+2*16+%2]
psubw m6, m7
paddw m1, [thrq+2*16+%2]
paddusw m6, m7
psubusw m1, [thrq+2*16+%2]
paddw m6, m7
psubw m3, [srcq+DCTSIZE*4*2]
psubusw m6, m7
movq m7, m1
psraw m2, 2
psubw m4, [srcq+DCTSIZE*6*2]
psubw m1, m6
psubw m0, [srcq+DCTSIZE*7*2]
paddw m6, m7
psraw m6, 2
movq m7, m2
pmulhw m1, [pw_5A82]
paddw m2, m6
movq [rsp], m2
psubw m7, m6
movq m2, [srcq+DCTSIZE*2*2]
psubw m1, m6
psubw m2, [srcq+DCTSIZE*5*2]
movq m6, m5
movq [rsp+8*3], m7
paddw m3, m2
paddw m2, m4
paddw m4, m0
movq m7, m3
psubw m3, m4
psllw m3, 2
psllw m7, 2
pmulhw m3, [pw_187E]
psllw m4, 2
pmulhw m7, [pw_22A3]
psllw m2, 2
pmulhw m4, [pw_539F]
paddw m5, m1
pmulhw m2, [pw_2D41]
psubw m6, m1
paddw m7, m3
movq [rsp+8], m5
paddw m4, m3
movq m3, [thrq+3*16+%2]
movq m1, m0
movq [rsp+8*2], m6
psubw m1, m2
paddw m0, m2
movq m5, m1
movq m2, [thrq+5*16+%2]
psubw m1, m7
paddw m5, m7
psubw m1, m3
movq m7, [thrq+16+%2]
psubw m5, m2
movq m6, m0
paddw m0, m4
paddusw m1, m3
psubw m6, m4
movq m4, [thrq+7*16+%2]
psubw m0, m7
psubw m6, m4
paddusw m5, m2
paddusw m6, m4
paddw m1, m3
paddw m5, m2
paddw m6, m4
psubusw m1, m3
psubusw m5, m2
psubusw m6, m4
movq m4, m1
por m4, m5
paddusw m0, m7
por m4, m6
paddw m0, m7
packssdw m4, m4
psubusw m0, m7
movd tmpd, m4
or tmpd, tmpd
jnz %1
movq m4, [rsp]
movq m1, m0
pmulhw m0, [pw_3642]
movq m2, m1
movq m5, [outq+DCTSIZE*0*2]
movq m3, m2
pmulhw m1, [pw_2441]
paddw m5, m4
movq m6, [rsp+8]
psraw m3, 2
pmulhw m2, [pw_0CBB]
psubw m4, m3
movq m7, [outq+DCTSIZE*1*2]
paddw m5, m3
movq [outq+DCTSIZE*7*2], m4
paddw m7, m6
movq m3, [rsp+8*2]
psubw m6, m0
movq m4, [outq+DCTSIZE*2*2]
paddw m7, m0
movq [outq], m5
paddw m4, m3
movq [outq+DCTSIZE*6*2], m6
psubw m3, m1
movq m5, [outq+DCTSIZE*5*2]
paddw m4, m1
movq m6, [outq+DCTSIZE*3*2]
paddw m5, m3
movq m0, [rsp+8*3]
add srcq, 8+%3
movq [outq+DCTSIZE*1*2], m7
paddw m6, m0
movq [outq+DCTSIZE*2*2], m4
psubw m0, m2
movq m7, [outq+DCTSIZE*4*2]
paddw m6, m2
movq [outq+DCTSIZE*5*2], m5
paddw m7, m0
movq [outq+DCTSIZE*3*2], m6
movq [outq+DCTSIZE*4*2], m7
add outq, 8+%3
%endmacro
%macro COLUMN_IDCT 0-1 0
movq m3, m5
psubw m5, m1
psllw m5, 1
paddw m3, m1
movq m2, m0
psubw m0, m6
movq m1, m5
psllw m0, 1
pmulhw m1, [pw_AC62]
paddw m5, m0
pmulhw m5, [pw_3B21]
paddw m2, m6
pmulhw m0, [pw_22A3]
movq m7, m2
movq m4, [rsp]
psubw m2, m3
psllw m2, 1
paddw m7, m3
pmulhw m2, [pw_2D41]
movq m6, m4
psraw m7, 2
paddw m4, [outq]
psubw m6, m7
movq m3, [rsp+8]
paddw m4, m7
movq [outq+DCTSIZE*7*2], m6
paddw m1, m5
movq [outq], m4
psubw m1, m7
movq m7, [rsp+8*2]
psubw m0, m5
movq m6, [rsp+8*3]
movq m5, m3
paddw m3, [outq+DCTSIZE*1*2]
psubw m5, m1
psubw m2, m1
paddw m3, m1
movq [outq+DCTSIZE*6*2], m5
movq m4, m7
paddw m7, [outq+DCTSIZE*2*2]
psubw m4, m2
paddw m4, [outq+DCTSIZE*5*2]
paddw m7, m2
movq [outq+DCTSIZE*1*2], m3
paddw m0, m2
movq [outq+DCTSIZE*2*2], m7
movq m1, m6
paddw m6, [outq+DCTSIZE*4*2]
psubw m1, m0
paddw m1, [outq+DCTSIZE*3*2]
paddw m6, m0
movq [outq+DCTSIZE*5*2], m4
add srcq, 8+%1
movq [outq+DCTSIZE*4*2], m6
movq [outq+DCTSIZE*3*2], m1
add outq, 8+%1
%endmacro
;void ff_column_fidct_mmx(int16_t *thr_adr, int16_t *data, int16_t *output, int cnt);
cglobal column_fidct, 4, 5, 0, 32, thr, src, out, cnt, tmp
.fdct1:
COLUMN_FDCT .idct1
jmp .fdct2
.idct1:
COLUMN_IDCT
.fdct2:
COLUMN_FDCT .idct2, 8, 16
sub cntd, 2
jg .fdct1
RET
.idct2:
COLUMN_IDCT 16
sub cntd, 2
jg .fdct1
RET
;void ff_row_idct_mmx(int16_t *workspace, int16_t *output_adr, ptrdiff_t output_stride, int cnt);
cglobal row_idct, 4, 5, 0, 16, src, dst, stride, cnt, stride3
add strideq, strideq
lea stride3q, [strideq+strideq*2]
.loop:
movq m0, [srcq+DCTSIZE*0*2]
movq m1, [srcq+DCTSIZE*1*2]
movq m4, m0
movq m2, [srcq+DCTSIZE*2*2]
punpcklwd m0, m1
movq m3, [srcq+DCTSIZE*3*2]
punpckhwd m4, m1
movq m7, m2
punpcklwd m2, m3
movq m6, m0
punpckldq m0, m2
punpckhdq m6, m2
movq m5, m0
punpckhwd m7, m3
psubw m0, m6
pmulhw m0, [pw_5A82]
movq m2, m4
punpckldq m4, m7
paddw m5, m6
punpckhdq m2, m7
movq m1, m4
psllw m0, 2
paddw m4, m2
movq m3, [srcq+DCTSIZE*0*2+8]
psubw m1, m2
movq m2, [srcq+DCTSIZE*1*2+8]
psubw m0, m5
movq m6, m4
paddw m4, m5
psubw m6, m5
movq m7, m1
movq m5, [srcq+DCTSIZE*2*2+8]
paddw m1, m0
movq [rsp], m4
movq m4, m3
movq [rsp+8], m6
punpcklwd m3, m2
movq m6, [srcq+DCTSIZE*3*2+8]
punpckhwd m4, m2
movq m2, m5
punpcklwd m5, m6
psubw m7, m0
punpckhwd m2, m6
movq m0, m3
punpckldq m3, m5
punpckhdq m0, m5
movq m5, m4
movq m6, m3
punpckldq m4, m2
psubw m3, m0
punpckhdq m5, m2
paddw m6, m0
movq m2, m4
movq m0, m3
psubw m4, m5
pmulhw m0, [pw_AC62]
paddw m3, m4
pmulhw m3, [pw_3B21]
paddw m2, m5
pmulhw m4, [pw_22A3]
movq m5, m2
psubw m2, m6
paddw m5, m6
pmulhw m2, [pw_2D41]
paddw m0, m3
psllw m0, 3
psubw m4, m3
movq m6, [rsp]
movq m3, m1
psllw m4, 3
psubw m0, m5
psllw m2, 3
paddw m1, m0
psubw m2, m0
psubw m3, m0
paddw m4, m2
movq m0, m7
paddw m7, m2
psubw m0, m2
movq m2, [pw_4]
psubw m6, m5
paddw m5, [rsp]
paddw m1, m2
paddw m5, m2
psraw m1, 3
paddw m7, m2
psraw m5, 3
paddw m5, [dstq]
psraw m7, 3
paddw m1, [dstq+strideq*1]
paddw m0, m2
paddw m7, [dstq+strideq*2]
paddw m3, m2
movq [dstq], m5
paddw m6, m2
movq [dstq+strideq*1], m1
psraw m0, 3
movq [dstq+strideq*2], m7
add dstq, stride3q
movq m5, [rsp+8]
psraw m3, 3
paddw m0, [dstq+strideq*2]
psubw m5, m4
paddw m3, [dstq+stride3q*1]
psraw m6, 3
paddw m4, [rsp+8]
paddw m5, m2
paddw m6, [dstq+strideq*4]
paddw m4, m2
movq [dstq+strideq*2], m0
psraw m5, 3
paddw m5, [dstq]
psraw m4, 3
paddw m4, [dstq+strideq*1]
add srcq, DCTSIZE*2*4
movq [dstq+stride3q*1], m3
movq [dstq+strideq*4], m6
movq [dstq], m5
movq [dstq+strideq*1], m4
sub dstq, stride3q
add dstq, 8
dec r3d
jnz .loop
RET
;void ff_row_fdct_mmx(int16_t *data, const uint8_t *pixels, ptrdiff_t line_size, int cnt);
cglobal row_fdct, 4, 5, 0, 16, src, pix, stride, cnt, stride3
lea stride3q, [strideq+strideq*2]
.loop:
movd m0, [pixq]
pxor m7, m7
movd m1, [pixq+strideq*1]
punpcklbw m0, m7
movd m2, [pixq+strideq*2]
punpcklbw m1, m7
punpcklbw m2, m7
add pixq,stride3q
movq m5, m0
movd m3, [pixq+strideq*4]
movq m6, m1
movd m4, [pixq+stride3q*1]
punpcklbw m3, m7
psubw m5, m3
punpcklbw m4, m7
paddw m0, m3
psubw m6, m4
movd m3, [pixq+strideq*2]
paddw m1, m4
movq [rsp], m5
punpcklbw m3, m7
movq [rsp+8], m6
movq m4, m2
movd m5, [pixq]
paddw m2, m3
movd m6, [pixq+strideq*1]
punpcklbw m5, m7
psubw m4, m3
punpcklbw m6, m7
movq m3, m5
paddw m5, m6
psubw m3, m6
movq m6, m0
movq m7, m1
psubw m0, m5
psubw m1, m2
paddw m7, m2
paddw m1, m0
movq m2, m7
psllw m1, 2
paddw m6, m5
pmulhw m1, [pw_2D41]
paddw m7, m6
psubw m6, m2
movq m5, m0
movq m2, m7
punpcklwd m7, m6
paddw m0, m1
punpckhwd m2, m6
psubw m5, m1
movq m6, m0
movq m1, [rsp+8]
punpcklwd m0, m5
punpckhwd m6, m5
movq m5, m0
punpckldq m0, m7
paddw m3, m4
punpckhdq m5, m7
movq m7, m6
movq [srcq+DCTSIZE*0*2], m0
punpckldq m6, m2
movq [srcq+DCTSIZE*1*2], m5
punpckhdq m7, m2
movq [srcq+DCTSIZE*2*2], m6
paddw m4, m1
movq [srcq+DCTSIZE*3*2], m7
psllw m3, 2
movq m2, [rsp]
psllw m4, 2
pmulhw m4, [pw_2D41]
paddw m1, m2
psllw m1, 2
movq m0, m3
pmulhw m0, [pw_22A3]
psubw m3, m1
pmulhw m3, [pw_187E]
movq m5, m2
pmulhw m1, [pw_539F]
psubw m2, m4
paddw m5, m4
movq m6, m2
paddw m0, m3
movq m7, m5
paddw m2, m0
psubw m6, m0
movq m4, m2
paddw m1, m3
punpcklwd m2, m6
paddw m5, m1
punpckhwd m4, m6
psubw m7, m1
movq m6, m5
punpcklwd m5, m7
punpckhwd m6, m7
movq m7, m2
punpckldq m2, m5
sub pixq, stride3q
punpckhdq m7, m5
movq m5, m4
movq [srcq+DCTSIZE*0*2+8], m2
punpckldq m4, m6
movq [srcq+DCTSIZE*1*2+8], m7
punpckhdq m5, m6
movq [srcq+DCTSIZE*2*2+8], m4
add pixq, 4
movq [srcq+DCTSIZE*3*2+8], m5
add srcq, DCTSIZE*4*2
dec cntd
jnz .loop
RET
+49
View File
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
* Copyright (C) 2005 Nikolaj Poroshin <porosh3@psu.ru>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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/x86/cpu.h"
#include "libavfilter/vf_fspp.h"
void ff_store_slice_mmx(uint8_t *dst, int16_t *src,
ptrdiff_t dst_stride, ptrdiff_t src_stride,
ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale);
void ff_store_slice2_mmx(uint8_t *dst, int16_t *src,
ptrdiff_t dst_stride, ptrdiff_t src_stride,
ptrdiff_t width, ptrdiff_t height, ptrdiff_t log2_scale);
void ff_mul_thrmat_mmx(int16_t *thr_adr_noq, int16_t *thr_adr, int q);
void ff_column_fidct_mmx(int16_t *thr_adr, int16_t *data, int16_t *output, int cnt);
void ff_row_idct_mmx(int16_t *workspace, int16_t *output_adr, ptrdiff_t output_stride, int cnt);
void ff_row_fdct_mmx(int16_t *data, const uint8_t *pixels, ptrdiff_t line_size, int cnt);
av_cold void ff_fspp_init_x86(FSPPContext *s)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_MMX(cpu_flags)) {
s->store_slice = ff_store_slice_mmx;
s->store_slice2 = ff_store_slice2_mmx;
s->mul_thrmat = ff_mul_thrmat_mmx;
s->column_fidct = ff_column_fidct_mmx;
s->row_idct = ff_row_idct_mmx;
s->row_fdct = ff_row_fdct_mmx;
}
}
+995
View File
@@ -0,0 +1,995 @@
;*****************************************************************************
;* x86-optimized functions for gblur filter
;*
;* 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/x86/x86util.asm"
SECTION .data
gblur_transpose_16x16_indices1: dq 2, 3, 0, 1, 6, 7, 4, 5
gblur_transpose_16x16_indices2: dq 1, 0, 3, 2, 5, 4, 7, 6
gblur_transpose_16x16_indices3: dd 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14
gblur_transpose_16x16_mask: dw 0xcc, 0x33, 0xaa, 0x55, 0xaaaa, 0x5555
gblur_vindex_width: dd 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
SECTION .text
%xdefine AVX2_MMSIZE 32
%xdefine AVX512_MMSIZE 64
%macro MOVSXDIFNIDN 1-*
%rep %0
movsxdifnidn %1q, %1d
%rotate 1
%endrep
%endmacro
%macro KXNOR 2-*
%if mmsize == AVX512_MMSIZE
kxnorw %2, %2, %2
%else
%if %0 == 3
mov %3, -1
%else
vpcmpeqd %1, %1, %1
%endif
%endif
%endmacro
%macro KMOVW 2-4
%if mmsize == AVX2_MMSIZE && %0 == 4
mova %1, %2
%elif mmsize == AVX512_MMSIZE
%if %0 == 4
%rotate 2
%endif
kmovw %1, %2
%endif
%endmacro
%macro PUSH_MASK 5
%if mmsize == AVX2_MMSIZE
%assign %%n mmsize/4
%assign %%i 0
%rep %%n
mov %4, %3
and %4, 1
neg %4
mov dword [%5 + %%i*4], %4
sar %3, 1
%assign %%i %%i+1
%endrep
movu %1, [%5]
%else
kmovd %2, %3
%endif
%endmacro
%macro VMASKMOVPS 4
%if mmsize == AVX2_MMSIZE
vpmaskmovd %1, %3, %2
%else
kmovw k7, %4
vmovups %1{k7}, %2
%endif
%endmacro
%macro VGATHERDPS 4
%if mmsize == AVX2_MMSIZE
vgatherdps %1, %2, %3
%else
vgatherdps %1{%4}, %2
%endif
%endmacro
%macro VSCATTERDPS128 7
%rep 4
mov %7, %6
and %7, 1
cmp %7, 0
je %%end_scatter
movss [%2 + %3*%4], xm%1
vpshufd m%1, m%1, 0x39
add %3, %5
sar %6, 1
%endrep
%%end_scatter:
%endmacro
; %1=register index
; %2=base address %3=vindex
; %4=scale %5=width
; %6=mask %7=tmp
; m15=reserved
%macro VSCATTERDPS256 7
mova m15, m%1
xor %3, %3
VSCATTERDPS128 15, %2, %3, %4, %5, %6, %7
vextractf128 xm15, m%1, 1
VSCATTERDPS128 15, %2, %3, %4, %5, %6, %7
%endmacro
; %1=base address %2=avx2 vindex
; %3=avx512 vindex %4=avx2 mask
; %5=avx512 mask %6=register index
; %7=width %8-*=tmp
%macro VSCATTERDPS 8-*
%if mmsize == AVX2_MMSIZE
%if %0 == 9
mov %9, %4
VSCATTERDPS256 %6, %1, %2, 4, %7, %9, %8
%else
VSCATTERDPS256 %6, %1, %2, 4, %7, %4, %8
%endif
%else
vscatterdps [%1 + %3*4]{%5}, m%6
%endif
%endmacro
%macro INIT_WORD_MASK 1-*
%assign %%i 0
%rep %0
kmovw %1, [gblur_transpose_16x16_mask + %%i * 2]
%assign %%i %%i+1
%rotate 1
%endrep
%endmacro
%macro INIT_INDICES 1-*
%assign %%i 1
%rep %0
movu %1, [gblur_transpose_16x16_indices %+ %%i]
%assign %%i %%i+1
%rotate 1
%endrep
%endmacro
%assign stack_offset 0
%macro PUSH_MM 1
%if mmsize == AVX2_MMSIZE
movu [rsp + stack_offset], %1
%assign stack_offset stack_offset+mmsize
%endif
%endmacro
%macro POP_MM 1
%if mmsize == AVX2_MMSIZE
%assign stack_offset stack_offset-mmsize
movu %1, [rsp + stack_offset]
%endif
%endmacro
%macro READ_LOCAL_BUFFER 1
%if mmsize == AVX512_MMSIZE
%assign %%i 19
%else
%assign %%i 9
%endif
%assign %%j %%i-1
%assign %%k %1-1
%xdefine %%m m %+ %%i
mova %%m, m3
FMULADD_PS %%m, %%m, m0, [localbufq + %%k * mmsize], %%m
%assign %%k %%k-1
%rep %1-1
%xdefine %%m m %+ %%j
mova %%m, m %+ %%i
FMULADD_PS %%m, %%m, m0, [localbufq + %%k * mmsize], %%m
%assign %%i %%i-1
%assign %%j %%j-1
%assign %%k %%k-1
%endrep
%if mmsize == AVX512_MMSIZE
mova m3, m %+ %%i
%endif
%endmacro
%macro FMADD_WRITE 4
FMULADD_PS %1, %1, %2, %3, %1
mova %4, %1
%endmacro
%macro WRITE_LOCAL_BUFFER_INTERNAL 8-16
%assign %%i 0
%rep %0
FMADD_WRITE m3, m0, m %+ %1, [localbufq + %%i * mmsize]
%assign %%i %%i+1
%rotate 1
%endrep
%endmacro
%macro GATHERPS 1
%if mmsize == AVX512_MMSIZE
%assign %%i 4
%else
%assign %%i 2
%endif
movu m %+ %%i, [ptrq]
mov strideq, widthq
%assign %%i %%i+1
%rep %1-2
movu m %+ %%i, [ptrq + strideq*4]
add strideq, widthq
%assign %%i %%i+1
%endrep
movu m %+ %%i, [ptrq + strideq*4]
%endmacro
%macro SCATTERPS_INTERNAL 8-16
movu [ptrq + strideq*0], m %+ %1
mov strideq, widthq
%rotate 1
%rep %0-2
movu [ptrq + strideq*4], m %+ %1
add strideq, widthq
%rotate 1
%endrep
movu [ptrq + strideq*4], m %+ %1
%endmacro
%macro BATCH_INSERT64X4 4-*
%assign %%imm8 %1
%rotate 1
%rep (%0-1)/3
vinserti64x4 m%1, m%2, ym%3, %%imm8
%rotate 3
%endrep
%endmacro
%macro BATCH_EXTRACT_INSERT 2-*
%assign %%imm8 %1
%rotate 1
%rep (%0-1)/2
vextractf64x4 ym%1, m%1, %%imm8
vextractf64x4 ym%2, m%2, %%imm8
vinserti64x4 m%1, m%1, ym%2, %%imm8
%rotate 2
%endrep
%endmacro
%macro BATCH_MOVE 2-*
%rep %0/2
mova m%1, m%2
%rotate 2
%endrep
%endmacro
%macro BATCH_PERMUTE 3-*
%xdefine %%decorator %1
%xdefine %%mask %2
%assign %%index %3
%rotate 3
%rep (%0-3)/2
vperm %+ %%decorator m%1{%%mask}, m %+ %%index, m%2
%rotate 2
%endrep
%endmacro
; input : m3-m19
; output: m8 m5 m9 m15 m16 m7 m17 m27 m24 m21 m25 m19 m12 m23 m13 m11
%macro TRANSPOSE_16X16_AVX512 0
BATCH_INSERT64X4 0x1, 20,4,12, 21,5,13, 22,6,14, 23,7,15
BATCH_INSERT64X4 0x1, 24,8,16, 25,9,17, 26,10,18, 27,11,19
BATCH_EXTRACT_INSERT 0x1, 4,12, 5,13, 6,14, 7,15
BATCH_EXTRACT_INSERT 0x1, 8,16, 9,17, 10,18, 11,19
BATCH_MOVE 12,20, 13,21, 14,22, 15,23
BATCH_PERMUTE q, k6, 28, 12,24, 13,25, 14,26, 15,27
BATCH_PERMUTE q, k5, 28, 24,20, 25,21, 26,22, 27,23
BATCH_MOVE 16,4, 17,5, 18,6, 19,7
BATCH_PERMUTE q, k6, 28, 16,8, 17,9, 18,10, 19,11
BATCH_PERMUTE q, k5, 28, 8,4, 9,5, 10,6, 11,7
BATCH_MOVE 4,12, 5,13, 6,24, 7,25
BATCH_MOVE 20,16, 21,17, 22,8, 23,9
BATCH_PERMUTE q, k4, 29, 4,14, 5,15, 6,26, 7,27
BATCH_PERMUTE q, k3, 29, 14,12, 15,13, 26,24, 27,25
BATCH_PERMUTE q, k4, 29, 20,18, 21,19, 22,10, 23,11
BATCH_PERMUTE q, k3, 29, 18,16, 19,17, 10,8, 11,9
BATCH_MOVE 8,4, 9,14, 16,6, 17,26
BATCH_MOVE 24,20, 25,18, 12,22, 13,10
BATCH_PERMUTE d, k2, 30, 8,5, 9,15, 16,7, 17,27
BATCH_PERMUTE d, k1, 30, 5,4, 15,14, 7,6, 27,26
BATCH_PERMUTE d, k2, 30, 24,21, 25,19, 12,23, 13,11
BATCH_PERMUTE d, k1, 30, 21,20, 19,18, 23,22, 11,10
%endmacro
%macro INSERT_UNPACK 8
vinsertf128 m%5, m%1, xm%3, 0x1
vinsertf128 m%6, m%2, xm%4, 0x1
vunpcklpd m%7, m%5, m%6
vunpckhpd m%8, m%5, m%6
%endmacro
%macro SHUFFLE 4
vshufps m%3, m%1, m%2, 0x88
vshufps m%4, m%1, m%2, 0xDD
mova m%1, m%3
mova m%2, m%4
%endmacro
%macro EXTRACT_INSERT_UNPACK 6
vextractf128 xm%1, m%1, 0x1
vextractf128 xm%2, m%2, 0x1
vinsertf128 m%3, m%3, xm%1, 0x0
vinsertf128 m%4, m%4, xm%2, 0x0
vunpcklpd m%5, m%3, m%4
vunpckhpd m%6, m%3, m%4
%endmacro
; Transpose 8x8 AVX2
; Limit the number ym# register to 16 for compatibility
; Used up registers instead of using stack memory
; Input: m2-m9
; Output: m12, m14, m13, m15, m8, m10, m9, m11
%macro TRANSPOSE_8X8_AVX2 0
INSERT_UNPACK 2, 3, 6, 7, 10, 11, 12, 13
INSERT_UNPACK 4, 5, 8, 9, 10, 11, 14, 15
SHUFFLE 12, 14, 10, 11
SHUFFLE 13, 15, 10, 11
EXTRACT_INSERT_UNPACK 4, 5, 8, 9, 10, 11
EXTRACT_INSERT_UNPACK 2, 3, 6, 7, 8, 9
SHUFFLE 8, 10, 6, 7
SHUFFLE 9, 11, 6, 7
%endmacro
%macro TRANSPOSE 0
%if cpuflag(avx512)
TRANSPOSE_16X16_AVX512
%elif cpuflag(avx2)
TRANSPOSE_8X8_AVX2
%endif
%endmacro
%macro WRITE_LOCAL_BUFFER 0
%if cpuflag(avx512)
WRITE_LOCAL_BUFFER_INTERNAL 8, 5, 9, 15, 16, 7, 17, 27, \
24, 21, 25, 19, 12, 23, 13, 11
%elif cpuflag(avx2)
WRITE_LOCAL_BUFFER_INTERNAL 12, 14, 13, 15, 8, 10, 9, 11
%endif
%endmacro
%macro SCATTERPS 0
%if cpuflag(avx512)
SCATTERPS_INTERNAL 8, 5, 9, 15, 16, 7, 17, 27, \
24, 21, 25, 19, 12, 23, 13, 11
%elif cpuflag(avx2)
SCATTERPS_INTERNAL 12, 14, 13, 15, 8, 10, 9, 11
%endif
%endmacro
%macro OPTIMIZED_LOOP_STEP 0
lea stepd, [stepsd - 1]
cmp stepd, 0
jle %%bscale_scalar
%%loop_step:
sub localbufq, mmsize
mulps m3, m1
movu [localbufq], m3
; Filter leftwards
lea xq, [widthq - 1]
%%loop_step_x_back:
sub localbufq, mmsize
FMULADD_PS m3, m3, m0, [localbufq], m3
movu [localbufq], m3
dec xq
cmp xq, 0
jg %%loop_step_x_back
; Filter rightwards
mulps m3, m1
movu [localbufq], m3
add localbufq, mmsize
lea xq, [widthq - 1]
%%loop_step_x:
FMULADD_PS m3, m3, m0, [localbufq], m3
movu [localbufq], m3
add localbufq, mmsize
dec xq
cmp xq, 0
jg %%loop_step_x
dec stepd
cmp stepd, 0
jg %%loop_step
%%bscale_scalar:
%endmacro
;***************************************************************************
; void ff_horiz_slice(float *ptr, int width, int height, int steps,
; float nu, float bscale)
;***************************************************************************
%macro HORIZ_SLICE 0
%if UNIX64
%if cpuflag(avx512) || cpuflag(avx2)
cglobal horiz_slice, 5, 12, mmnum, 0-mmsize*4, buffer, width, height, steps, \
localbuf, x, y, step, stride, remain, ptr, mask
%else
cglobal horiz_slice, 4, 9, 9, ptr, width, height, steps, x, y, step, stride, remain
%endif
%else
%if cpuflag(avx512) || cpuflag(avx2)
cglobal horiz_slice, 5, 12, mmnum, 0-mmsize*4, buffer, width, height, steps, nu, bscale, \
localbuf, x, y, step, stride, remain, ptr, mask
%else
cglobal horiz_slice, 4, 9, 9, ptr, width, height, steps, nu, bscale, x, y, step, stride, remain
%endif
%endif
%if cpuflag(avx512) || cpuflag(avx2)
%assign rows mmsize/4
%assign cols mmsize/4
%if WIN64
VBROADCASTSS m0, num ; nu
VBROADCASTSS m1, bscalem ; bscale
mov nuq, localbufm
DEFINE_ARGS buffer, width, height, steps, \
localbuf, x, y, step, stride, remain, ptr, mask
%else
VBROADCASTSS m0, xmm0 ; nu
VBROADCASTSS m1, xmm1 ; bscale
%endif
MOVSXDIFNIDN width, height, steps
%if cpuflag(avx512)
vpbroadcastd m2, widthd
INIT_WORD_MASK k6, k5, k4, k3, k2, k1
INIT_INDICES m28, m29, m30
%else
movd xm2, widthd
VBROADCASTSS m2, xm2
%endif
vpmulld m2, m2, [gblur_vindex_width] ; vindex width
xor yq, yq ; y = 0
xor xq, xq ; x = 0
cmp heightq, rows
jl .y_scalar
sub heightq, rows
.loop_y:
; ptr = buffer + y * width;
mov ptrq, yq
imul ptrq, widthq
lea ptrq, [bufferq + ptrq*4]
KXNOR m5, k7
VGATHERDPS m3, [ptrq + m2*4], m5, k7
mulps m3, m1
movu [localbufq], m3
add ptrq, 4
add localbufq, mmsize
; Filter rightwards
PUSH_MM m2
lea xq, [widthq - 1]
.loop_x:
PUSH_MM m3
GATHERPS cols
TRANSPOSE
POP_MM m3
WRITE_LOCAL_BUFFER
add ptrq, mmsize
add localbufq, rows * mmsize
sub xq, cols
cmp xq, cols
jge .loop_x
POP_MM m2
cmp xq, 0
jle .bscale_scalar
.loop_x_scalar:
KXNOR m5, k7
VGATHERDPS m4, [ptrq + m2*4], m5, k7
FMULADD_PS m3, m3, m0, m4, m3
movu [localbufq], m3
add ptrq, 0x4
add localbufq, mmsize
dec xq
cmp xq, 0
jg .loop_x_scalar
.bscale_scalar:
OPTIMIZED_LOOP_STEP
sub ptrq, 4
sub localbufq, mmsize
mulps m3, m1
KXNOR m5, k7, maskq
VSCATTERDPS ptrq, strideq, m2, maskq, k7, 3, widthq, remainq
; Filter leftwards
PUSH_MM m2
lea xq, [widthq - 1]
.loop_x_back:
sub localbufq, rows * mmsize
READ_LOCAL_BUFFER cols
PUSH_MM m2
TRANSPOSE
POP_MM m3
sub ptrq, mmsize
SCATTERPS
sub xq, cols
cmp xq, cols
jge .loop_x_back
POP_MM m2
cmp xq, 0
jle .end_loop_x
.loop_x_back_scalar:
sub ptrq, 0x4
sub localbufq, mmsize
FMULADD_PS m3, m3, m0, [localbufq], m3
KXNOR m5, k7, maskq
VSCATTERDPS ptrq, strideq, m2, maskq, k7, 3, widthq, remainq
dec xq
cmp xq, 0
jg .loop_x_back_scalar
.end_loop_x:
add yq, rows
cmp yq, heightq
jle .loop_y
add heightq, rows
cmp yq, heightq
jge .end_scalar
mov remainq, widthq
imul remainq, mmsize
add ptrq, remainq
.y_scalar:
mov remainq, heightq
sub remainq, yq
mov maskq, 1
shlx maskq, maskq, remainq
sub maskq, 1
mov remainq, maskq
PUSH_MASK m5, k1, remaind, xd, rsp + 0x20
mov ptrq, yq
imul ptrq, widthq
lea ptrq, [bufferq + ptrq * 4] ; ptrq = buffer + y * width
KMOVW m6, m5, k7, k1
VGATHERDPS m3, [ptrq + m2 * 4], m6, k7
mulps m3, m1 ; p0 *= bscale
movu [localbufq], m3
add localbufq, mmsize
; Filter rightwards
lea xq, [widthq - 1]
.y_scalar_loop_x:
add ptrq, 4
KMOVW m6, m5, k7, k1
VGATHERDPS m4, [ptrq + m2 * 4], m6, k7
FMULADD_PS m3, m3, m0, m4, m3
movu [localbufq], m3
add localbufq, mmsize
dec xq
cmp xq, 0
jg .y_scalar_loop_x
OPTIMIZED_LOOP_STEP
sub localbufq, mmsize
mulps m3, m1 ; p0 *= bscale
KMOVW k7, k1
VSCATTERDPS ptrq, strideq, m2, maskq, k7, 3, widthq, remainq, heightq
; Filter leftwards
lea xq, [widthq - 1]
.y_scalar_loop_x_back:
sub ptrq, 4
sub localbufq, mmsize
FMULADD_PS m3, m3, m0, [localbufq], m3
KMOVW k7, k1
VSCATTERDPS ptrq, strideq, m2, maskq, k7, 3, widthq, remainq, heightq
dec xq
cmp xq, 0
jg .y_scalar_loop_x_back
.end_scalar:
RET
%else
%if WIN64
movss m0, num
movss m1, bscalem
DEFINE_ARGS ptr, width, height, steps, x, y, step, stride, remain
%endif
movsxdifnidn widthq, widthd
mulss m2, m0, m0 ; nu ^ 2
mulss m3, m2, m0 ; nu ^ 3
mulss m4, m3, m0 ; nu ^ 4
xor xq, xq
xor yd, yd
mov strideq, widthq
; stride = width * 4
shl strideq, 2
; w = w - ((w - 1) & 3)
mov remainq, widthq
sub remainq, 1
and remainq, 3
sub widthq, remainq
shufps m0, m0, 0
shufps m2, m2, 0
shufps m3, m3, 0
shufps m4, m4, 0
.loop_y:
xor stepd, stepd
.loop_step:
; p0 *= bscale
mulss m5, m1, [ptrq + xq * 4]
movss [ptrq + xq * 4], m5
inc xq
; filter rightwards
; Here we are vectorizing the c version by 4
; for (x = 1; x < width; x++)
; ptr[x] += nu * ptr[x - 1];
; let p0 stands for ptr[x-1], the data from last loop
; and [p1,p2,p3,p4] be the vector data for this loop.
; Unrolling the loop, we get:
; p1' = p1 + p0*nu
; p2' = p2 + p1*nu + p0*nu^2
; p3' = p3 + p2*nu + p1*nu^2 + p0*nu^3
; p4' = p4 + p3*nu + p2*nu^2 + p1*nu^3 + p0*nu^4
; so we can do it in simd:
; [p1',p2',p3',p4'] = [p1,p2,p3,p4] + [p0,p1,p2,p3]*nu +
; [0,p0,p1,p2]*nu^2 + [0,0,p0,p1]*nu^3 +
; [0,0,0,p0]*nu^4
.loop_x:
movu m6, [ptrq + xq * 4] ; s = [p1,p2,p3,p4]
pslldq m7, m6, 4 ; [0, p1,p2,p3]
movss m7, m5 ; [p0,p1,p2,p3]
FMULADD_PS m6, m7, m0, m6, m8 ; s += [p0,p1,p2,p3] * nu
pslldq m7, 4 ; [0,p0,p1,p2]
FMULADD_PS m6, m7, m2, m6, m8 ; s += [0,p0,p1,p2] * nu^2
pslldq m7, 4
FMULADD_PS m6, m7, m3, m6, m8 ; s += [0,0,p0,p1] * nu^3
pslldq m7, 4
FMULADD_PS m6, m7, m4, m6, m8 ; s += [0,0,0,p0] * nu^4
movu [ptrq + xq * 4], m6
shufps m5, m6, m6, q3333
add xq, 4
cmp xq, widthq
jl .loop_x
add widthq, remainq
cmp xq, widthq
jge .end_scalar
.loop_scalar:
; ptr[x] += nu * ptr[x-1]
movss m5, [ptrq + 4*xq - 4]
mulss m5, m0
addss m5, [ptrq + 4*xq]
movss [ptrq + 4*xq], m5
inc xq
cmp xq, widthq
jl .loop_scalar
.end_scalar:
; ptr[width - 1] *= bscale
dec xq
mulss m5, m1, [ptrq + 4*xq]
movss [ptrq + 4*xq], m5
shufps m5, m5, 0
; filter leftwards
; for (; x > 0; x--)
; ptr[x - 1] += nu * ptr[x];
; The idea here is basically the same as filter rightwards.
; But we need to take care as the data layout is different.
; Let p0 stands for the ptr[x], which is the data from last loop.
; The way we do it in simd as below:
; [p-4', p-3', p-2', p-1'] = [p-4, p-3, p-2, p-1]
; + [p-3, p-2, p-1, p0] * nu
; + [p-2, p-1, p0, 0] * nu^2
; + [p-1, p0, 0, 0] * nu^3
; + [p0, 0, 0, 0] * nu^4
.loop_x_back:
sub xq, 4
movu m6, [ptrq + xq * 4] ; s = [p-4, p-3, p-2, p-1]
psrldq m7, m6, 4 ; [p-3, p-2, p-1, 0 ]
blendps m7, m5, 0x8 ; [p-3, p-2, p-1, p0 ]
FMULADD_PS m6, m7, m0, m6, m8 ; s+= [p-3, p-2, p-1, p0 ] * nu
psrldq m7, 4 ;
FMULADD_PS m6, m7, m2, m6, m8 ; s+= [p-2, p-1, p0, 0] * nu^2
psrldq m7, 4
FMULADD_PS m6, m7, m3, m6, m8 ; s+= [p-1, p0, 0, 0] * nu^3
psrldq m7, 4
FMULADD_PS m6, m7, m4, m6, m8 ; s+= [p0, 0, 0, 0] * nu^4
movu [ptrq + xq * 4], m6
shufps m5, m6, m6, 0 ; m5 = [p-4', p-4', p-4', p-4']
cmp xq, remainq
jg .loop_x_back
cmp xq, 0
jle .end_scalar_back
.loop_scalar_back:
; ptr[x-1] += nu * ptr[x]
movss m5, [ptrq + 4*xq]
mulss m5, m0
addss m5, [ptrq + 4*xq - 4]
movss [ptrq + 4*xq - 4], m5
dec xq
cmp xq, 0
jg .loop_scalar_back
.end_scalar_back:
; reset aligned width for next line
sub widthq, remainq
inc stepd
cmp stepd, stepsd
jl .loop_step
add ptrq, strideq
inc yd
cmp yd, heightd
jl .loop_y
RET
%endif
%endmacro
%if ARCH_X86_64
INIT_XMM sse4
HORIZ_SLICE
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
%xdefine mmnum 16
HORIZ_SLICE
%endif
%if HAVE_AVX512_EXTERNAL
INIT_ZMM avx512
%xdefine mmnum 32
HORIZ_SLICE
%endif
%endif
%macro POSTSCALE_SLICE 0
cglobal postscale_slice, 2, 2, 4, ptr, length, postscale, min, max
shl lengthd, 2
add ptrq, lengthq
neg lengthq
%if ARCH_X86_32
VBROADCASTSS m0, postscalem
VBROADCASTSS m1, minm
VBROADCASTSS m2, maxm
%elif WIN64
VBROADCASTSS m0, xmm2
VBROADCASTSS m1, xmm3
VBROADCASTSS m2, maxm
%else ; UNIX
VBROADCASTSS m0, xmm0
VBROADCASTSS m1, xmm1
VBROADCASTSS m2, xmm2
%endif
.loop:
%if cpuflag(avx2) || cpuflag(avx512)
mulps m3, m0, [ptrq + lengthq]
%else
movu m3, [ptrq + lengthq]
mulps m3, m0
%endif
maxps m3, m1
minps m3, m2
movu [ptrq+lengthq], m3
add lengthq, mmsize
jl .loop
RET
%endmacro
INIT_XMM sse
POSTSCALE_SLICE
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
POSTSCALE_SLICE
%endif
%if HAVE_AVX512_EXTERNAL
INIT_ZMM avx512
POSTSCALE_SLICE
%endif
;*******************************************************************************
; void ff_verti_slice(float *buffer, int width, int height, int column_begin,
; int column_end, int steps, float nu, float bscale);
;*******************************************************************************
%macro VERTI_SLICE 0
%if UNIX64
cglobal verti_slice, 6, 12, 9, 0-mmsize*2, buffer, width, height, cbegin, cend, \
steps, x, y, cwidth, step, ptr, stride
%else
cglobal verti_slice, 6, 12, 9, 0-mmsize*2, buffer, width, height, cbegin, cend, \
steps, nu, bscale, x, y, cwidth, step, \
ptr, stride
%endif
%assign cols mmsize/4
%if WIN64
VBROADCASTSS m0, num
VBROADCASTSS m1, bscalem
DEFINE_ARGS buffer, width, height, cbegin, cend, \
steps, x, y, cwidth, step, ptr, stride
%else
VBROADCASTSS m0, xmm0 ; nu
VBROADCASTSS m1, xmm1 ; bscale
%endif
MOVSXDIFNIDN width, height, cbegin, cend, steps
mov cwidthq, cendq
sub cwidthq, cbeginq
lea strideq, [widthq * 4]
xor xq, xq ; x = 0
cmp cwidthq, cols
jl .x_scalar
cmp cwidthq, 0x0
je .end_scalar
sub cwidthq, cols
.loop_x:
xor stepq, stepq
.loop_step:
; ptr = buffer + x + column_begin;
lea ptrq, [xq + cbeginq]
lea ptrq, [bufferq + ptrq*4]
; ptr[15:0] *= bcale;
movu m2, [ptrq]
mulps m2, m1
movu [ptrq], m2
; Filter downwards
mov yq, 1
.loop_y_down:
add ptrq, strideq ; ptrq += width
movu m3, [ptrq]
FMULADD_PS m2, m2, m0, m3, m2
movu [ptrq], m2
inc yq
cmp yq, heightq
jl .loop_y_down
mulps m2, m1
movu [ptrq], m2
; Filter upwards
dec yq
.loop_y_up:
sub ptrq, strideq
movu m3, [ptrq]
FMULADD_PS m2, m2, m0, m3, m2
movu [ptrq], m2
dec yq
cmp yq, 0
jg .loop_y_up
inc stepq
cmp stepq, stepsq
jl .loop_step
add xq, cols
cmp xq, cwidthq
jle .loop_x
add cwidthq, cols
cmp xq, cwidthq
jge .end_scalar
.x_scalar:
xor stepq, stepq
mov qword [rsp + 0x10], xq
sub cwidthq, xq
mov xq, 1
shlx cwidthq, xq, cwidthq
sub cwidthq, 1
PUSH_MASK m4, k1, cwidthd, xd, rsp + 0x20
mov xq, qword [rsp + 0x10]
.loop_step_scalar:
lea ptrq, [xq + cbeginq]
lea ptrq, [bufferq + ptrq*4]
VMASKMOVPS m2, [ptrq], m4, k1
mulps m2, m1
VMASKMOVPS [ptrq], m2, m4, k1
; Filter downwards
mov yq, 1
.x_scalar_loop_y_down:
add ptrq, strideq
VMASKMOVPS m3, [ptrq], m4, k1
FMULADD_PS m2, m2, m0, m3, m2
VMASKMOVPS [ptrq], m2, m4, k1
inc yq
cmp yq, heightq
jl .x_scalar_loop_y_down
mulps m2, m1
VMASKMOVPS [ptrq], m2, m4, k1
; Filter upwards
dec yq
.x_scalar_loop_y_up:
sub ptrq, strideq
VMASKMOVPS m3, [ptrq], m4, k1
FMULADD_PS m2, m2, m0, m3, m2
VMASKMOVPS [ptrq], m2, m4, k1
dec yq
cmp yq, 0
jg .x_scalar_loop_y_up
inc stepq
cmp stepq, stepsq
jl .loop_step_scalar
.end_scalar:
RET
%endmacro
%if ARCH_X86_64
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
VERTI_SLICE
%endif
%if HAVE_AVX512_EXTERNAL
INIT_ZMM avx512
VERTI_SLICE
%endif
%endif
+74
View File
@@ -0,0 +1,74 @@
/*
*
* 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 "config.h"
#include "libavutil/attributes.h"
#include "libavutil/cpu.h"
#include "libavutil/mem.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/gblur.h"
void ff_horiz_slice_sse4(float *ptr, int width, int height, int steps, float nu, float bscale, float *localbuf);
void ff_horiz_slice_avx2(float *ptr, int width, int height, int steps, float nu, float bscale, float *localbuf);
void ff_horiz_slice_avx512(float *ptr, int width, int height, int steps, float nu, float bscale, float *localbuf);
void ff_postscale_slice_sse(float *ptr, int length, float postscale, float min, float max);
void ff_postscale_slice_avx2(float *ptr, int length, float postscale, float min, float max);
void ff_postscale_slice_avx512(float *ptr, int length, float postscale, float min, float max);
void ff_verti_slice_avx2(float *buffer, int width, int height, int column_begin, int column_end,
int steps, float nu, float bscale);
void ff_verti_slice_avx512(float *buffer, int width, int height, int column_begin, int column_end,
int steps, float nu, float bscale);
av_cold void ff_gblur_init_x86(GBlurContext *s)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE(cpu_flags)) {
s->postscale_slice = ff_postscale_slice_sse;
}
if (EXTERNAL_AVX2_FAST(cpu_flags)) {
s->postscale_slice = ff_postscale_slice_avx2;
}
#if ARCH_X86_64
if (EXTERNAL_SSE4(cpu_flags)) {
s->horiz_slice = ff_horiz_slice_sse4;
}
if (EXTERNAL_AVX2(cpu_flags)) {
s->verti_slice = ff_verti_slice_avx2;
}
if (EXTERNAL_AVX512(cpu_flags)) {
s->postscale_slice = ff_postscale_slice_avx512;
s->verti_slice = ff_verti_slice_avx512;
}
if (EXTERNAL_AVX2(cpu_flags)) {
s->stride = EXTERNAL_AVX512(cpu_flags) ? 16 : 8;
s->localbuf = av_malloc(s->stride * sizeof(float) * s->planewidth[0] * s->planeheight[0]);
if (!s->localbuf)
return;
s->horiz_slice = ff_horiz_slice_avx2;
if (EXTERNAL_AVX512(cpu_flags)) {
s->horiz_slice = ff_horiz_slice_avx512;
}
}
#endif
}
+110
View File
@@ -0,0 +1,110 @@
;******************************************************************************
;* x86-optimized functions for gradfun filter
;*
;* 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/x86/x86util.asm"
SECTION_RODATA
pw_7f: times 8 dw 0x7F
pw_ff: times 8 dw 0xFF
SECTION .text
%macro FILTER_LINE 1
movh m0, [r2+r0]
movh m1, [r3+r0]
punpcklbw m0, m7
punpcklwd m1, m1
psllw m0, 7
psubw m1, m0
PABSW m2, m1
pmulhuw m2, m5
psubw m2, m6
pminsw m2, m7
pmullw m2, m2
psllw m1, 2
paddw m0, %1
pmulhw m1, m2
paddw m0, m1
psraw m0, 7
packuswb m0, m0
movh [r1+r0], m0
%endmacro
INIT_MMX mmxext
cglobal gradfun_filter_line, 6, 6
movh m5, r4d
pxor m7, m7
pshufw m5, m5,0
mova m6, [pw_7f]
mova m3, [r5]
mova m4, [r5+8]
.loop:
FILTER_LINE m3
add r0, 4
jge .end
FILTER_LINE m4
add r0, 4
jl .loop
.end:
RET
INIT_XMM ssse3
cglobal gradfun_filter_line, 6, 6, 8
movd m5, r4d
pxor m7, m7
pshuflw m5, m5, 0
mova m6, [pw_7f]
punpcklqdq m5, m5
mova m4, [r5]
.loop:
FILTER_LINE m4
add r0, 8
jl .loop
RET
%macro BLUR_LINE 1
cglobal gradfun_blur_line_%1, 6, 6, 8
mova m7, [pw_ff]
.loop:
%1 m0, [r4+r0]
%1 m1, [r5+r0]
mova m2, m0
mova m3, m1
psrlw m0, 8
psrlw m1, 8
pand m2, m7
pand m3, m7
paddw m0, m1
paddw m2, m3
paddw m0, m2
paddw m0, [r2+r0]
mova m1, [r1+r0]
mova [r1+r0], m0
psubw m0, m1
mova [r3+r0], m0
add r0, 16
jl .loop
RET
%endmacro
INIT_XMM sse2
BLUR_LINE movdqa
BLUR_LINE movdqu
+104
View File
@@ -0,0 +1,104 @@
/*
* Copyright (C) 2009 Loren Merritt <lorenm@u.washington.edu>
*
* 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 "config.h"
#include "libavutil/attributes.h"
#include "libavutil/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/gradfun.h"
void ff_gradfun_filter_line_mmxext(intptr_t x, uint8_t *dst, const uint8_t *src,
const uint16_t *dc, int thresh,
const uint16_t *dithers);
void ff_gradfun_filter_line_ssse3(intptr_t x, uint8_t *dst, const uint8_t *src,
const uint16_t *dc, int thresh,
const uint16_t *dithers);
void ff_gradfun_blur_line_movdqa_sse2(intptr_t x, uint16_t *buf,
const uint16_t *buf1, uint16_t *dc,
const uint8_t *src1, const uint8_t *src2);
void ff_gradfun_blur_line_movdqu_sse2(intptr_t x, uint16_t *buf,
const uint16_t *buf1, uint16_t *dc,
const uint8_t *src1, const uint8_t *src2);
#if HAVE_X86ASM
static void gradfun_filter_line_mmxext(uint8_t *dst, const uint8_t *src,
const uint16_t *dc,
int width, int thresh,
const uint16_t *dithers)
{
intptr_t x;
if (width & 3) {
x = width & ~3;
ff_gradfun_filter_line_c(dst + x, src + x, dc + x / 2,
width - x, thresh, dithers);
width = x;
}
x = -width;
ff_gradfun_filter_line_mmxext(x, dst + width, src + width, dc + width / 2,
thresh, dithers);
}
static void gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16_t *dc,
int width, int thresh,
const uint16_t *dithers)
{
intptr_t x;
if (width & 7) {
// could be 10% faster if I somehow eliminated this
x = width & ~7;
ff_gradfun_filter_line_c(dst + x, src + x, dc + x / 2,
width - x, thresh, dithers);
width = x;
}
x = -width;
ff_gradfun_filter_line_ssse3(x, dst + width, src + width, dc + width / 2,
thresh, dithers);
}
static void gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1,
const uint8_t *src, int src_linesize, int width)
{
intptr_t x = -2 * width;
if (((intptr_t) src | src_linesize) & 15)
ff_gradfun_blur_line_movdqu_sse2(x, buf + width, buf1 + width,
dc + width, src + width * 2,
src + width * 2 + src_linesize);
else
ff_gradfun_blur_line_movdqa_sse2(x, buf + width, buf1 + width,
dc + width, src + width * 2,
src + width * 2 + src_linesize);
}
#endif /* HAVE_X86ASM */
av_cold void ff_gradfun_init_x86(GradFunContext *gf)
{
#if HAVE_X86ASM
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_MMXEXT(cpu_flags))
gf->filter_line = gradfun_filter_line_mmxext;
if (EXTERNAL_SSSE3(cpu_flags))
gf->filter_line = gradfun_filter_line_ssse3;
if (EXTERNAL_SSE2(cpu_flags))
gf->blur_line = gradfun_blur_line_sse2;
#endif /* HAVE_X86ASM */
}
+90
View File
@@ -0,0 +1,90 @@
;*****************************************************************************
;* x86-optimized functions for hflip filter
;*
;* Copyright (C) 2017 Paul B Mahol
;*
;* 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/x86/x86util.asm"
SECTION_RODATA
pb_flip_byte: db 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
pb_flip_short: db 14,15,12,13,10,11,8,9,6,7,4,5,2,3,0,1
SECTION .text
;%1 byte or short, %2 b or w, %3 size in byte (1 for byte, 2 for short)
%macro HFLIP 3
cglobal hflip_%1, 3, 5, 3, src, dst, w, r, x
VBROADCASTI128 m0, [pb_flip_%1]
xor xq, xq
%if %3 == 1
movsxdifnidn wq, wd
%else ; short
add wd, wd
%endif
mov rq, wq
and rq, 2 * mmsize - 1
cmp wq, 2 * mmsize
jl .loop1
sub wq, rq
.loop0:
neg xq
%if mmsize == 32
vpermq m1, [srcq + xq - mmsize + %3], 0x4e; flip each lane at load
vpermq m2, [srcq + xq - 2 * mmsize + %3], 0x4e; flip each lane at load
%else
movu m1, [srcq + xq - mmsize + %3]
movu m2, [srcq + xq - 2 * mmsize + %3]
%endif
pshufb m1, m0
pshufb m2, m0
neg xq
movu [dstq + xq ], m1
movu [dstq + xq + mmsize], m2
add xq, mmsize * 2
cmp xq, wq
jl .loop0
cmp rq, 0
je .end
add wq, rq
.loop1:
neg xq
mov r%2, [srcq + xq]
neg xq
mov [dstq + xq], r%2
add xq, %3
cmp xq, wq
jl .loop1
.end:
RET
%endmacro
INIT_XMM ssse3
HFLIP byte, b, 1
HFLIP short, w, 2
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
HFLIP byte, b, 1
HFLIP short, w, 2
%endif
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2017 Paul B Mahol
*
* 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/hflip.h"
void ff_hflip_byte_ssse3(const uint8_t *src, uint8_t *dst, int w);
void ff_hflip_byte_avx2(const uint8_t *src, uint8_t *dst, int w);
void ff_hflip_short_ssse3(const uint8_t *src, uint8_t *dst, int w);
void ff_hflip_short_avx2(const uint8_t *src, uint8_t *dst, int w);
av_cold void ff_hflip_init_x86(FlipContext *s, int step[4], int nb_planes)
{
int cpu_flags = av_get_cpu_flags();
int i;
for (i = 0; i < nb_planes; i++) {
if (step[i] == 1) {
if (EXTERNAL_SSSE3(cpu_flags)) {
s->flip_line[i] = ff_hflip_byte_ssse3;
}
if (EXTERNAL_AVX2_FAST(cpu_flags)) {
s->flip_line[i] = ff_hflip_byte_avx2;
}
} else if (step[i] == 2) {
if (EXTERNAL_SSSE3(cpu_flags)) {
s->flip_line[i] = ff_hflip_short_ssse3;
}
if (EXTERNAL_AVX2_FAST(cpu_flags)) {
s->flip_line[i] = ff_hflip_short_avx2;
}
}
}
}
+106
View File
@@ -0,0 +1,106 @@
;******************************************************************************
;* Copyright (c) 2012 Loren Merritt
;*
;* 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/x86/x86util.asm"
SECTION .text
%macro LOWPASS 3 ; prevsample, cursample, lut
sub %1q, %2q
%if lut_bits != 8
sar %1q, 8-lut_bits
%endif
movsx %1q, word [%3q+%1q*2]
add %1q, %2q
%endmacro
%macro LOAD 3 ; dstreg, x, bitdepth
%if %3 == 8
movzx %1, byte [srcq+%2]
%else
movzx %1, word [srcq+(%2)*2]
%endif
%if %3 != 16
shl %1, 16-%3
add %1, (1<<(15-%3))-1
%endif
%endmacro
%macro HQDN3D_ROW 1 ; bitdepth
%if ARCH_X86_64
cglobal hqdn3d_row_%1_x86, 7,10,0, src, dst, lineant, frameant, width, spatial, temporal, pixelant, t0, t1
%else
cglobal hqdn3d_row_%1_x86, 7,7,0, src, dst, lineant, frameant, width, spatial, temporal
%endif
%assign bytedepth (%1+7)>>3
%assign lut_bits 4+4*(%1/16)
dec widthq
lea srcq, [srcq+widthq*bytedepth]
lea dstq, [dstq+widthq*bytedepth]
lea frameantq, [frameantq+widthq*2]
lea lineantq, [lineantq+widthq*2]
neg widthq
%define xq widthq
%if ARCH_X86_32
mov dstmp, dstq
mov srcmp, srcq
mov frameantmp, frameantq
mov lineantmp, lineantq
%define dstq r0
%define frameantq r0
%define lineantq r0
%define pixelantq r1
%define pixelantd r1d
DECLARE_REG_TMP 2,3
%endif
LOAD pixelantd, xq, %1
ALIGN 16
.loop:
movifnidn srcq, srcmp
LOAD t0d, xq+1, %1 ; skip on the last iteration to avoid overread
.loop2:
movifnidn lineantq, lineantmp
movzx t1d, word [lineantq+xq*2]
LOWPASS t1, pixelant, spatial
mov [lineantq+xq*2], t1w
LOWPASS pixelant, t0, spatial
movifnidn frameantq, frameantmp
movzx t0d, word [frameantq+xq*2]
LOWPASS t0, t1, temporal
mov [frameantq+xq*2], t0w
movifnidn dstq, dstmp
%if %1 != 16
shr t0d, 16-%1 ; could eliminate this by storing from t0h, but only with some contraints on register allocation
%endif
%if %1 == 8
mov [dstq+xq], t0b
%else
mov [dstq+xq*2], t0w
%endif
inc xq
jl .loop
je .loop2
RET
%endmacro ; HQDN3D_ROW
HQDN3D_ROW 8
HQDN3D_ROW 9
HQDN3D_ROW 10
HQDN3D_ROW 16
+49
View File
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2012 Loren Merritt
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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 <stddef.h>
#include <stdint.h>
#include "libavutil/attributes.h"
#include "libavfilter/vf_hqdn3d.h"
#include "config.h"
void ff_hqdn3d_row_8_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant,
uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial,
int16_t *temporal);
void ff_hqdn3d_row_9_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant,
uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial,
int16_t *temporal);
void ff_hqdn3d_row_10_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant,
uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial,
int16_t *temporal);
void ff_hqdn3d_row_16_x86(uint8_t *src, uint8_t *dst, uint16_t *line_ant,
uint16_t *frame_ant, ptrdiff_t w, int16_t *spatial,
int16_t *temporal);
av_cold void ff_hqdn3d_init_x86(HQDN3DContext *hqdn3d)
{
#if HAVE_X86ASM
hqdn3d->denoise_row[8] = ff_hqdn3d_row_8_x86;
hqdn3d->denoise_row[9] = ff_hqdn3d_row_9_x86;
hqdn3d->denoise_row[10] = ff_hqdn3d_row_10_x86;
hqdn3d->denoise_row[16] = ff_hqdn3d_row_16_x86;
#endif /* HAVE_X86ASM */
}
+112
View File
@@ -0,0 +1,112 @@
;*****************************************************************************
;* x86-optimized functions for idet filter
;*
;* Copyright (C) 2014 Pascal Massimino (pascal.massimino@gmail.com)
;* Copyright (c) 2014 Neil Birkbeck (birkbeck@google.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/x86/x86util.asm"
SECTION .text
;******************************************************************************
; 16bit implementation that does 4/8-pixels at a time
%macro PABS_DIFF_WD 3 ; a, b, junk , output=a
psubusw %3, %2, %1
psubusw %1, %2
por %1, %3
mova %2, %1
punpcklwd %1, m_zero
punpckhwd %2, m_zero
paddd %1, %2
%endmacro
%macro IDET_FILTER_LINE_16BIT 1 ; %1=increment (4 or 8 words)
cglobal idet_filter_line_16bit, 4, 5, 8, a, b, c, width, index
xor indexq, indexq
%define m_zero m1
%define m_sum m0
pxor m_sum, m_sum
pxor m_zero, m_zero
.loop_16bit:
movu m2, [bq + indexq * 2] ; B
movu m3, [aq + indexq * 2] ; A
mova m6, m2
psubusw m5, m2, m3 ; ba
movu m4, [cq + indexq * 2] ; C
add indexq, %1
psubusw m3, m2 ; ab
CMP indexd, widthd
psubusw m6, m4 ; bc
psubusw m4, m2 ; cb
PABS_DIFF_WD m3, m6, m7 ; |ab - bc|
PABS_DIFF_WD m5, m4, m7 ; |ba - cb|
paddd m_sum, m3
paddd m_sum, m5
jl .loop_16bit
HADDD m_sum, m2
movd eax, m_sum
RET
%endmacro
INIT_XMM sse2
IDET_FILTER_LINE_16BIT 8
;******************************************************************************
; SSE2 8-bit implementation that does 16-bytes at a time:
INIT_XMM sse2
cglobal idet_filter_line, 4, 6, 7, a, b, c, width, index, total
xor indexq, indexq
pxor m0, m0
pxor m1, m1
.sse2_loop:
movu m2, [bq + indexq*1] ; B
movu m3, [aq + indexq*1] ; A
mova m6, m2
mova m4, m3
psubusb m5, m2, m3 ; ba
movu m3, [cq + indexq*1] ; C
add indexq, 0x10
psubusb m4, m2 ; ab
CMP indexd, widthd
psubusb m6, m3 ; bc
psubusb m3, m2 ; cb
psadbw m4, m6 ; |ab - bc|
paddq m0, m4
psadbw m5, m3 ; |ba - cb|
paddq m1, m5
jl .sse2_loop
paddq m0, m1
movhlps m1, m0
paddq m0, m1
movd eax, m0
RET
+72
View File
@@ -0,0 +1,72 @@
/*
* 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/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/vf_idet.h"
#if HAVE_X86ASM
/* declares main callable idet_filter_line_sse2() */
#define FUNC_MAIN_DECL(KIND, SPAN) \
int ff_idet_filter_line_##KIND(const uint8_t *a, const uint8_t *b, \
const uint8_t *c, int w); \
static int idet_filter_line_##KIND(const uint8_t *a, const uint8_t *b, \
const uint8_t *c, int w) { \
int sum = 0; \
const int left_over = w & (SPAN - 1); \
w -= left_over; \
if (w > 0) \
sum += ff_idet_filter_line_##KIND(a, b, c, w); \
if (left_over > 0) \
sum += ff_idet_filter_line_c(a + w, b + w, c + w, left_over); \
return sum; \
}
#define FUNC_MAIN_DECL_16bit(KIND, SPAN) \
int ff_idet_filter_line_16bit_##KIND(const uint16_t *a, const uint16_t *b, \
const uint16_t *c, int w); \
static int idet_filter_line_16bit_##KIND(const uint16_t *a, const uint16_t *b, \
const uint16_t *c, int w) { \
int sum = 0; \
const int left_over = w & (SPAN - 1); \
w -= left_over; \
if (w > 0) \
sum += ff_idet_filter_line_16bit_##KIND(a, b, c, w); \
if (left_over > 0) \
sum += ff_idet_filter_line_c_16bit(a + w, b + w, c + w, left_over); \
return sum; \
}
FUNC_MAIN_DECL(sse2, 16)
FUNC_MAIN_DECL_16bit(sse2, 8)
#endif
av_cold void ff_idet_init_x86(IDETContext *idet, int for_16b)
{
#if HAVE_X86ASM
const int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE2(cpu_flags)) {
idet->filter_line = for_16b ? (ff_idet_filter_func)idet_filter_line_16bit_sse2 : idet_filter_line_sse2;
}
#endif // HAVE_X86ASM
}
+226
View File
@@ -0,0 +1,226 @@
;*****************************************************************************
;* x86-optimized functions for interlace filter
;*
;* Copyright (C) 2014 Kieran Kunhya <kierank@obe.tv>
;* Copyright (c) 2014 Michael Niedermayer <michaelni@gmx.at>
;* Copyright (c) 2017 Thomas Mundt <tmundt75@gmail.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 General Public License as published by
;* the Free Software Foundation; either version 2 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 General Public License for more details.
;*
;* You should have received a copy of the GNU 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/x86/x86util.asm"
SECTION_RODATA
pw_4: times 8 dw 4
SECTION .text
%macro LOWPASS 1
add dstq, hq
add srcq, hq
add mrefq, srcq
add prefq, srcq
neg hq
pcmpeq%1 m6, m6
test hq, mmsize
je .loop
;process 1 * mmsize
movu m0, [mrefq+hq]
pavg%1 m0, [prefq+hq]
pxor m0, m6
pxor m2, m6, [srcq+hq]
pavg%1 m0, m2
pxor m0, m6
movu [dstq+hq], m0
add hq, mmsize
jge .end
.loop:
movu m0, [mrefq+hq]
movu m1, [mrefq+hq+mmsize]
pavg%1 m0, [prefq+hq]
pavg%1 m1, [prefq+hq+mmsize]
pxor m0, m6
pxor m1, m6
pxor m2, m6, [srcq+hq]
pxor m3, m6, [srcq+hq+mmsize]
pavg%1 m0, m2
pavg%1 m1, m3
pxor m0, m6
pxor m1, m6
movu [dstq+hq], m0
movu [dstq+hq+mmsize], m1
add hq, 2*mmsize
jl .loop
.end:
RET
%endmacro
%macro LOWPASS_LINE 0
cglobal lowpass_line, 5, 5, 7, dst, h, src, mref, pref
LOWPASS b
cglobal lowpass_line_16, 5, 5, 7, dst, h, src, mref, pref
shl hq, 1
LOWPASS w
%endmacro
%macro LOWPASS_LINE_COMPLEX 0
cglobal lowpass_line_complex, 5, 5, 8, dst, h, src, mref, pref
pxor m7, m7
.loop:
movu m0, [srcq+mrefq]
movu m2, [srcq+prefq]
mova m1, m0
mova m3, m2
punpcklbw m0, m7
punpcklbw m2, m7
punpckhbw m1, m7
punpckhbw m3, m7
paddw m0, m2
paddw m1, m3
mova m6, m0
mova m5, m1
movu m2, [srcq]
mova m3, m2
punpcklbw m2, m7
punpckhbw m3, m7
paddw m0, m2
paddw m1, m3
psllw m2, 1
psllw m3, 1
paddw m0, m2
paddw m1, m3
psllw m0, 1
psllw m1, 1
pcmpgtw m6, m2
pcmpgtw m5, m3
packsswb m6, m5
movu m2, [srcq+mrefq*2]
movu m4, [srcq+prefq*2]
mova m3, m2
mova m5, m4
punpcklbw m2, m7
punpcklbw m4, m7
punpckhbw m3, m7
punpckhbw m5, m7
paddw m2, m4
paddw m3, m5
paddw m0, [pw_4]
paddw m1, [pw_4]
psubusw m0, m2
psubusw m1, m3
psrlw m0, 3
psrlw m1, 3
packuswb m0, m1
mova m1, m0
movu m2, [srcq]
pmaxub m0, m2
pminub m1, m2
pand m0, m6
pandn m6, m1
por m0, m6
movu [dstq], m0
add dstq, mmsize
add srcq, mmsize
sub hd, mmsize
jg .loop
RET
cglobal lowpass_line_complex_12, 5, 5, 8, 16, dst, h, src, mref, pref, clip_max
movd m7, DWORD clip_maxm
SPLATW m7, m7, 0
movu [rsp], m7
.loop:
movu m0, [srcq+mrefq]
movu m1, [srcq+mrefq+mmsize]
movu m2, [srcq+prefq]
movu m3, [srcq+prefq+mmsize]
paddw m0, m2
paddw m1, m3
mova m6, m0
mova m7, m1
movu m2, [srcq]
movu m3, [srcq+mmsize]
paddw m0, m2
paddw m1, m3
psllw m2, 1
psllw m3, 1
paddw m0, m2
paddw m1, m3
psllw m0, 1
psllw m1, 1
pcmpgtw m6, m2
pcmpgtw m7, m3
movu m2, [srcq+2*mrefq]
movu m3, [srcq+2*mrefq+mmsize]
movu m4, [srcq+2*prefq]
movu m5, [srcq+2*prefq+mmsize]
paddw m2, m4
paddw m3, m5
paddw m0, [pw_4]
paddw m1, [pw_4]
psubusw m0, m2
psubusw m1, m3
psrlw m0, 3
psrlw m1, 3
pminsw m0, [rsp]
pminsw m1, [rsp]
mova m2, m0
mova m3, m1
movu m4, [srcq]
pmaxsw m0, m4
pminsw m2, m4
movu m4, [srcq + mmsize]
pmaxsw m1, m4
pminsw m3, m4
pand m0, m6
pand m1, m7
pandn m6, m2
pandn m7, m3
por m0, m6
por m1, m7
movu [dstq], m0
movu [dstq+mmsize], m1
add dstq, 2*mmsize
add srcq, 2*mmsize
sub hd, mmsize
jg .loop
RET
%endmacro
INIT_XMM sse2
LOWPASS_LINE
INIT_XMM avx
LOWPASS_LINE
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
LOWPASS_LINE
%endif
INIT_XMM sse2
LOWPASS_LINE_COMPLEX
+80
View File
@@ -0,0 +1,80 @@
;*****************************************************************************
;* x86-optimized functions for limiter filter
;*
;* 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/x86/x86util.asm"
SECTION .text
INIT_XMM sse2
cglobal limiter_8bit, 6, 7, 3, src, dst, slinesize, dlinesize, w, h, x
movsxdifnidn wq, wd
add srcq, wq
add dstq, wq
neg wq
movd m1, r6m
punpcklbw m1, m1
SPLATW m1, m1
movd m2, r7m
punpcklbw m2, m2
SPLATW m2, m2
.nextrow:
mov xq, wq
.loop:
movu m0, [srcq + xq]
CLIPUB m0, m1, m2
movu [dstq+xq], m0
add xq, mmsize
jl .loop
add srcq, slinesizeq
add dstq, dlinesizeq
sub hd, 1
jg .nextrow
RET
INIT_XMM sse4
cglobal limiter_16bit, 6, 7, 3, src, dst, slinesize, dlinesize, w, h, x
shl wd, 1
add srcq, wq
add dstq, wq
neg wq
movd m1, r6m
SPLATW m1, m1
movd m2, r7m
SPLATW m2, m2
.nextrow:
mov xq, wq
.loop:
movu m0, [srcq + xq]
pmaxuw m0, m1
pminuw m0, m2
movu [dstq+xq], m0
add xq, mmsize
jl .loop
add srcq, slinesizeq
add dstq, dlinesizeq
sub hd, 1
jg .nextrow
RET
+44
View File
@@ -0,0 +1,44 @@
/*
* 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/x86/cpu.h"
#include "libavfilter/limiter.h"
void ff_limiter_8bit_sse2(const uint8_t *src, uint8_t *dst,
ptrdiff_t slinesize, ptrdiff_t dlinesize,
int w, int h, int min, int max);
void ff_limiter_16bit_sse4(const uint8_t *src, uint8_t *dst,
ptrdiff_t slinesize, ptrdiff_t dlinesize,
int w, int h, int min, int max);
void ff_limiter_init_x86(LimiterDSPContext *dsp, int bpp)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE2(cpu_flags)) {
if (bpp <= 8) {
dsp->limiter = ff_limiter_8bit_sse2;
}
}
if (EXTERNAL_SSE4(cpu_flags)) {
if (bpp > 8) {
dsp->limiter = ff_limiter_16bit_sse4;
}
}
}
+662
View File
@@ -0,0 +1,662 @@
;*****************************************************************************
;* x86-optimized functions for lut3d filter
;*
;* Copyright (c) 2021 Mark Reid <mindmark@gmail.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/x86/x86util.asm"
SECTION_RODATA
pd_1f: times 8 dd 1.0
pd_3f: times 8 dd 3.0
pd_65535f: times 8 dd 65535.0
pd_65535_invf: times 8 dd 0x37800080 ;1.0/65535.0
pb_shuffle16: db 0, 1, 0x80, 0x80, \
2, 3, 0x80, 0x80, \
4, 5, 0x80, 0x80, \
6, 7, 0x80, 0x80
pb_lo_pack_shuffle16: db 0, 1, 4, 5, \
8, 9, 12, 13, \
0x80, 0x80, 0x80, 0x80, \
0x80, 0x80, 0x80, 0x80
pb_hi_pack_shuffle16: db 0x80, 0x80, 0x80, 0x80, \
0x80, 0x80, 0x80, 0x80, \
0, 1, 4, 5, \
8, 9, 12, 13
SECTION .text
struc Lut3DPreLut
.size: resd 1
.min: resd 3
.max: resd 3
.scale: resd 3
.lut: resq 3
endstruc
struc LUT3DContext
.class: resq 1
.lut: resq 1
.lutsize: resd 1
.lutsize2: resd 1
.scale: resd 3
endstruc
%define AV_NUM_DATA_POINTERS 8
struc AVFrame
.data: resq AV_NUM_DATA_POINTERS
.linesize: resd AV_NUM_DATA_POINTERS
.extended_data: resq 1
.width: resd 1
.height: resd 1
endstruc
%define rm rsp
%define gm rsp+mmsize
%define bm rsp+(mmsize*2)
%define lut3dsizem [rsp+mmsize*3]
%define lut3dsize2m [rsp+mmsize*4]
%define lut3dmaxm [rsp+mmsize*5]
%define prelutmaxm [rsp+mmsize*6]
%define scalerm [rsp+mmsize*7]
%define scalegm [rsp+mmsize*8]
%define scalebm [rsp+mmsize*9]
%define prelutminrm [rsp+mmsize*10]
%define prelutmingm [rsp+mmsize*11]
%define prelutminbm [rsp+mmsize*12]
%define prelutscalerm [rsp+mmsize*13]
%define prelutscalegm [rsp+mmsize*14]
%define prelutscalebm [rsp+mmsize*15]
; data pointers
%define srcrm [rsp+mmsize*16 + 0]
%define srcgm [rsp+mmsize*16 + 8]
%define srcbm [rsp+mmsize*16 + 16]
%define srcam [rsp+mmsize*16 + 24]
%define dstrm [rsp+mmsize*16 + 32]
%define dstgm [rsp+mmsize*16 + 40]
%define dstbm [rsp+mmsize*16 + 48]
%define dstam [rsp+mmsize*16 + 56]
; 1 - prev
; 2 - next
; 3 - offset
%macro FETCH_PRELUT_PN 3
mov tmp2d, [rm + %3]
mov tmp3d, [gm + %3]
movss xm%1, [tmpq + tmp2q*4]
movss xm%2, [tmpq + tmp3q*4]
movss [rm + %3], xm%1
movss [gm + %3], xm%2
%endmacro
; 1 - p
; 2 - n
; 3 - p indices
; 4 - n indices
%macro GATHER_PRELUT 4
%if cpuflag(avx2)
vpcmpeqb m7, m7
vgatherdps m%1, [tmpq + m%3*4], m7 ; p
vpcmpeqb m9, m9
vgatherdps m%2, [tmpq + m%4*4], m9 ; n
%else
mova [rm], m%3
mova [gm], m%4
FETCH_PRELUT_PN %1, %2, 0
FETCH_PRELUT_PN %1, %2, 4
FETCH_PRELUT_PN %1, %2, 8
FETCH_PRELUT_PN %1, %2, 12
%if mmsize > 16
FETCH_PRELUT_PN %1, %2, 16
FETCH_PRELUT_PN %1, %2, 20
FETCH_PRELUT_PN %1, %2, 24
FETCH_PRELUT_PN %1, %2, 28
%endif
movu m%1, [rm]
movu m%2, [gm]
%endif
%endmacro
%macro FLOORPS 2
%if mmsize > 16
vroundps %1, %2, 0x01
%else
cvttps2dq %1, %2
cvtdq2ps %1, %1
%endif
%endmacro
; %1 = %2 * %3 + %1
%macro MADD3 3
%if cpuflag(avx2)
vfmadd231ps %1, %2, %3
%else
mulps %2, %2, %3
addps %1, %1, %2
%endif
%endmacro
; 1 - dst
; 2 - index
; 3 - min
; 4 - scale
; assumes lut max m13, m14 1.0f, zero m15
%macro APPLY_PRELUT 4
; scale
subps m5, m%1, %3 ; v - min
mulps m5, m5, %4 ; v * scale
; clamp
maxps m5, m5, m15 ; max zero, Max first, NAN set to zero
minps m5, m5, m13 ; min lut max
FLOORPS m3, m5 ; prev index
subps m5, m5, m3 ; d
addps m4, m3, m14 ; p+1 = n index
minps m4, m4, m13 ; clamp n idex
mov tmpq, [prelutq + Lut3DPreLut.lut + %2*8]
cvttps2dq m6, m3
cvttps2dq m10, m4
GATHER_PRELUT %1, 4, 6, 10
; lerp
subps m8, m4, m%1
MADD3 m%1, m8, m5
%endmacro
; 1 - dst
; 2 - scale
; assumes lut max m13, zero m15
%macro APPLY_SCALE 2
mulps m%1, m%1, %2
maxps m%1, m%1, m15 ; Max first, NAN set to zero
minps m%1, m%1, m13
%endmacro
%macro BLEND 4
%if mmsize > 16
vblendvps %1, %2, %3, %4
%else
%ifidni %1,%2
%error operand 1 must not equal operand 2
%endif
%ifidni %1,%3
%error operand 1 must not equal operand 3
%endif
mova %1, %2
xorps %1, %3
andps %1, %4
xorps %1, %2
%endif
%endmacro
%macro ADD3 4
addps %1, %2, %3
addps %1, %1, %4
%endmacro
%macro FETCH_LUT3D_RGB 4
mov tmp2d, [rm + %4]
movss xm%1, [tmpq + tmp2q*4 + 0]
movss xm%2, [tmpq + tmp2q*4 + 4]
movss xm%3, [tmpq + tmp2q*4 + 8]
movss [rm + %4], xm%1
movss [gm + %4], xm%2
movss [bm + %4], xm%3
%endmacro
; 1 - dstr
; 2 - dstg
; 3 - dstb
; 4 - indices
%macro GATHER_LUT3D_INDICES 4
%if cpuflag(avx2)
vpcmpeqb m3, m3
vgatherdps m%1, [tmpq + m%4*4 + 0], m3
vpcmpeqb m14, m14
vgatherdps m%2, [tmpq + m%4*4 + 4], m14
vpcmpeqb m15, m15
vgatherdps m%3, [tmpq + m%4*4 + 8], m15
%else
movu [rm], m%4
FETCH_LUT3D_RGB %1, %2, %3, 0
FETCH_LUT3D_RGB %1, %2, %3, 4
FETCH_LUT3D_RGB %1, %2, %3, 8
FETCH_LUT3D_RGB %1, %2, %3, 12
%if mmsize > 16
FETCH_LUT3D_RGB %1, %2, %3, 16
FETCH_LUT3D_RGB %1, %2, %3, 20
FETCH_LUT3D_RGB %1, %2, %3, 24
FETCH_LUT3D_RGB %1, %2, %3, 28
%endif
movu m%1, [rm]
movu m%2, [gm]
movu m%3, [bm]
%endif
%endmacro
%macro interp_tetrahedral 0
%define d_r m0
%define d_g m1
%define d_b m2
%define prev_r m3
%define prev_g m4
%define prev_b m5
%define next_r m6
%define next_g m7
%define next_b m8
%define x0 m4
%define x1 m5
%define x2 m6
; setup prev index
FLOORPS prev_r, m0
FLOORPS prev_g, m1
FLOORPS prev_b, m2
; setup deltas
subps d_r, m0, prev_r
subps d_g, m1, prev_g
subps d_b, m2, prev_b
; setup next index
addps next_r, prev_r, m14 ; +1
minps next_r, next_r, m13 ; clamp lutmax
addps next_g, prev_g, m14 ; +1
minps next_g, next_g, m13 ; clamp lutmax
addps next_b, prev_b, m14 ; +1
minps next_b, next_b, m13 ; clamp lutmax
; prescale indices
mulps prev_r, prev_r, lut3dsize2m
mulps next_r, next_r, lut3dsize2m
mulps prev_g, prev_g, lut3dsizem
mulps next_g, next_g, lut3dsizem
mulps prev_b, prev_b, [pd_3f]
mulps next_b, next_b, [pd_3f]
; cxxxa m10
; 1 is the delta that is the largest
; r> == c100 == (r>g && r>b)
; g> == c010 == (g>r && g>b)
; b> == c001 == (b>r && b>g)
; if delta > other 2 use next else prev
; cxxxb m11;
; 0 is the delta that is the smallest
; r< == c011 == (r<=g && r<=b)
; g< == c101 == (g<=r && g<=b)
; b< == c110 == (b<=r && b<=g)
; if delta <= other 2 use prev else next
cmpps m13, d_r, d_g, 0x1E ; r>g
cmpps m14, d_g, d_b, 0x1E ; g>b
cmpps m15, d_b, d_r, 0x1E ; b>r
; r> !b>r && r>g
andnps m9, m15, m13
BLEND m10, prev_r, next_r, m9
; r< !r>g && b>r
andnps m9, m13, m15
BLEND m11, next_r, prev_r, m9
; g> !r>g && g>b
andnps m9, m13, m14
BLEND m12, prev_g, next_g, m9
addps m10, m10, m12
; g< !g>b && r>g
andnps m9, m14, m13
BLEND m12, next_g, prev_g, m9
addps m11, m11, m12
; b> !g>b && b>r
andnps m9, m14, m15
BLEND m12, prev_b, next_b, m9
addps m10, m10, m12
; b< !b>r && g>b
andnps m9, m15, m14
BLEND m12, next_b, prev_b, m9
addps m11, m11, m12
; c000 m12;
ADD3 m12, prev_r, prev_g, prev_b
; c111 m13;
ADD3 m13, next_r, next_g, next_b
; sort delta r,g,b x0 >= x1 >= x2
minps m7, d_r, d_g
maxps m8, d_r, d_g
minps x2, m7, d_b
maxps m7, m7, d_b
maxps x0, m8, d_b
minps x1, m8, m7
; convert indices to integer
cvttps2dq m12, m12
cvttps2dq m10, m10
cvttps2dq m11, m11
cvttps2dq m13, m13
; now the gathering festival
mov tmpq, [ctxq + LUT3DContext.lut]
GATHER_LUT3D_INDICES 0, 1, 2, 12
movu m14, [pd_1f]
subps m14, m14, x0; 1 - x0
mulps m0, m0, m14
mulps m1, m1, m14
mulps m2, m2, m14
GATHER_LUT3D_INDICES 7, 8, 9, 10
subps m14, x0, x1; x0 - x1
MADD3 m0, m7, m14
MADD3 m1, m8, m14
MADD3 m2, m9, m14
GATHER_LUT3D_INDICES 7, 8, 9, 11
subps m14, x1, x2; x1 - x2
MADD3 m0, m7, m14
MADD3 m1, m8, m14
MADD3 m2, m9, m14
GATHER_LUT3D_INDICES 7, 8, 9, 13
MADD3 m0, m7, x2
MADD3 m1, m8, x2
MADD3 m2, m9, x2
%endmacro
%macro INIT_DATA_PTR 3
mov ptrq, [%2 + AVFrame.data + %3 * 8]
mov tmpd, [%2 + AVFrame.linesize + %3 * 4]
imul tmpd, slice_startd
add ptrq, tmpq
mov %1, ptrq
%endmacro
%macro INC_DATA_PTR 3
mov tmpd, [%2 + AVFrame.linesize + %3 * 4]
mov ptrq, %1
add ptrq, tmpq
mov %1, ptrq
%endmacro
%macro LOAD16 2
mov ptrq, %2
%if mmsize > 16
movu xm%1, [ptrq + xq*2]
%else
movsd xm%1, [ptrq + xq*2]
%endif
%if cpuflag(avx2)
vpmovzxwd m%1, xm%1
%else
%if mmsize > 16
pshufd xm4, xm%1, (1 << 6 | 0 << 4 | 3 << 2 | 2 << 0)
pshufb xm%1, xm6 ; pb_shuffle16
pshufb xm4, xm6 ; pb_shuffle16
vinsertf128 m%1, m%1, xm4, 1
%else
pshufd xm%1, xm%1, (3 << 6 | 1 << 4 | 3 << 2 | 0 << 0)
pshuflw xm%1, xm%1, (2 << 6 | 1 << 4 | 2 << 2 | 0 << 0)
pshufhw xm%1, xm%1, (2 << 6 | 1 << 4 | 2 << 2 | 0 << 0)
%endif
%endif
cvtdq2ps m%1, m%1
mulps m%1, m%1, m7 ; pd_65535_invf
%endmacro
%macro STORE16 2
mulps m%2, m%2, m5 ; [pd_65535f]
minps m%2, m%2, m5 ; [pd_65535f]
maxps m%2, m%2, m15 ; zero
cvttps2dq m%2, m%2
%if mmsize > 16
vextractf128 xm4, m%2, 1
pshufb xm%2, xm6 ; [pb_lo_pack_shuffle16]
pshufb xm4, xm7 ; [pb_hi_pack_shuffle16]
por xm%2, xm4
%else
pshuflw xm%2, xm%2, (1 << 6 | 1 << 4 | 2 << 2 | 0 << 0)
pshufhw xm%2, xm%2, (1 << 6 | 1 << 4 | 2 << 2 | 0 << 0)
pshufd xm%2, xm%2, (3 << 6 | 3 << 4 | 2 << 2 | 0 << 0)
%endif
mov ptrq, %1
%if mmsize > 16
movu [ptrq + xq*2], xm%2
%else
movsd [ptrq + xq*2], xm%2
%endif
%endmacro
; 1 - interp method
; 2 - format_name
; 3 - depth
; 4 - is float format
%macro DEFINE_INTERP_FUNC 4
cglobal interp_%1_%2, 7, 13, 16, mmsize*16+(8*8), ctx, prelut, src_image, dst_image, slice_start, slice_end, has_alpha, width, x, ptr, tmp, tmp2, tmp3
; store lut max and lutsize
mov tmpd, dword [ctxq + LUT3DContext.lutsize]
cvtsi2ss xm0, tmpd
mulss xm0, xm0, [pd_3f]
VBROADCASTSS m0, xm0
mova lut3dsizem, m0
sub tmpd, 1
cvtsi2ss xm0, tmpd
VBROADCASTSS m0, xm0
mova lut3dmaxm, m0
; scale_r
mulss xm1, xm0, dword [ctxq + LUT3DContext.scale + 0*4]
VBROADCASTSS m1, xm1
mova scalerm, m1
; scale_g
mulss xm1, xm0, dword [ctxq + LUT3DContext.scale + 1*4]
VBROADCASTSS m1, xm1
mova scalegm, m1
; scale_b
mulss xm1, xm0, dword [ctxq + LUT3DContext.scale + 2*4]
VBROADCASTSS m1, xm1
mova scalebm, m1
; store lutsize2
cvtsi2ss xm0, dword [ctxq + LUT3DContext.lutsize2]
mulss xm0, xm0, [pd_3f]
VBROADCASTSS m0, xm0
mova lut3dsize2m, m0
; init prelut values
cmp prelutq, 0
je %%skip_init_prelut
mov tmpd, dword [prelutq + Lut3DPreLut.size]
sub tmpd, 1
cvtsi2ss xm0, tmpd
VBROADCASTSS m0, xm0
mova prelutmaxm, m0
VBROADCASTSS m0, dword [prelutq + Lut3DPreLut.min + 0*4]
mova prelutminrm, m0
VBROADCASTSS m0, dword [prelutq + Lut3DPreLut.min + 1*4]
mova prelutmingm, m0
VBROADCASTSS m0, dword [prelutq + Lut3DPreLut.min + 2*4]
mova prelutminbm, m0
VBROADCASTSS m0, dword [prelutq + Lut3DPreLut.scale + 0*4]
mova prelutscalerm, m0
VBROADCASTSS m0, dword [prelutq + Lut3DPreLut.scale + 1*4]
mova prelutscalegm, m0
VBROADCASTSS m0, dword [prelutq + Lut3DPreLut.scale + 2*4]
mova prelutscalebm, m0
%%skip_init_prelut:
mov widthd, [src_imageq + AVFrame.width]
; gbra pixel order
INIT_DATA_PTR srcrm, src_imageq, 2
INIT_DATA_PTR srcgm, src_imageq, 0
INIT_DATA_PTR srcbm, src_imageq, 1
INIT_DATA_PTR srcam, src_imageq, 3
INIT_DATA_PTR dstrm, dst_imageq, 2
INIT_DATA_PTR dstgm, dst_imageq, 0
INIT_DATA_PTR dstbm, dst_imageq, 1
INIT_DATA_PTR dstam, dst_imageq, 3
%%loop_y:
xor xq, xq
%%loop_x:
movu m14, [pd_1f]
xorps m15, m15, m15
%if %4 ; float
mov ptrq, srcrm
movu m0, [ptrq + xq*4]
mov ptrq, srcgm
movu m1, [ptrq + xq*4]
mov ptrq, srcbm
movu m2, [ptrq + xq*4]
%else
; constants for LOAD16
movu m7, [pd_65535_invf]
%if notcpuflag(avx2) && mmsize >= 32
movu xm6, [pb_shuffle16]
%endif
LOAD16 0, srcrm
LOAD16 1, srcgm
LOAD16 2, srcbm
%endif
cmp prelutq, 0
je %%skip_prelut
mova m13, prelutmaxm
APPLY_PRELUT 0, 0, prelutminrm, prelutscalerm
APPLY_PRELUT 1, 1, prelutmingm, prelutscalegm
APPLY_PRELUT 2, 2, prelutminbm, prelutscalebm
%%skip_prelut:
mova m13, lut3dmaxm
APPLY_SCALE 0, scalerm
APPLY_SCALE 1, scalegm
APPLY_SCALE 2, scalebm
interp_%1
%if %4 ; float
mov ptrq, dstrm
movu [ptrq + xq*4], m0
mov ptrq, dstgm
movu [ptrq + xq*4], m1
mov ptrq, dstbm
movu [ptrq + xq*4], m2
cmp has_alphad, 0
je %%skip_alphaf
mov ptrq, srcam
movu m0, [ptrq + xq*4]
mov ptrq, dstam
movu [ptrq + xq*4], m0
%%skip_alphaf:
%else
; constants for STORE16
movu m5, [pd_65535f]
%if mmsize > 16
movu xm6, [pb_lo_pack_shuffle16]
movu xm7, [pb_hi_pack_shuffle16]
%endif
xorps m15, m15, m15
STORE16 dstrm, 0
STORE16 dstgm, 1
STORE16 dstbm, 2
cmp has_alphad, 0
je %%skip_alpha
%if mmsize > 16
mov ptrq, srcam
movu xm0, [ptrq + xq*2]
mov ptrq, dstam
movu [ptrq + xq*2], xm0
%else
mov ptrq, srcam
movsd xm0, [ptrq + xq*2]
mov ptrq, dstam
movsd [ptrq + xq*2], xm0
%endif
%%skip_alpha:
%endif
add xq, mmsize/4
cmp xd, widthd
jl %%loop_x
INC_DATA_PTR srcrm, src_imageq, 2
INC_DATA_PTR srcgm, src_imageq, 0
INC_DATA_PTR srcbm, src_imageq, 1
INC_DATA_PTR srcam, src_imageq, 3
INC_DATA_PTR dstrm, dst_imageq, 2
INC_DATA_PTR dstgm, dst_imageq, 0
INC_DATA_PTR dstbm, dst_imageq, 1
INC_DATA_PTR dstam, dst_imageq, 3
inc slice_startd
cmp slice_startd, slice_endd
jl %%loop_y
RET
%endmacro
%if ARCH_X86_64
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
DEFINE_INTERP_FUNC tetrahedral, pf32, 32, 1
DEFINE_INTERP_FUNC tetrahedral, p16, 16, 0
%endif
%if HAVE_AVX_EXTERNAL
INIT_YMM avx
DEFINE_INTERP_FUNC tetrahedral, pf32, 32, 1
DEFINE_INTERP_FUNC tetrahedral, p16, 16, 0
%endif
INIT_XMM sse2
DEFINE_INTERP_FUNC tetrahedral, pf32, 32, 1
DEFINE_INTERP_FUNC tetrahedral, p16, 16, 0
%endif
+92
View File
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2021 Mark Reid <mindmark@gmail.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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/lut3d.h"
#define DEFINE_INTERP_FUNC(name, format, opt) \
void ff_interp_##name##_##format##_##opt(LUT3DContext *lut3d, Lut3DPreLut *prelut, AVFrame *src, AVFrame *dst, int slice_start, int slice_end, int has_alpha); \
static int interp_##name##_##format##_##opt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
{ \
LUT3DContext *lut3d = ctx->priv; \
Lut3DPreLut *prelut = lut3d->prelut.size > 0? &lut3d->prelut: NULL; \
ThreadData *td = arg; \
AVFrame *in = td->in; \
AVFrame *out = td->out; \
int has_alpha = in->linesize[3] && out != in; \
int slice_start = (in->height * jobnr ) / nb_jobs; \
int slice_end = (in->height * (jobnr+1)) / nb_jobs; \
ff_interp_##name##_##format##_##opt(lut3d, prelut, in, out, slice_start, slice_end, has_alpha); \
return 0; \
}
#if ARCH_X86_64
#if HAVE_AVX2_EXTERNAL
DEFINE_INTERP_FUNC(tetrahedral, pf32, avx2)
DEFINE_INTERP_FUNC(tetrahedral, p16, avx2)
#endif
#if HAVE_AVX_EXTERNAL
DEFINE_INTERP_FUNC(tetrahedral, pf32, avx)
DEFINE_INTERP_FUNC(tetrahedral, p16, avx)
#endif
#if HAVE_SSE2_EXTERNAL
DEFINE_INTERP_FUNC(tetrahedral, pf32, sse2)
DEFINE_INTERP_FUNC(tetrahedral, p16, sse2)
#endif
#endif
av_cold void ff_lut3d_init_x86(LUT3DContext *s, const AVPixFmtDescriptor *desc)
{
int cpu_flags = av_get_cpu_flags();
int planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
int isfloat = desc->flags & AV_PIX_FMT_FLAG_FLOAT;
int depth = desc->comp[0].depth;
#if ARCH_X86_64
if (EXTERNAL_AVX2_FAST(cpu_flags) && EXTERNAL_FMA3(cpu_flags) && s->interpolation == INTERPOLATE_TETRAHEDRAL && planar) {
#if HAVE_AVX2_EXTERNAL
if (isfloat && planar) {
s->interp = interp_tetrahedral_pf32_avx2;
} else if (depth == 16) {
s->interp = interp_tetrahedral_p16_avx2;
}
#endif
} else if (EXTERNAL_AVX_FAST(cpu_flags) && s->interpolation == INTERPOLATE_TETRAHEDRAL && planar) {
#if HAVE_AVX_EXTERNAL
if (isfloat) {
s->interp = interp_tetrahedral_pf32_avx;
} else if (depth == 16) {
s->interp = interp_tetrahedral_p16_avx;
}
#endif
} else if (EXTERNAL_SSE2(cpu_flags) && s->interpolation == INTERPOLATE_TETRAHEDRAL && planar) {
#if HAVE_SSE2_EXTERNAL
if (isfloat) {
s->interp = interp_tetrahedral_pf32_sse2;
} else if (depth == 16) {
s->interp = interp_tetrahedral_p16_sse2;
}
#endif
}
#endif
}
+95
View File
@@ -0,0 +1,95 @@
;*****************************************************************************
;* x86-optimized functions for maskedclamp filter
;*
;* Copyright (c) 2019 Paul B Mahol
;*
;* 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/x86/x86util.asm"
SECTION .text
;------------------------------------------------------------------------------
; void ff_maskedclamp(const uint8_t *src, uint8_t *dst,
; const uint8_t *darksrc,
; const uint8_t *brightsrc,
; int w, int undershoot, int overshoot)
;------------------------------------------------------------------------------
INIT_XMM sse2
cglobal maskedclamp8, 5,5,5, src, dst, dark, bright, w, undershoot, overshoot
movsxdifnidn wq, wd
add srcq, wq
add darkq, wq
add brightq, wq
add dstq, wq
neg wq
movd m3, r5m
punpcklbw m3, m3
SPLATW m3, m3
movd m4, r6m
punpcklbw m4, m4
SPLATW m4, m4
.loop:
movu m0, [srcq + wq]
movu m1, [darkq + wq]
movu m2, [brightq + wq]
psubusb m1, m3
paddusb m2, m4
CLIPUB m0, m1, m2
mova [dstq + wq], m0
add wq, mmsize
jl .loop
RET
INIT_XMM sse4
cglobal maskedclamp16, 5,5,5, src, dst, dark, bright, w, undershoot, overshoot
shl wd, 1
add srcq, wq
add darkq, wq
add brightq, wq
add dstq, wq
neg wq
movd m3, r5m
SPLATW m3, m3
movd m4, r6m
SPLATW m4, m4
.loop:
movu m0, [srcq + wq]
movu m1, [darkq + wq]
movu m2, [brightq + wq]
psubusw m1, m3
paddusw m2, m4
pmaxuw m0, m1
pminuw m0, m2
mova [dstq + wq], m0
add wq, mmsize
jl .loop
RET
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2019 Paul B Mahol
*
* 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/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/maskedclamp.h"
void ff_maskedclamp8_sse2(const uint8_t *bsrc, uint8_t *dst,
const uint8_t *darksrc, const uint8_t *brightsrc,
int w, int undershoot, int overshoot);
void ff_maskedclamp16_sse4(const uint8_t *bsrc, uint8_t *dst,
const uint8_t *darksrc, const uint8_t *brightsrc,
int w, int undershoot, int overshoot);
av_cold void ff_maskedclamp_init_x86(MaskedClampDSPContext *dsp, int depth)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE2(cpu_flags) && depth <= 8) {
dsp->maskedclamp = ff_maskedclamp8_sse2;
}
if (EXTERNAL_SSE4(cpu_flags) && depth > 8) {
dsp->maskedclamp = ff_maskedclamp16_sse4;
}
}
+84
View File
@@ -0,0 +1,84 @@
;*****************************************************************************
;* x86-optimized functions for maskedmerge filter
;*
;* Copyright (C) 2015 Paul B Mahol
;*
;* 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/x86/x86util.asm"
SECTION_RODATA
pw_127: times 8 dw 127
pw_255: times 8 dw 255
pw_32897: times 8 dw 32897
SECTION .text
INIT_XMM sse2
%if ARCH_X86_64
cglobal maskedmerge8, 8, 11, 8, bsrc, osrc, msrc, dst, blinesize, olinesize, mlinesize, dlinesize, w, h, x
mov wd, dword wm
mov hd, dword hm
%else
cglobal maskedmerge8, 5, 7, 8, bsrc, osrc, msrc, dst, blinesize, w, x
mov wd, r8m
%define olinesizeq r5mp
%define mlinesizeq r6mp
%define dlinesizeq r7mp
%define hd r9mp
%endif
mova m4, [pw_255]
mova m5, [pw_127]
mova m7, [pw_32897]
pxor m6, m6
add bsrcq, wq
add osrcq, wq
add msrcq, wq
add dstq, wq
neg wq
.nextrow:
mov xq, wq
.loop:
movh m0, [bsrcq + xq]
movh m1, [osrcq + xq]
movh m3, [msrcq + xq]
mova m2, m4
punpcklbw m0, m6
punpcklbw m1, m6
punpcklbw m3, m6
psubw m2, m3
pmullw m2, m0
pmullw m1, m3
paddw m1, m2
paddw m1, m5
pmulhuw m1, m7
psrlw m1, 7
packuswb m1, m1
movh [dstq + xq], m1
add xq, mmsize / 2
jl .loop
add bsrcq, blinesizeq
add osrcq, olinesizeq
add msrcq, mlinesizeq
add dstq, dlinesizeq
sub hd, 1
jg .nextrow
RET
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2015 Paul B Mahol
*
* 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/maskedmerge.h"
void ff_maskedmerge8_sse2(const uint8_t *bsrc, const uint8_t *osrc,
const uint8_t *msrc, uint8_t *dst,
ptrdiff_t blinesize, ptrdiff_t olinesize,
ptrdiff_t mlinesize, ptrdiff_t dlinesize,
int w, int h,
int half, int shift);
av_cold void ff_maskedmerge_init_x86(MaskedMergeContext *s)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE2(cpu_flags) && s->depth == 8) {
s->maskedmerge = ff_maskedmerge8_sse2;
}
}
+97
View File
@@ -0,0 +1,97 @@
;*****************************************************************************
;* x86-optimized functions for nlmeans filter
;*
;* 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/x86/x86util.asm"
%if HAVE_AVX2_EXTERNAL && ARCH_X86_64
SECTION_RODATA 32
ending_lut: dd -1, -1, -1, -1, -1, -1, -1, -1,\
0, -1, -1, -1, -1, -1, -1, -1,\
0, 0, -1, -1, -1, -1, -1, -1,\
0, 0, 0, -1, -1, -1, -1, -1,\
0, 0, 0, 0, -1, -1, -1, -1,\
0, 0, 0, 0, 0, -1, -1, -1,\
0, 0, 0, 0, 0, 0, -1, -1,\
0, 0, 0, 0, 0, 0, 0, -1,\
0, 0, 0, 0, 0, 0, 0, 0
SECTION .text
; void ff_compute_weights_line(const uint32_t *const iia,
; const uint32_t *const iib,
; const uint32_t *const iid,
; const uint32_t *const iie,
; const uint8_t *const src,
; float *total,
; float *sum,
; const float *const lut,
; int max,
; int startx, int endx);
INIT_YMM avx2
cglobal compute_weights_line, 8, 13, 5, 0, iia, iib, iid, iie, src, total, sum, lut, x, startx, endx, mod, elut
movsxd startxq, dword startxm
movsxd endxq, dword endxm
VPBROADCASTD m2, r8m
mov xq, startxq
mov modq, mmsize / 4
lea elutq, [ending_lut]
vpcmpeqd m4, m4
.loop:
mov startxq, endxq
sub startxq, xq
cmp startxq, modq
cmovge startxq, modq
sal startxq, 5
movu m0, [iieq + xq * 4]
psubd m0, [iidq + xq * 4]
psubd m0, [iibq + xq * 4]
paddd m0, [iiaq + xq * 4]
por m0, [elutq + startxq]
pminud m0, m2
pslld m0, 2
mova m3, m4
vgatherdps m1, [lutq + m0], m3
pmovzxbd m0, [srcq + xq]
cvtdq2ps m0, m0
mulps m0, m1
addps m1, [totalq + xq * 4]
addps m0, [sumq + xq * 4]
movups [totalq + xq * 4], m1
movups [sumq + xq * 4], m0
add xq, mmsize / 4
cmp xq, endxq
jl .loop
RET
%endif
+40
View File
@@ -0,0 +1,40 @@
/*
* 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/x86/cpu.h"
#include "libavfilter/vf_nlmeans.h"
void ff_compute_weights_line_avx2(const uint32_t *const iia,
const uint32_t *const iib,
const uint32_t *const iid,
const uint32_t *const iie,
const uint8_t *const src,
float *total_weight,
float *sum,
const float *const weight_lut,
int max_meaningful_diff,
int startx, int endx);
av_cold void ff_nlmeans_init_x86(NLMeansDSPContext *dsp)
{
int cpu_flags = av_get_cpu_flags();
if (ARCH_X86_64 && EXTERNAL_AVX2_FAST(cpu_flags))
dsp->compute_weights_line = ff_compute_weights_line_avx2;
}
+115
View File
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
* Copyright (c) 2013 Paul B Mahol
*
* 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/x86/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavfilter/vf_noise.h"
#if HAVE_INLINE_ASM
#if HAVE_6REGS
static void line_noise_avg_mmx(uint8_t *dst, const uint8_t *src,
int len, const int8_t * const *shift)
{
x86_reg mmx_len = len & (~7);
__asm__ volatile(
"mov %5, %%"FF_REG_a" \n\t"
".p2align 4 \n\t"
"1: \n\t"
"movq (%1, %%"FF_REG_a"), %%mm1 \n\t"
"movq (%0, %%"FF_REG_a"), %%mm0 \n\t"
"paddb (%2, %%"FF_REG_a"), %%mm1\n\t"
"paddb (%3, %%"FF_REG_a"), %%mm1\n\t"
"movq %%mm0, %%mm2 \n\t"
"movq %%mm1, %%mm3 \n\t"
"punpcklbw %%mm0, %%mm0 \n\t"
"punpckhbw %%mm2, %%mm2 \n\t"
"punpcklbw %%mm1, %%mm1 \n\t"
"punpckhbw %%mm3, %%mm3 \n\t"
"pmulhw %%mm0, %%mm1 \n\t"
"pmulhw %%mm2, %%mm3 \n\t"
"paddw %%mm1, %%mm1 \n\t"
"paddw %%mm3, %%mm3 \n\t"
"paddw %%mm0, %%mm1 \n\t"
"paddw %%mm2, %%mm3 \n\t"
"psrlw $8, %%mm1 \n\t"
"psrlw $8, %%mm3 \n\t"
"packuswb %%mm3, %%mm1 \n\t"
"movq %%mm1, (%4, %%"FF_REG_a") \n\t"
"add $8, %%"FF_REG_a" \n\t"
" js 1b \n\t"
:: "r" (src+mmx_len), "r" (shift[0]+mmx_len), "r" (shift[1]+mmx_len), "r" (shift[2]+mmx_len),
"r" (dst+mmx_len), "g" (-mmx_len)
: "%"FF_REG_a
);
if (mmx_len != len){
const int8_t *shift2[3] = { shift[0]+mmx_len, shift[1]+mmx_len, shift[2]+mmx_len };
ff_line_noise_avg_c(dst+mmx_len, src+mmx_len, len-mmx_len, shift2);
}
}
#endif /* HAVE_6REGS */
static void line_noise_mmxext(uint8_t *dst, const uint8_t *src,
const int8_t *noise, int len, int shift)
{
x86_reg mmx_len = len & (~7);
noise += shift;
__asm__ volatile(
"mov %3, %%"FF_REG_a" \n\t"
"pcmpeqb %%mm7, %%mm7 \n\t"
"psllw $15, %%mm7 \n\t"
"packsswb %%mm7, %%mm7 \n\t"
".p2align 4 \n\t"
"1: \n\t"
"movq (%0, %%"FF_REG_a"), %%mm0 \n\t"
"movq (%1, %%"FF_REG_a"), %%mm1 \n\t"
"pxor %%mm7, %%mm0 \n\t"
"paddsb %%mm1, %%mm0 \n\t"
"pxor %%mm7, %%mm0 \n\t"
"movntq %%mm0, (%2, %%"FF_REG_a") \n\t"
"add $8, %%"FF_REG_a" \n\t"
" js 1b \n\t"
:: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
: "%"FF_REG_a
);
if (mmx_len != len)
ff_line_noise_c(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
}
#endif /* HAVE_INLINE_ASM */
av_cold void ff_noise_init_x86(NoiseContext *n)
{
#if HAVE_INLINE_ASM
int cpu_flags = av_get_cpu_flags();
if (INLINE_MMX(cpu_flags)) {
#if HAVE_6REGS
n->line_noise_avg = line_noise_avg_mmx;
#endif
}
if (INLINE_MMXEXT(cpu_flags)) {
n->line_noise = line_noise_mmxext;
}
#endif
}
+144
View File
@@ -0,0 +1,144 @@
;*****************************************************************************
;* x86-optimized functions for overlay filter
;*
;* Copyright (C) 2018 Paul B Mahol
;* Copyright (C) 2018 Henrik Gramner
;*
;* 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/x86/x86util.asm"
SECTION_RODATA
pb_1: times 16 db 1
pw_128: times 8 dw 128
pw_255: times 8 dw 255
pw_257: times 8 dw 257
SECTION .text
INIT_XMM sse4
cglobal overlay_row_44, 5, 7, 6, 0, dst, da, s, a, w, r, x
xor xq, xq
movsxdifnidn wq, wd
mov rq, wq
and rq, mmsize/2 - 1
cmp wq, mmsize/2
jl .end
sub wq, rq
mova m3, [pw_255]
mova m4, [pw_128]
mova m5, [pw_257]
.loop:
pmovzxbw m0, [sq+xq]
pmovzxbw m2, [aq+xq]
pmovzxbw m1, [dstq+xq]
pmullw m0, m2
pxor m2, m3
pmullw m1, m2
paddw m0, m4
paddw m0, m1
pmulhuw m0, m5
packuswb m0, m0
movq [dstq+xq], m0
add xq, mmsize/2
cmp xq, wq
jl .loop
.end:
mov eax, xd
RET
INIT_XMM sse4
cglobal overlay_row_22, 5, 7, 6, 0, dst, da, s, a, w, r, x
xor xq, xq
movsxdifnidn wq, wd
sub wq, 1
mov rq, wq
and rq, mmsize/2 - 1
cmp wq, mmsize/2
jl .end
sub wq, rq
mova m3, [pw_255]
mova m4, [pw_128]
mova m5, [pw_257]
.loop:
pmovzxbw m0, [sq+xq]
movu m1, [aq+2*xq]
pandn m2, m3, m1
psllw m1, 8
pavgw m2, m1
pavgw m2, m1
psrlw m2, 8
pmovzxbw m1, [dstq+xq]
pmullw m0, m2
pxor m2, m3
pmullw m1, m2
paddw m0, m4
paddw m0, m1
pmulhuw m0, m5
packuswb m0, m0
movq [dstq+xq], m0
add xq, mmsize/2
cmp xq, wq
jl .loop
.end:
mov eax, xd
RET
INIT_XMM sse4
cglobal overlay_row_20, 6, 7, 7, 0, dst, da, s, a, w, r, x
mov daq, aq
add daq, rmp
xor xq, xq
movsxdifnidn wq, wd
sub wq, 1
mov rq, wq
and rq, mmsize/2 - 1
cmp wq, mmsize/2
jl .end
sub wq, rq
mova m3, [pw_255]
mova m4, [pw_128]
mova m5, [pw_257]
mova m6, [pb_1]
.loop:
pmovzxbw m0, [sq+xq]
movu m2, [aq+2*xq]
movu m1, [daq+2*xq]
pmaddubsw m2, m6
pmaddubsw m1, m6
paddw m2, m1
psrlw m2, 2
pmovzxbw m1, [dstq+xq]
pmullw m0, m2
pxor m2, m3
pmullw m1, m2
paddw m0, m4
paddw m0, m1
pmulhuw m0, m5
packuswb m0, m0
movq [dstq+xq], m0
add xq, mmsize/2
cmp xq, wq
jl .loop
.end:
mov eax, xd
RET
+65
View File
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2018 Paul B Mahol
*
* 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/vf_overlay.h"
int ff_overlay_row_44_sse4(uint8_t *d, uint8_t *da, uint8_t *s, uint8_t *a,
int w, ptrdiff_t alinesize);
int ff_overlay_row_20_sse4(uint8_t *d, uint8_t *da, uint8_t *s, uint8_t *a,
int w, ptrdiff_t alinesize);
int ff_overlay_row_22_sse4(uint8_t *d, uint8_t *da, uint8_t *s, uint8_t *a,
int w, ptrdiff_t alinesize);
av_cold void ff_overlay_init_x86(OverlayContext *s, int format, int pix_format,
int alpha_format, int main_has_alpha)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE4(cpu_flags) &&
(format == OVERLAY_FORMAT_YUV444 ||
format == OVERLAY_FORMAT_GBRP) &&
alpha_format == 0 && main_has_alpha == 0) {
s->blend_row[0] = ff_overlay_row_44_sse4;
s->blend_row[1] = ff_overlay_row_44_sse4;
s->blend_row[2] = ff_overlay_row_44_sse4;
}
if (EXTERNAL_SSE4(cpu_flags) &&
(pix_format == AV_PIX_FMT_YUV420P) &&
(format == OVERLAY_FORMAT_YUV420) &&
alpha_format == 0 && main_has_alpha == 0) {
s->blend_row[0] = ff_overlay_row_44_sse4;
s->blend_row[1] = ff_overlay_row_20_sse4;
s->blend_row[2] = ff_overlay_row_20_sse4;
}
if (EXTERNAL_SSE4(cpu_flags) &&
(format == OVERLAY_FORMAT_YUV422) &&
alpha_format == 0 && main_has_alpha == 0) {
s->blend_row[0] = ff_overlay_row_44_sse4;
s->blend_row[1] = ff_overlay_row_22_sse4;
s->blend_row[2] = ff_overlay_row_22_sse4;
}
}
+57
View File
@@ -0,0 +1,57 @@
;*****************************************************************************
;* x86-optimized functions for pp7 filter
;*
;* Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg is free software; you can redistribute it and/or modify
;* it under the terms of the GNU General Public License as published by
;* the Free Software Foundation; either version 2 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 General Public License for more details.
;*
;* You should have received a copy of the GNU 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/x86/x86util.asm"
SECTION .text
INIT_MMX mmx
;void ff_pp7_dctB_mmx(int16_t *dst, int16_t *src)
cglobal pp7_dctB, 2, 2, 0, dst, src
movq m0, [srcq]
movq m1, [srcq+mmsize*1]
paddw m0, [srcq+mmsize*6]
paddw m1, [srcq+mmsize*5]
movq m2, [srcq+mmsize*2]
movq m3, [srcq+mmsize*3]
paddw m2, [srcq+mmsize*4]
paddw m3, m3
movq m4, m3
psubw m3, m0
paddw m4, m0
movq m0, m2
psubw m2, m1
paddw m0, m1
movq m1, m4
psubw m4, m0
paddw m1, m0
movq m0, m3
psubw m3, m2
psubw m3, m2
paddw m2, m0
paddw m2, m0
movq [dstq], m1
movq [dstq+mmsize*2], m4
movq [dstq+mmsize*1], m2
movq [dstq+mmsize*3], m3
RET
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/vf_pp7.h"
void ff_pp7_dctB_mmx(int16_t *dst, int16_t *src);
av_cold void ff_pp7_init_x86(PP7Context *p)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_MMX(cpu_flags))
p->dctB = ff_pp7_dctB_mmx;
}
+140
View File
@@ -0,0 +1,140 @@
;*****************************************************************************
;* x86-optimized functions for psnr filter
;*
;* Copyright (C) 2015 Ronald S. Bultje <rsbultje@gmail.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/x86/x86util.asm"
SECTION .text
%macro SSE_LINE_FN 2 ; 8 or 16, byte or word
INIT_XMM sse2
%if ARCH_X86_32
%if %1 == 8
cglobal sse_line_%1 %+ bit, 0, 6, 8, res, buf, w, px1, px2, ref
%else
cglobal sse_line_%1 %+ bit, 0, 7, 8, res, buf, reshigh, w, px1, px2, ref
%endif
mov bufq, r0mp
mov refq, r1mp
mov wd, r2m
%else
cglobal sse_line_%1 %+ bit, 3, 5, 8, buf, ref, w, px1, px2
%endif
pxor m6, m6
pxor m7, m7
sub wd, mmsize*2
jl .end
.loop:
movu m0, [bufq+mmsize*0]
movu m1, [bufq+mmsize*1]
movu m2, [refq+mmsize*0]
movu m3, [refq+mmsize*1]
%if %1 == 8
add bufq, mmsize*2
add refq, mmsize*2
psubusb m4, m0, m2
psubusb m5, m1, m3
psubusb m2, m0
psubusb m3, m1
por m2, m4
por m3, m5
punpcklbw m0, m2, m6
punpcklbw m1, m3, m6
punpckhbw m2, m6
punpckhbw m3, m6
%else
psubw m0, m2
psubw m1, m3
movu m2, [bufq+mmsize*2]
movu m3, [bufq+mmsize*3]
movu m4, [refq+mmsize*2]
movu m5, [refq+mmsize*3]
psubw m2, m4
psubw m3, m5
add bufq, mmsize*4
add refq, mmsize*4
%endif
pmaddwd m0, m0
pmaddwd m1, m1
pmaddwd m2, m2
pmaddwd m3, m3
paddd m0, m1
paddd m2, m3
%if %1 == 8
paddd m7, m0
paddd m7, m2
%else
paddd m0, m2
punpckldq m2, m0, m6
punpckhdq m0, m6
paddq m7, m0
paddq m7, m2
%endif
sub wd, mmsize*2
jge .loop
.end:
add wd, mmsize*2
movhlps m0, m7
%if %1 == 8
paddd m7, m0
pshufd m0, m7, 1
paddd m7, m0
movd eax, m7
%else
paddq m7, m0
%if ARCH_X86_32
movd eax, m7
psrldq m7, 4
movd edx, m7
%else
movq rax, m7
%endif
%endif
; deal with cases where w % 32 != 0
test wd, wd
jz .end_scalar
.loop_scalar:
movzx px1d, %2 [bufq+wq*(%1/8)-(%1/8)]
movzx px2d, %2 [refq+wq*(%1/8)-(%1/8)]
sub px1d, px2d
imul px1d, px1d
%if %1 == 8
add eax, px1d
%elif ARCH_X86_64
add rax, px1q
%else
add eax, px1d
adc edx, 0
%endif
dec wd
jg .loop_scalar
.end_scalar:
; for %1=8, no need to zero edx on x86-32, since edx=wd, which is zero
RET
%endmacro
INIT_XMM sse2
SSE_LINE_FN 8, byte
SSE_LINE_FN 16, word
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.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/x86/cpu.h"
#include "libavfilter/psnr.h"
uint64_t ff_sse_line_8bit_sse2(const uint8_t *buf, const uint8_t *ref, int w);
uint64_t ff_sse_line_16bit_sse2(const uint8_t *buf, const uint8_t *ref, int w);
void ff_psnr_init_x86(PSNRDSPContext *dsp, int bpp)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE2(cpu_flags)) {
if (bpp <= 8) {
dsp->sse_line = ff_sse_line_8bit_sse2;
} else if (bpp <= 15) {
dsp->sse_line = ff_sse_line_16bit_sse2;
}
}
}
+178
View File
@@ -0,0 +1,178 @@
;*****************************************************************************
;* x86-optimized functions for pullup filter
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg is free software; you can redistribute it and/or modify
;* it under the terms of the GNU General Public License as published by
;* the Free Software Foundation; either version 2 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 General Public License for more details.
;*
;* You should have received a copy of the GNU 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/x86/x86util.asm"
SECTION .text
INIT_MMX mmx
cglobal pullup_filter_diff, 3, 5, 8, first, second, size
mov r3, 4
pxor m4, m4
pxor m7, m7
.loop:
movq m0, [firstq]
movq m2, [firstq]
add firstq, sizeq
movq m1, [secondq]
add secondq, sizeq
psubusb m2, m1
psubusb m1, m0
movq m0, m2
movq m3, m1
punpcklbw m0, m7
punpcklbw m1, m7
punpckhbw m2, m7
punpckhbw m3, m7
paddw m4, m0
paddw m4, m1
paddw m4, m2
paddw m4, m3
dec r3
jnz .loop
movq m3, m4
punpcklwd m4, m7
punpckhwd m3, m7
paddd m3, m4
movd eax, m3
psrlq m3, 32
movd r4d, m3
add eax, r4d
RET
INIT_MMX mmx
cglobal pullup_filter_comb, 3, 5, 8, first, second, size
mov r3, 4
pxor m6, m6
pxor m7, m7
sub secondq, sizeq
.loop:
movq m0, [firstq]
movq m1, [secondq]
punpcklbw m0, m7
movq m2, [secondq+sizeq]
punpcklbw m1, m7
punpcklbw m2, m7
paddw m0, m0
paddw m1, m2
movq m2, m0
psubusw m0, m1
psubusw m1, m2
paddw m6, m0
paddw m6, m1
movq m0, [firstq]
movq m1, [secondq]
punpckhbw m0, m7
movq m2, [secondq+sizeq]
punpckhbw m1, m7
punpckhbw m2, m7
paddw m0, m0
paddw m1, m2
movq m2, m0
psubusw m0, m1
psubusw m1, m2
paddw m6, m0
paddw m6, m1
movq m0, [secondq+sizeq]
movq m1, [firstq]
punpcklbw m0, m7
movq m2, [firstq+sizeq]
punpcklbw m1, m7
punpcklbw m2, m7
paddw m0, m0
paddw m1, m2
movq m2, m0
psubusw m0, m1
psubusw m1, m2
paddw m6, m0
paddw m6, m1
movq m0, [secondq+sizeq]
movq m1, [firstq]
punpckhbw m0, m7
movq m2, [firstq+sizeq]
punpckhbw m1, m7
punpckhbw m2, m7
paddw m0, m0
paddw m1, m2
movq m2, m0
psubusw m0, m1
psubusw m1, m2
paddw m6, m0
paddw m6, m1
add firstq, sizeq
add secondq, sizeq
dec r3
jnz .loop
movq m5, m6
punpcklwd m6, m7
punpckhwd m5, m7
paddd m5, m6
movd eax, m5
psrlq m5, 32
movd r4d, m5
add eax, r4d
RET
INIT_MMX mmx
cglobal pullup_filter_var, 3, 5, 8, first, second, size
mov r3, 3
pxor m4, m4
pxor m7, m7
.loop:
movq m0, [firstq]
movq m2, [firstq]
movq m1, [firstq+sizeq]
add firstq, sizeq
psubusb m2, m1
psubusb m1, m0
movq m0, m2
movq m3, m1
punpcklbw m0, m7
punpcklbw m1, m7
punpckhbw m2, m7
punpckhbw m3, m7
paddw m4, m0
paddw m4, m1
paddw m4, m2
paddw m4, m3
dec r3
jnz .loop
movq m3, m4
punpcklwd m4, m7
punpckhwd m3, m7
paddd m3, m4
movd eax, m3
psrlq m3, 32
movd r4d, m3
add eax, r4d
shl eax, 2
RET
+40
View File
@@ -0,0 +1,40 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/vf_pullup.h"
int ff_pullup_filter_diff_mmx(const uint8_t *a, const uint8_t *b, ptrdiff_t s);
int ff_pullup_filter_comb_mmx(const uint8_t *a, const uint8_t *b, ptrdiff_t s);
int ff_pullup_filter_var_mmx (const uint8_t *a, const uint8_t *b, ptrdiff_t s);
av_cold void ff_pullup_init_x86(PullupContext *s)
{
#if HAVE_X86ASM
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_MMX(cpu_flags)) {
s->diff = ff_pullup_filter_diff_mmx;
s->comb = ff_pullup_filter_comb_mmx;
s->var = ff_pullup_filter_var_mmx;
}
#endif
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2015 James Darnley
*
* 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/removegrain.h"
void ff_rg_fl_mode_1_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_10_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_11_12_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_13_14_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_19_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_20_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_21_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_22_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
#if ARCH_X86_64
void ff_rg_fl_mode_2_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_3_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_4_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_5_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_6_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_7_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_8_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_9_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_15_16_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_17_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_18_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_23_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
void ff_rg_fl_mode_24_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int pixels);
#endif
av_cold void ff_removegrain_init_x86(RemoveGrainContext *rg)
{
#if CONFIG_GPL
int cpu_flags = av_get_cpu_flags();
int i;
for (i = 0; i < rg->nb_planes; i++) {
if (EXTERNAL_SSE2(cpu_flags))
switch (rg->mode[i]) {
case 1: rg->fl[i] = ff_rg_fl_mode_1_sse2; break;
case 10: rg->fl[i] = ff_rg_fl_mode_10_sse2; break;
case 11: /* fall through */
case 12: rg->fl[i] = ff_rg_fl_mode_11_12_sse2; break;
case 13: /* fall through */
case 14: rg->fl[i] = ff_rg_fl_mode_13_14_sse2; break;
case 19: rg->fl[i] = ff_rg_fl_mode_19_sse2; break;
case 20: rg->fl[i] = ff_rg_fl_mode_20_sse2; break;
case 21: rg->fl[i] = ff_rg_fl_mode_21_sse2; break;
case 22: rg->fl[i] = ff_rg_fl_mode_22_sse2; break;
#if ARCH_X86_64
case 2: rg->fl[i] = ff_rg_fl_mode_2_sse2; break;
case 3: rg->fl[i] = ff_rg_fl_mode_3_sse2; break;
case 4: rg->fl[i] = ff_rg_fl_mode_4_sse2; break;
case 5: rg->fl[i] = ff_rg_fl_mode_5_sse2; break;
case 6: rg->fl[i] = ff_rg_fl_mode_6_sse2; break;
case 7: rg->fl[i] = ff_rg_fl_mode_7_sse2; break;
case 8: rg->fl[i] = ff_rg_fl_mode_8_sse2; break;
case 9: rg->fl[i] = ff_rg_fl_mode_9_sse2; break;
case 15: /* fall through */
case 16: rg->fl[i] = ff_rg_fl_mode_15_16_sse2; break;
case 17: rg->fl[i] = ff_rg_fl_mode_17_sse2; break;
case 18: rg->fl[i] = ff_rg_fl_mode_18_sse2; break;
case 23: rg->fl[i] = ff_rg_fl_mode_23_sse2; break;
case 24: rg->fl[i] = ff_rg_fl_mode_24_sse2; break;
#endif /* ARCH_x86_64 */
}
}
#endif /* CONFIG_GPL */
}
+242
View File
@@ -0,0 +1,242 @@
/*
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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/cpu.h"
#include "libavutil/crc.h"
#include "libavutil/x86/asm.h"
#include "libavfilter/vf_spp.h"
#if HAVE_MMX_INLINE
static void hardthresh_mmx(int16_t dst[64], const int16_t src[64],
int qp, const uint8_t *permutation)
{
int bias = 0; //FIXME
unsigned int threshold1;
threshold1 = qp * ((1<<4) - bias) - 1;
#define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \
"movq " #src0 ", %%mm0 \n" \
"movq " #src1 ", %%mm1 \n" \
"movq " #src2 ", %%mm2 \n" \
"movq " #src3 ", %%mm3 \n" \
"psubw %%mm4, %%mm0 \n" \
"psubw %%mm4, %%mm1 \n" \
"psubw %%mm4, %%mm2 \n" \
"psubw %%mm4, %%mm3 \n" \
"paddusw %%mm5, %%mm0 \n" \
"paddusw %%mm5, %%mm1 \n" \
"paddusw %%mm5, %%mm2 \n" \
"paddusw %%mm5, %%mm3 \n" \
"paddw %%mm6, %%mm0 \n" \
"paddw %%mm6, %%mm1 \n" \
"paddw %%mm6, %%mm2 \n" \
"paddw %%mm6, %%mm3 \n" \
"psubusw %%mm6, %%mm0 \n" \
"psubusw %%mm6, %%mm1 \n" \
"psubusw %%mm6, %%mm2 \n" \
"psubusw %%mm6, %%mm3 \n" \
"psraw $3, %%mm0 \n" \
"psraw $3, %%mm1 \n" \
"psraw $3, %%mm2 \n" \
"psraw $3, %%mm3 \n" \
\
"movq %%mm0, %%mm7 \n" \
"punpcklwd %%mm2, %%mm0 \n" /*A*/ \
"punpckhwd %%mm2, %%mm7 \n" /*C*/ \
"movq %%mm1, %%mm2 \n" \
"punpcklwd %%mm3, %%mm1 \n" /*B*/ \
"punpckhwd %%mm3, %%mm2 \n" /*D*/ \
"movq %%mm0, %%mm3 \n" \
"punpcklwd %%mm1, %%mm0 \n" /*A*/ \
"punpckhwd %%mm7, %%mm3 \n" /*C*/ \
"punpcklwd %%mm2, %%mm7 \n" /*B*/ \
"punpckhwd %%mm2, %%mm1 \n" /*D*/ \
\
"movq %%mm0, " #dst0 " \n" \
"movq %%mm7, " #dst1 " \n" \
"movq %%mm3, " #dst2 " \n" \
"movq %%mm1, " #dst3 " \n"
__asm__ volatile(
"movd %2, %%mm4 \n"
"movd %3, %%mm5 \n"
"movd %4, %%mm6 \n"
"packssdw %%mm4, %%mm4 \n"
"packssdw %%mm5, %%mm5 \n"
"packssdw %%mm6, %%mm6 \n"
"packssdw %%mm4, %%mm4 \n"
"packssdw %%mm5, %%mm5 \n"
"packssdw %%mm6, %%mm6 \n"
REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0))
REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0))
REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0))
REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0))
: : "r" (src), "r" (dst), "g" (threshold1+1), "g" (threshold1+5), "g" (threshold1-4) //FIXME maybe more accurate then needed?
);
dst[0] = (src[0] + 4) >> 3;
}
static void softthresh_mmx(int16_t dst[64], const int16_t src[64],
int qp, const uint8_t *permutation)
{
int bias = 0; //FIXME
unsigned int threshold1;
threshold1 = qp*((1<<4) - bias) - 1;
#undef REQUANT_CORE
#define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \
"movq " #src0 ", %%mm0 \n" \
"movq " #src1 ", %%mm1 \n" \
"pxor %%mm6, %%mm6 \n" \
"pxor %%mm7, %%mm7 \n" \
"pcmpgtw %%mm0, %%mm6 \n" \
"pcmpgtw %%mm1, %%mm7 \n" \
"pxor %%mm6, %%mm0 \n" \
"pxor %%mm7, %%mm1 \n" \
"psubusw %%mm4, %%mm0 \n" \
"psubusw %%mm4, %%mm1 \n" \
"pxor %%mm6, %%mm0 \n" \
"pxor %%mm7, %%mm1 \n" \
"movq " #src2 ", %%mm2 \n" \
"movq " #src3 ", %%mm3 \n" \
"pxor %%mm6, %%mm6 \n" \
"pxor %%mm7, %%mm7 \n" \
"pcmpgtw %%mm2, %%mm6 \n" \
"pcmpgtw %%mm3, %%mm7 \n" \
"pxor %%mm6, %%mm2 \n" \
"pxor %%mm7, %%mm3 \n" \
"psubusw %%mm4, %%mm2 \n" \
"psubusw %%mm4, %%mm3 \n" \
"pxor %%mm6, %%mm2 \n" \
"pxor %%mm7, %%mm3 \n" \
\
"paddsw %%mm5, %%mm0 \n" \
"paddsw %%mm5, %%mm1 \n" \
"paddsw %%mm5, %%mm2 \n" \
"paddsw %%mm5, %%mm3 \n" \
"psraw $3, %%mm0 \n" \
"psraw $3, %%mm1 \n" \
"psraw $3, %%mm2 \n" \
"psraw $3, %%mm3 \n" \
\
"movq %%mm0, %%mm7 \n" \
"punpcklwd %%mm2, %%mm0 \n" /*A*/ \
"punpckhwd %%mm2, %%mm7 \n" /*C*/ \
"movq %%mm1, %%mm2 \n" \
"punpcklwd %%mm3, %%mm1 \n" /*B*/ \
"punpckhwd %%mm3, %%mm2 \n" /*D*/ \
"movq %%mm0, %%mm3 \n" \
"punpcklwd %%mm1, %%mm0 \n" /*A*/ \
"punpckhwd %%mm7, %%mm3 \n" /*C*/ \
"punpcklwd %%mm2, %%mm7 \n" /*B*/ \
"punpckhwd %%mm2, %%mm1 \n" /*D*/ \
\
"movq %%mm0, " #dst0 " \n" \
"movq %%mm7, " #dst1 " \n" \
"movq %%mm3, " #dst2 " \n" \
"movq %%mm1, " #dst3 " \n"
__asm__ volatile(
"movd %2, %%mm4 \n"
"movd %3, %%mm5 \n"
"packssdw %%mm4, %%mm4 \n"
"packssdw %%mm5, %%mm5 \n"
"packssdw %%mm4, %%mm4 \n"
"packssdw %%mm5, %%mm5 \n"
REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0))
REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0))
REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0))
REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0))
: : "r" (src), "r" (dst), "g" (threshold1), "rm" (4) //FIXME maybe more accurate then needed?
);
dst[0] = (src[0] + 4) >> 3;
}
static void store_slice_mmx(uint8_t *dst, const int16_t *src,
int dst_stride, int src_stride,
int width, int height, int log2_scale,
const uint8_t dither[8][8])
{
int y;
for (y = 0; y < height; y++) {
uint8_t *dst1 = dst;
const int16_t *src1 = src;
__asm__ volatile(
"movq (%3), %%mm3 \n"
"movq (%3), %%mm4 \n"
"movd %4, %%mm2 \n"
"pxor %%mm0, %%mm0 \n"
"punpcklbw %%mm0, %%mm3 \n"
"punpckhbw %%mm0, %%mm4 \n"
"psraw %%mm2, %%mm3 \n"
"psraw %%mm2, %%mm4 \n"
"movd %5, %%mm2 \n"
"1: \n"
"movq (%0), %%mm0 \n"
"movq 8(%0), %%mm1 \n"
"paddw %%mm3, %%mm0 \n"
"paddw %%mm4, %%mm1 \n"
"psraw %%mm2, %%mm0 \n"
"psraw %%mm2, %%mm1 \n"
"packuswb %%mm1, %%mm0 \n"
"movq %%mm0, (%1) \n"
"add $16, %0 \n"
"add $8, %1 \n"
"cmp %2, %1 \n"
" jb 1b \n"
: "+r" (src1), "+r"(dst1)
: "r"(dst + width), "r"(dither[y]), "g"(log2_scale), "g"(MAX_LEVEL - log2_scale)
);
src += src_stride;
dst += dst_stride;
}
}
#endif /* HAVE_MMX_INLINE */
av_cold void ff_spp_init_x86(SPPContext *s)
{
#if HAVE_MMX_INLINE
int cpu_flags = av_get_cpu_flags();
if (cpu_flags & AV_CPU_FLAG_MMX) {
static const uint32_t mmx_idct_perm_crc = 0xe5e8adc4;
uint32_t idct_perm_crc =
av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0,
s->dct->idct_permutation,
sizeof(s->dct->idct_permutation));
int64_t bps;
s->store_slice = store_slice_mmx;
av_opt_get_int(s->dct, "bits_per_sample", 0, &bps);
if (bps <= 8 && idct_perm_crc == mmx_idct_perm_crc) {
switch (s->mode) {
case 0: s->requantize = hardthresh_mmx; break;
case 1: s->requantize = softthresh_mmx; break;
}
}
}
#endif
}
+257
View File
@@ -0,0 +1,257 @@
;*****************************************************************************
;* x86-optimized functions for ssim filter
;*
;* Copyright (C) 2015 Ronald S. Bultje <rsbultje@gmail.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/x86/x86util.asm"
SECTION_RODATA
pw_1: times 8 dw 1
ssim_c1: times 4 dd 416 ;(.01*.01*255*255*64 + .5)
ssim_c2: times 4 dd 235963 ;(.03*.03*255*255*64*63 + .5)
SECTION .text
%macro SSIM_4X4_LINE 1
%if ARCH_X86_64
cglobal ssim_4x4_line, 6, 8, %1, buf, buf_stride, ref, ref_stride, sums, w, buf_stride3, ref_stride3
%else
cglobal ssim_4x4_line, 5, 7, %1, buf, buf_stride, ref, ref_stride, sums, buf_stride3, ref_stride3
%define wd r5mp
%endif
lea ref_stride3q, [ref_strideq*3]
lea buf_stride3q, [buf_strideq*3]
%if notcpuflag(xop)
pxor m7, m7
mova m15, [pw_1]
%endif
.loop:
%if cpuflag(xop)
pmovzxbw m0, [bufq+buf_strideq*0]
pmovzxbw m1, [refq+ref_strideq*0]
pmaddwd m4, m0, m0
pmaddwd m6, m0, m1
pmovzxbw m2, [bufq+buf_strideq*1]
vpmadcswd m4, m1, m1, m4
pmovzxbw m3, [refq+ref_strideq*1]
paddw m0, m2
vpmadcswd m4, m2, m2, m4
vpmadcswd m6, m2, m3, m6
paddw m1, m3
vpmadcswd m4, m3, m3, m4
pmovzxbw m2, [bufq+buf_strideq*2]
pmovzxbw m3, [refq+ref_strideq*2]
vpmadcswd m4, m2, m2, m4
vpmadcswd m6, m2, m3, m6
pmovzxbw m5, [bufq+buf_stride3q]
pmovzxbw m7, [refq+ref_stride3q]
vpmadcswd m4, m3, m3, m4
vpmadcswd m6, m5, m7, m6
paddw m0, m2
paddw m1, m3
vpmadcswd m4, m5, m5, m4
paddw m0, m5
paddw m1, m7
vpmadcswd m4, m7, m7, m4
%else
movh m0, [bufq+buf_strideq*0] ; a1
movh m1, [refq+ref_strideq*0] ; b1
movh m2, [bufq+buf_strideq*1] ; a2
movh m3, [refq+ref_strideq*1] ; b2
punpcklbw m0, m7 ; s1 [word]
punpcklbw m1, m7 ; s2 [word]
punpcklbw m2, m7 ; s1 [word]
punpcklbw m3, m7 ; s2 [word]
pmaddwd m4, m0, m0 ; a1 * a1
pmaddwd m5, m1, m1 ; b1 * b1
pmaddwd m8, m2, m2 ; a2 * a2
pmaddwd m9, m3, m3 ; b2 * b2
paddd m4, m5 ; ss
paddd m8, m9 ; ss
pmaddwd m6, m0, m1 ; a1 * b1 = ss12
pmaddwd m5, m2, m3 ; a2 * b2 = ss12
paddw m0, m2
paddw m1, m3
paddd m6, m5 ; s12
paddd m4, m8 ; ss
movh m2, [bufq+buf_strideq*2] ; a3
movh m3, [refq+ref_strideq*2] ; b3
movh m5, [bufq+buf_stride3q] ; a4
movh m8, [refq+ref_stride3q] ; b4
punpcklbw m2, m7 ; s1 [word]
punpcklbw m3, m7 ; s2 [word]
punpcklbw m5, m7 ; s1 [word]
punpcklbw m8, m7 ; s2 [word]
pmaddwd m9, m2, m2 ; a3 * a3
pmaddwd m10, m3, m3 ; b3 * b3
pmaddwd m12, m5, m5 ; a4 * a4
pmaddwd m13, m8, m8 ; b4 * b4
pmaddwd m11, m2, m3 ; a3 * b3 = ss12
pmaddwd m14, m5, m8 ; a4 * b4 = ss12
paddd m9, m10
paddd m12, m13
paddw m0, m2
paddw m1, m3
paddw m0, m5
paddw m1, m8
paddd m6, m11
paddd m4, m9
paddd m6, m14
paddd m4, m12
%endif
; m0 = [word] s1 a,a,a,a,b,b,b,b
; m1 = [word] s2 a,a,a,a,b,b,b,b
; m4 = [dword] ss a,a,b,b
; m6 = [dword] s12 a,a,b,b
%if cpuflag(xop)
vphaddwq m0, m0 ; [dword] s1 a, 0, b, 0
vphaddwq m1, m1 ; [dword] s2 a, 0, b, 0
vphadddq m4, m4 ; [dword] ss a, 0, b, 0
vphadddq m6, m6 ; [dword] s12 a, 0, b, 0
punpckhdq m2, m0, m1 ; [dword] s1 b, s2 b, 0, 0
punpckldq m0, m1 ; [dword] s1 a, s2 a, 0, 0
punpckhdq m3, m4, m6 ; [dword] ss b, s12 b, 0, 0
punpckldq m4, m6 ; [dword] ss a, s12 a, 0, 0
punpcklqdq m1, m2, m3 ; [dword] b s1, s2, ss, s12
punpcklqdq m0, m4 ; [dword] a s1, s2, ss, s12
%else
pmaddwd m0, m15 ; [dword] s1 a,a,b,b
pmaddwd m1, m15 ; [dword] s2 a,a,b,b
phaddd m0, m4 ; [dword] s1 a, b, ss a, b
phaddd m1, m6 ; [dword] s2 a, b, s12 a, b
punpckhdq m2, m0, m1 ; [dword] ss a, s12 a, ss b, s12 b
punpckldq m0, m1 ; [dword] s1 a, s2 a, s1 b, s2 b
punpckhqdq m1, m0, m2 ; [dword] b s1, s2, ss, s12
punpcklqdq m0, m2 ; [dword] a s1, s2, ss, s12
%endif
mova [sumsq+ 0], m0
mova [sumsq+mmsize], m1
add bufq, mmsize/2
add refq, mmsize/2
add sumsq, mmsize*2
sub wd, mmsize/8
jg .loop
RET
%endmacro
%if ARCH_X86_64
INIT_XMM ssse3
SSIM_4X4_LINE 16
%endif
%if HAVE_XOP_EXTERNAL
INIT_XMM xop
SSIM_4X4_LINE 8
%endif
INIT_XMM sse4
cglobal ssim_end_line, 3, 3, 7, sum0, sum1, w
pxor m0, m0
pxor m6, m6
.loop:
mova m1, [sum0q+mmsize*0]
mova m2, [sum0q+mmsize*1]
mova m3, [sum0q+mmsize*2]
mova m4, [sum0q+mmsize*3]
paddd m1, [sum1q+mmsize*0]
paddd m2, [sum1q+mmsize*1]
paddd m3, [sum1q+mmsize*2]
paddd m4, [sum1q+mmsize*3]
paddd m1, m2
paddd m2, m3
paddd m3, m4
paddd m4, [sum0q+mmsize*4]
paddd m4, [sum1q+mmsize*4]
TRANSPOSE4x4D 1, 2, 3, 4, 5
; m1 = fs1, m2 = fs2, m3 = fss, m4 = fs12
pslld m3, 6
pslld m4, 6
pmulld m5, m1, m2 ; fs1 * fs2
pmulld m1, m1 ; fs1 * fs1
pmulld m2, m2 ; fs2 * fs2
psubd m3, m1
psubd m4, m5 ; covariance
psubd m3, m2 ; variance
; m1 = fs1 * fs1, m2 = fs2 * fs2, m3 = variance, m4 = covariance, m5 = fs1 * fs2
paddd m4, m4 ; 2 * covariance
paddd m5, m5 ; 2 * fs1 * fs2
paddd m1, m2 ; fs1 * fs1 + fs2 * fs2
paddd m3, [ssim_c2] ; variance + ssim_c2
paddd m4, [ssim_c2] ; 2 * covariance + ssim_c2
paddd m5, [ssim_c1] ; 2 * fs1 * fs2 + ssim_c1
paddd m1, [ssim_c1] ; fs1 * fs1 + fs2 * fs2 + ssim_c1
; convert to float
cvtdq2ps m3, m3
cvtdq2ps m4, m4
cvtdq2ps m5, m5
cvtdq2ps m1, m1
mulps m4, m5
mulps m3, m1
divps m4, m3 ; ssim_endl
mova m5, m4
cvtps2pd m3, m5
movhlps m5, m5
cvtps2pd m5, m5
addpd m0, m3 ; ssim
addpd m6, m5 ; ssim
add sum0q, mmsize*4
add sum1q, mmsize*4
sub wd, 4
jg .loop
; subpd the ones we added too much
test wd, wd
jz .end
add wd, 4
cmp wd, 1
jz .skip3
cmp wd, 2
jz .skip2
.skip1: ; 3 valid => skip 1 invalid
psrldq m5, 8
subpd m6, m5
jmp .end
.skip2: ; 2 valid => skip 2 invalid
subpd m6, m5
jmp .end
.skip3: ; 1 valid => skip 3 invalid
psrldq m3, 8
subpd m0, m3
subpd m6, m5
.end:
addpd m0, m6
movhlps m4, m0
addpd m0, m4
%if ARCH_X86_32
movsd r0m, m0
fld qword r0m
%endif
RET
+43
View File
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.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/x86/cpu.h"
#include "libavfilter/ssim.h"
void ff_ssim_4x4_line_ssse3(const uint8_t *buf, ptrdiff_t buf_stride,
const uint8_t *ref, ptrdiff_t ref_stride,
int (*sums)[4], int w);
void ff_ssim_4x4_line_xop (const uint8_t *buf, ptrdiff_t buf_stride,
const uint8_t *ref, ptrdiff_t ref_stride,
int (*sums)[4], int w);
double ff_ssim_end_line_sse4(const int (*sum0)[4], const int (*sum1)[4], int w);
void ff_ssim_init_x86(SSIMDSPContext *dsp)
{
int cpu_flags = av_get_cpu_flags();
if (ARCH_X86_64 && EXTERNAL_SSSE3(cpu_flags))
dsp->ssim_4x4_line = ff_ssim_4x4_line_ssse3;
if (EXTERNAL_SSE4(cpu_flags))
dsp->ssim_end_line = ff_ssim_end_line_sse4;
if (EXTERNAL_XOP(cpu_flags))
dsp->ssim_4x4_line = ff_ssim_4x4_line_xop;
}
+216
View File
@@ -0,0 +1,216 @@
;*****************************************************************************
;* x86-optimized functions for stereo3d filter
;*
;* Copyright (C) 2015 Paul B Mahol
;*
;* 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/x86/x86util.asm"
SECTION_RODATA
; rgbrgbrgbrgb
; rrrrggggbbbb
shuf: db 0, 4, 8, 1,5, 9, 2, 6,10,3, 7,11,-1,-1,-1,-1
ex_r: db 0,-1,-1,-1,3,-1,-1,-1,6,-1,-1,-1, 9,-1,-1,-1
ex_g: db 1,-1,-1,-1,4,-1,-1,-1,7,-1,-1,-1,10,-1,-1,-1
ex_b: db 2,-1,-1,-1,5,-1,-1,-1,8,-1,-1,-1,11,-1,-1,-1
SECTION .text
INIT_XMM sse4
%if ARCH_X86_64
cglobal anaglyph, 6, 10, 14, 2*6*mmsize, dst, lsrc, rsrc, dst_linesize, l_linesize, r_linesize, width, height, o, cnt
%define ana_matrix_rq r6q
%define ana_matrix_gq r7q
%define ana_matrix_bq r8q
%else ; ARCH_X86_32
%if HAVE_ALIGNED_STACK
cglobal anaglyph, 3, 7, 8, 2*9*mmsize, dst, lsrc, rsrc, dst_linesize, l_linesize, o, cnt
%else
cglobal anaglyph, 3, 6, 8, 2*9*mmsize, dst, lsrc, rsrc, dst_linesize, o, cnt
%define l_linesizeq r4mp
%endif ; HAVE_ALIGNED_STACK
%define ana_matrix_rq r3q
%define ana_matrix_gq r4q
%define ana_matrix_bq r5q
%define r_linesizeq r5mp
%define widthd r6mp
%define heightd r7mp
%define m8 [rsp+mmsize*12]
%define m9 [rsp+mmsize*13]
%define m10 [rsp+mmsize*14]
%define m11 [rsp+mmsize*15]
%define m12 [rsp+mmsize*16]
%define m13 [rsp+mmsize*17]
%endif ; ARCH
mov ana_matrix_rq, r8m
mov ana_matrix_gq, r9m
mov ana_matrix_bq, r10m
movu m3, [ana_matrix_rq+ 0]
movq m5, [ana_matrix_rq+16]
pshufd m0, m3, q0000
pshufd m1, m3, q1111
pshufd m2, m3, q2222
pshufd m3, m3, q3333
pshufd m4, m5, q0000
pshufd m5, m5, q1111
mova [rsp+mmsize*0], m0
mova [rsp+mmsize*1], m1
mova [rsp+mmsize*2], m2
mova [rsp+mmsize*3], m3
mova [rsp+mmsize*4], m4
mova [rsp+mmsize*5], m5
movu m3, [ana_matrix_gq+ 0]
movq m5, [ana_matrix_gq+16]
pshufd m0, m3, q0000
pshufd m1, m3, q1111
pshufd m2, m3, q2222
pshufd m3, m3, q3333
pshufd m4, m5, q0000
pshufd m5, m5, q1111
mova [rsp+mmsize*6 ], m0
mova [rsp+mmsize*7 ], m1
mova [rsp+mmsize*8 ], m2
mova [rsp+mmsize*9 ], m3
mova [rsp+mmsize*10], m4
mova [rsp+mmsize*11], m5
%if ARCH_X86_64
movu m11, [ana_matrix_bq+ 0]
movq m13, [ana_matrix_bq+16]
pshufd m8, m11, q0000
pshufd m9, m11, q1111
pshufd m10, m11, q2222
pshufd m11, m11, q3333
pshufd m12, m13, q0000
pshufd m13, m13, q1111
mov widthd, dword widthm
mov heightd, dword heightm
%else
movu m3, [ana_matrix_bq+ 0]
movq m5, [ana_matrix_bq+16]
pshufd m0, m3, q0000
pshufd m1, m3, q1111
pshufd m2, m3, q2222
pshufd m3, m3, q3333
pshufd m4, m5, q0000
pshufd m5, m5, q1111
mova [rsp+mmsize*12], m0
mova [rsp+mmsize*13], m1
mova [rsp+mmsize*14], m2
mova [rsp+mmsize*15], m3
mova [rsp+mmsize*16], m4
mova [rsp+mmsize*17], m5
mov dst_linesizeq, r3m
%if HAVE_ALIGNED_STACK
mov l_linesizeq, r4m
%endif
%endif ; ARCH
.nextrow:
mov od, widthd
xor cntd, cntd
.loop:
movu m3, [lsrcq+cntq]
pshufb m1, m3, [ex_r]
pshufb m2, m3, [ex_g]
pshufb m3, [ex_b]
movu m0, [rsrcq+cntq]
pshufb m4, m0, [ex_r]
pshufb m5, m0, [ex_g]
pshufb m0, [ex_b]
pmulld m1, [rsp+mmsize*0]
pmulld m2, [rsp+mmsize*1]
pmulld m3, [rsp+mmsize*2]
pmulld m4, [rsp+mmsize*3]
pmulld m5, [rsp+mmsize*4]
pmulld m0, [rsp+mmsize*5]
paddd m1, m2
paddd m3, m4
paddd m5, m0
paddd m1, m3
paddd m1, m5
movu m3, [lsrcq+cntq]
pshufb m7, m3, [ex_r]
pshufb m2, m3, [ex_g]
pshufb m3, [ex_b]
movu m0, [rsrcq+cntq]
pshufb m4, m0, [ex_r]
pshufb m5, m0, [ex_g]
pshufb m0, [ex_b]
pmulld m7, [rsp+mmsize*6]
pmulld m2, [rsp+mmsize*7]
pmulld m3, [rsp+mmsize*8]
pmulld m4, [rsp+mmsize*9]
pmulld m5, [rsp+mmsize*10]
pmulld m0, [rsp+mmsize*11]
paddd m7, m2
paddd m3, m4
paddd m5, m0
paddd m7, m3
paddd m7, m5
movu m4, [lsrcq+cntq]
pshufb m2, m4, [ex_r]
pshufb m3, m4, [ex_g]
pshufb m4, [ex_b]
movu m0, [rsrcq+cntq]
pshufb m5, m0, [ex_r]
pshufb m6, m0, [ex_g]
pshufb m0, [ex_b]
pmulld m2, m8
pmulld m3, m9
pmulld m4, m10
pmulld m5, m11
pmulld m6, m12
pmulld m0, m13
paddd m2, m3
paddd m4, m5
paddd m6, m0
paddd m2, m4
paddd m2, m6
psrld m1, 16
psrld m7, 16
psrld m2, 16
packusdw m1, m7
packusdw m2, m2
packuswb m1, m2
pshufb m1, [shuf]
movq [dstq+cntq+0], m1
psrldq m1, 8
movd [dstq+cntq+8], m1
add cntd, 12
sub od, 4
jg .loop
add dstq, dst_linesizeq
add lsrcq, l_linesizeq
add rsrcq, r_linesizeq
sub heightd, 1
jg .nextrow
RET
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2015 Paul B Mahol
*
* 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/x86/cpu.h"
#include "libavfilter/stereo3d.h"
void ff_anaglyph_sse4(uint8_t *dst, uint8_t *lsrc, uint8_t *rsrc,
ptrdiff_t dst_linesize, ptrdiff_t l_linesize, ptrdiff_t r_linesize,
int width, int height,
const int *ana_matrix_r, const int *ana_matrix_g, const int *ana_matrix_b);
void ff_stereo3d_init_x86(Stereo3DDSPContext *dsp)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE4(cpu_flags)) {
dsp->anaglyph = ff_anaglyph_sse4;
}
}
+85
View File
@@ -0,0 +1,85 @@
;*****************************************************************************
;* x86-optimized functions for threshold filter
;*
;* Copyright (C) 2017 Paul B Mahol
;*
;* 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/x86/x86util.asm"
SECTION .text
;%1 depth (8 or 16) ; %2 b or w
%macro THRESHOLD 2
%if ARCH_X86_64
cglobal threshold%1, 10, 13, 5, in, threshold, min, max, out, ilinesize, tlinesize, flinesize, slinesize, olinesize, w, h, x
mov wd, dword wm
mov hd, dword hm
%else
cglobal threshold%1, 5, 7, 5, in, threshold, min, max, out, w, x
mov wd, r10m
%define ilinesizeq r5mp
%define tlinesizeq r6mp
%define flinesizeq r7mp
%define slinesizeq r8mp
%define olinesizeq r9mp
%define hd r11mp
%endif
%if %1 == 16
add wq, wq ; w *= 2 (16 bits instead of 8)
%endif
add inq, wq
add thresholdq, wq
add minq, wq
add maxq, wq
add outq, wq
neg wq
.nextrow:
mov xq, wq
.loop:
movu m1, [inq + xq]
movu m0, [thresholdq + xq]
movu m2, [minq + xq]
movu m3, [maxq + xq]
pminu%2 m0, m1
pcmpeq%2 m0, m1
PBLENDVB m3, m2, m0
movu [outq + xq], m3
add xq, mmsize
jl .loop
add inq, ilinesizeq
add thresholdq, tlinesizeq
add minq, flinesizeq
add maxq, slinesizeq
add outq, olinesizeq
sub hd, 1
jg .nextrow
RET
%endmacro
INIT_XMM sse4
THRESHOLD 8, b
THRESHOLD 16, w
%if HAVE_AVX2_EXTERNAL
INIT_YMM avx2
THRESHOLD 8, b
THRESHOLD 16, w
%endif
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2015 Paul B Mahol
*
* 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/threshold.h"
#define THRESHOLD_FUNC(depth, opt) \
void ff_threshold##depth##_##opt(const uint8_t *in, const uint8_t *threshold,\
const uint8_t *min, const uint8_t *max, \
uint8_t *out, \
ptrdiff_t ilinesize, ptrdiff_t tlinesize, \
ptrdiff_t flinesize, ptrdiff_t slinesize, \
ptrdiff_t olinesize, \
int w, int h);
THRESHOLD_FUNC(8, sse4)
THRESHOLD_FUNC(8, avx2)
THRESHOLD_FUNC(16, sse4)
THRESHOLD_FUNC(16, avx2)
av_cold void ff_threshold_init_x86(ThresholdContext *s)
{
int cpu_flags = av_get_cpu_flags();
if (s->depth == 8) {
if (EXTERNAL_SSE4(cpu_flags)) {
s->threshold = ff_threshold8_sse4;
}
if (EXTERNAL_AVX2_FAST(cpu_flags)) {
s->threshold = ff_threshold8_avx2;
}
} else if (s->depth == 16) {
if (EXTERNAL_SSE4(cpu_flags)) {
s->threshold = ff_threshold16_sse4;
}
if (EXTERNAL_AVX2_FAST(cpu_flags)) {
s->threshold = ff_threshold16_avx2;
}
}
}
@@ -0,0 +1,92 @@
/*
* Copyright (C) 2014 Kieran Kunhya <kierank@obe.tv>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU 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/cpu.h"
#include "libavutil/internal.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/tinterlace.h"
void ff_lowpass_line_sse2(uint8_t *dstp, ptrdiff_t linesize,
const uint8_t *srcp, ptrdiff_t mref,
ptrdiff_t pref, int clip_max);
void ff_lowpass_line_avx (uint8_t *dstp, ptrdiff_t linesize,
const uint8_t *srcp, ptrdiff_t mref,
ptrdiff_t pref, int clip_max);
void ff_lowpass_line_avx2 (uint8_t *dstp, ptrdiff_t linesize,
const uint8_t *srcp, ptrdiff_t mref,
ptrdiff_t pref, int clip_max);
void ff_lowpass_line_16_sse2(uint8_t *dstp, ptrdiff_t linesize,
const uint8_t *srcp, ptrdiff_t mref,
ptrdiff_t pref, int clip_max);
void ff_lowpass_line_16_avx (uint8_t *dstp, ptrdiff_t linesize,
const uint8_t *srcp, ptrdiff_t mref,
ptrdiff_t pref, int clip_max);
void ff_lowpass_line_16_avx2 (uint8_t *dstp, ptrdiff_t linesize,
const uint8_t *srcp, ptrdiff_t mref,
ptrdiff_t pref, int clip_max);
void ff_lowpass_line_complex_sse2(uint8_t *dstp, ptrdiff_t linesize,
const uint8_t *srcp, ptrdiff_t mref,
ptrdiff_t pref, int clip_max);
void ff_lowpass_line_complex_12_sse2(uint8_t *dstp, ptrdiff_t linesize,
const uint8_t *srcp, ptrdiff_t mref,
ptrdiff_t pref, int clip_max);
av_cold void ff_tinterlace_init_x86(TInterlaceContext *s)
{
int cpu_flags = av_get_cpu_flags();
if (s->csp->comp[0].depth > 8) {
if (EXTERNAL_SSE2(cpu_flags)) {
if (!(s->flags & TINTERLACE_FLAG_CVLPF))
s->lowpass_line = ff_lowpass_line_16_sse2;
else
s->lowpass_line = ff_lowpass_line_complex_12_sse2;
}
if (EXTERNAL_AVX(cpu_flags))
if (!(s->flags & TINTERLACE_FLAG_CVLPF))
s->lowpass_line = ff_lowpass_line_16_avx;
if (EXTERNAL_AVX2_FAST(cpu_flags)) {
if (!(s->flags & TINTERLACE_FLAG_CVLPF)) {
s->lowpass_line = ff_lowpass_line_16_avx2;
}
}
} else {
if (EXTERNAL_SSE2(cpu_flags)) {
if (!(s->flags & TINTERLACE_FLAG_CVLPF))
s->lowpass_line = ff_lowpass_line_sse2;
else
s->lowpass_line = ff_lowpass_line_complex_sse2;
}
if (EXTERNAL_AVX(cpu_flags))
if (!(s->flags & TINTERLACE_FLAG_CVLPF))
s->lowpass_line = ff_lowpass_line_avx;
if (EXTERNAL_AVX2_FAST(cpu_flags)) {
if (!(s->flags & TINTERLACE_FLAG_CVLPF)) {
s->lowpass_line = ff_lowpass_line_avx2;
}
}
}
}
+87
View File
@@ -0,0 +1,87 @@
;*****************************************************************************
;* x86-optimized functions for transpose filter
;*
;* Copyright (C) 2019 Paul B Mahol
;*
;* 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/x86/x86util.asm"
SECTION .text
;------------------------------------------------------------------------------
; void ff_transpose_8x8(uint8_t *src, ptrdiff_t src_linesize,
; uint8_t *dst, ptrdiff_t dst_linesize)
;------------------------------------------------------------------------------
INIT_XMM sse2
cglobal transpose_8x8_8, 4,5,8, src, src_linesize, dst, dst_linesize, linesize3
lea linesize3q, [src_linesizeq * 3]
movq m0, [srcq + src_linesizeq * 0]
movq m1, [srcq + src_linesizeq * 1]
movq m2, [srcq + src_linesizeq * 2]
movq m3, [srcq + linesize3q]
lea srcq, [srcq + src_linesizeq * 4]
movq m4, [srcq + src_linesizeq * 0]
movq m5, [srcq + src_linesizeq * 1]
movq m6, [srcq + src_linesizeq * 2]
movq m7, [srcq + linesize3q]
TRANSPOSE_8X8B 0, 1, 2, 3, 4, 5, 6, 7
lea linesize3q, [dst_linesizeq * 3]
movq [dstq + dst_linesizeq * 0], m0
movq [dstq + dst_linesizeq * 1], m1
movq [dstq + dst_linesizeq * 2], m2
movq [dstq + linesize3q], m3
lea dstq, [dstq + dst_linesizeq * 4]
movq [dstq + dst_linesizeq * 0], m4
movq [dstq + dst_linesizeq * 1], m5
movq [dstq + dst_linesizeq * 2], m6
movq [dstq + linesize3q], m7
RET
cglobal transpose_8x8_16, 4,5,9, ARCH_X86_32 * 32, src, src_linesize, dst, dst_linesize, linesize3
lea linesize3q, [src_linesizeq * 3]
movu m0, [srcq + src_linesizeq * 0]
movu m1, [srcq + src_linesizeq * 1]
movu m2, [srcq + src_linesizeq * 2]
movu m3, [srcq + linesize3q]
lea srcq, [srcq + src_linesizeq * 4]
movu m4, [srcq + src_linesizeq * 0]
movu m5, [srcq + src_linesizeq * 1]
movu m6, [srcq + src_linesizeq * 2]
movu m7, [srcq + linesize3q]
%if ARCH_X86_64
TRANSPOSE8x8W 0, 1, 2, 3, 4, 5, 6, 7, 8
%else
TRANSPOSE8x8W 0, 1, 2, 3, 4, 5, 6, 7, [rsp], [rsp + 16]
%endif
lea linesize3q, [dst_linesizeq * 3]
movu [dstq + dst_linesizeq * 0], m0
movu [dstq + dst_linesizeq * 1], m1
movu [dstq + dst_linesizeq * 2], m2
movu [dstq + linesize3q], m3
lea dstq, [dstq + dst_linesizeq * 4]
movu [dstq + dst_linesizeq * 0], m4
movu [dstq + dst_linesizeq * 1], m5
movu [dstq + dst_linesizeq * 2], m6
movu [dstq + linesize3q], m7
RET
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2019 Paul B Mahol
*
* 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/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/transpose.h"
void ff_transpose_8x8_8_sse2(uint8_t *src,
ptrdiff_t src_linesize,
uint8_t *dst,
ptrdiff_t dst_linesize);
void ff_transpose_8x8_16_sse2(uint8_t *src,
ptrdiff_t src_linesize,
uint8_t *dst,
ptrdiff_t dst_linesize);
av_cold void ff_transpose_init_x86(TransVtable *v, int pixstep)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE2(cpu_flags) && pixstep == 1) {
v->transpose_8x8 = ff_transpose_8x8_8_sse2;
}
if (EXTERNAL_SSE2(cpu_flags) && pixstep == 2) {
v->transpose_8x8 = ff_transpose_8x8_16_sse2;
}
}
+256
View File
@@ -0,0 +1,256 @@
;*****************************************************************************
;* x86-optimized functions for v360 filter
;*
;* 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/x86/x86util.asm"
%if HAVE_AVX2_EXTERNAL
SECTION_RODATA
pb_mask: db 0,4,8,12,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
pw_mask: db 0,1,4, 5, 8, 9,12,13,-1,-1,-1,-1,-1,-1,-1,-1
pd_255: times 4 dd 255
pd_65535: times 4 dd 65535
SECTION .text
; void ff_remap2_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
; const uint16_t *u, const uint16_t *v, const int16_t *ker);
INIT_YMM avx2
cglobal remap1_8bit_line, 6, 7, 6, dst, width, src, in_linesize, u, v, x
movsxdifnidn widthq, widthd
xor xq, xq
movd xm0, in_linesized
pcmpeqw m4, m4
VBROADCASTI128 m3, [pb_mask]
vpbroadcastd m0, xm0
.loop:
pmovsxwd m1, [vq + xq * 2]
pmovsxwd m2, [uq + xq * 2]
pmulld m1, m0
paddd m1, m2
mova m2, m4
vpgatherdd m5, [srcq + m1], m2
pshufb m1, m5, m3
vextracti128 xm2, m1, 1
movd [dstq+xq], xm1
movd [dstq+xq+4], xm2
add xq, mmsize / 4
cmp xq, widthq
jl .loop
RET
INIT_YMM avx2
cglobal remap1_16bit_line, 6, 7, 6, dst, width, src, in_linesize, u, v, x
movsxdifnidn widthq, widthd
xor xq, xq
movd xm0, in_linesized
pcmpeqw m4, m4
VBROADCASTI128 m3, [pw_mask]
vpbroadcastd m0, xm0
.loop:
pmovsxwd m1, [vq + xq * 2]
pmovsxwd m2, [uq + xq * 2]
pslld m2, 0x1
pmulld m1, m0
paddd m1, m2
mova m2, m4
vpgatherdd m5, [srcq + m1], m2
pshufb m1, m5, m3
vextracti128 xm2, m1, 1
movq [dstq+xq*2], xm1
movq [dstq+xq*2+8], xm2
add xq, mmsize / 4
cmp xq, widthq
jl .loop
RET
INIT_YMM avx2
cglobal remap2_8bit_line, 7, 8, 8, dst, width, src, in_linesize, u, v, ker, x
movsxdifnidn widthq, widthd
movd xm0, in_linesized
%if ARCH_X86_32
DEFINE_ARGS dst, width, src, x, u, v, ker
%endif
xor xq, xq
pcmpeqw m7, m7
vpbroadcastd m0, xm0
vpbroadcastd m6, [pd_255]
.loop:
pmovsxwd m1, [kerq + xq * 8]
pmovsxwd m2, [vq + xq * 8]
pmovsxwd m3, [uq + xq * 8]
pmulld m4, m2, m0
paddd m4, m3
mova m3, m7
vpgatherdd m2, [srcq + m4], m3
pand m2, m6
pmulld m2, m1
phaddd m2, m2
phaddd m1, m2, m2
psrld m1, m1, 0xe
vextracti128 xm2, m1, 1
pextrb [dstq+xq], xm1, 0
pextrb [dstq+xq+1], xm2, 0
add xq, mmsize / 16
cmp xq, widthq
jl .loop
RET
INIT_YMM avx2
cglobal remap2_16bit_line, 7, 8, 8, dst, width, src, in_linesize, u, v, ker, x
movsxdifnidn widthq, widthd
movd xm0, in_linesized
%if ARCH_X86_32
DEFINE_ARGS dst, width, src, x, u, v, ker
%endif
xor xq, xq
pcmpeqw m7, m7
vpbroadcastd m0, xm0
vpbroadcastd m6, [pd_65535]
.loop:
pmovsxwd m1, [kerq + xq * 8]
pmovsxwd m2, [vq + xq * 8]
pmovsxwd m3, [uq + xq * 8]
pslld m3, 0x1
pmulld m4, m2, m0
paddd m4, m3
mova m3, m7
vpgatherdd m2, [srcq + m4], m3
pand m2, m6
pmulld m2, m1
phaddd m2, m2
phaddd m1, m2, m2
psrld m1, m1, 0xe
vextracti128 xm2, m1, 1
pextrw [dstq+xq*2], xm1, 0
pextrw [dstq+xq*2+2], xm2, 0
add xq, mmsize / 16
cmp xq, widthq
jl .loop
RET
%if ARCH_X86_64
INIT_YMM avx2
cglobal remap3_8bit_line, 7, 11, 8, dst, width, src, in_linesize, u, v, ker, x, y, tmp, z
movsxdifnidn widthq, widthd
xor zq, zq
xor yq, yq
xor xq, xq
movd xm0, in_linesized
pcmpeqw m7, m7
vpbroadcastd m0, xm0
vpbroadcastd m6, [pd_255]
.loop:
pmovsxwd m1, [kerq + yq]
pmovsxwd m2, [vq + yq]
pmovsxwd m3, [uq + yq]
pmulld m4, m2, m0
paddd m4, m3
mova m3, m7
vpgatherdd m2, [srcq + m4], m3
pand m2, m6
pmulld m2, m1
HADDD m2, m1
movzx tmpq, word [vq + yq + 16]
imul tmpq, in_linesizeq
movzx zq, word [uq + yq + 16]
add tmpq, zq
movzx zq, byte [srcq + tmpq]
movzx tmpq, word [kerq + yq + 16]
imul zd, tmpd
movd xm1, zd
paddd m2, m1
psrld m2, m2, 0xe
packuswb m2, m2
pextrb [dstq+xq], xm2, 0
add xq, 1
add yq, 18
cmp xq, widthq
jl .loop
RET
INIT_YMM avx2
cglobal remap4_8bit_line, 7, 9, 11, dst, width, src, in_linesize, u, v, ker, x, y
movsxdifnidn widthq, widthd
xor yq, yq
xor xq, xq
movd xm0, in_linesized
pcmpeqw m7, m7
vpbroadcastd m0, xm0
vpbroadcastd m6, [pd_255]
.loop:
pmovsxwd m1, [kerq + yq]
pmovsxwd m5, [kerq + yq + 16]
pmovsxwd m2, [vq + yq]
pmovsxwd m8, [vq + yq + 16]
pmovsxwd m3, [uq + yq]
pmovsxwd m9, [uq + yq + 16]
pmulld m4, m2, m0
pmulld m10, m8, m0
paddd m4, m3
paddd m10, m9
mova m3, m7
vpgatherdd m2, [srcq + m4], m3
mova m3, m7
vpgatherdd m4, [srcq + m10], m3
pand m2, m6
pand m4, m6
pmulld m2, m1
pmulld m4, m5
paddd m2, m4
HADDD m2, m1
psrld m2, m2, 0xe
packuswb m2, m2
pextrb [dstq+xq], xm2, 0
add xq, 1
add yq, 32
cmp xq, widthq
jl .loop
RET
%endif
%endif
+71
View File
@@ -0,0 +1,71 @@
/*
* 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 "config.h"
#include "libavutil/attributes.h"
#include "libavutil/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/v360.h"
void ff_remap1_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
const int16_t *const u, const int16_t *const v, const int16_t *const ker);
void ff_remap2_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
const int16_t *const u, const int16_t *const v, const int16_t *const ker);
void ff_remap3_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
const int16_t *const u, const int16_t *const v, const int16_t *const ker);
void ff_remap4_8bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
const int16_t *const u, const int16_t *const v, const int16_t *const ker);
void ff_remap1_16bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
const int16_t *const u, const int16_t *const v, const int16_t *const ker);
void ff_remap2_16bit_line_avx2(uint8_t *dst, int width, const uint8_t *src, ptrdiff_t in_linesize,
const int16_t *const u, const int16_t *const v, const int16_t *const ker);
av_cold void ff_v360_init_x86(V360Context *s, int depth)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == NEAREST && depth <= 8)
s->remap_line = ff_remap1_8bit_line_avx2;
if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == BILINEAR && depth <= 8)
s->remap_line = ff_remap2_8bit_line_avx2;
if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == NEAREST && depth > 8)
s->remap_line = ff_remap1_16bit_line_avx2;
if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == BILINEAR && depth > 8)
s->remap_line = ff_remap2_16bit_line_avx2;
#if ARCH_X86_64
if (EXTERNAL_AVX2_FAST(cpu_flags) && s->interp == LAGRANGE9 && depth <= 8)
s->remap_line = ff_remap3_8bit_line_avx2;
if (EXTERNAL_AVX2_FAST(cpu_flags) && (s->interp == BICUBIC ||
s->interp == LANCZOS ||
s->interp == SPLINE16 ||
s->interp == GAUSSIAN ||
s->interp == MITCHELL) && depth <= 8)
s->remap_line = ff_remap4_8bit_line_avx2;
#endif
}
+259
View File
@@ -0,0 +1,259 @@
;*****************************************************************************
;* x86-optimized functions for w3fdif filter
;*
;* Copyright (c) 2015 Paul B Mahol
;*
;* 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/x86/x86util.asm"
SECTION .text
INIT_XMM sse2
cglobal w3fdif_scale, 3, 3, 2, 0, out_pixel, work_pixel, linesize
.loop:
mova m0, [work_pixelq]
mova m1, [work_pixelq+mmsize]
psrad m0, 15
psrad m1, 15
packssdw m0, m1
packuswb m0, m0
movh [out_pixelq], m0
add out_pixelq, mmsize/2
add work_pixelq, mmsize*2
sub linesized, mmsize/2
jg .loop
RET
cglobal w3fdif_simple_low, 4, 5, 6, 0, work_line, in_lines_cur0, coef, linesize, offset
movd m1, [coefq]
DEFINE_ARGS work_line, in_lines_cur0, in_lines_cur1, linesize, offset
SPLATW m0, m1, 0
SPLATW m1, m1, 1
pxor m4, m4
mov offsetq, 0
mov in_lines_cur1q, [in_lines_cur0q + gprsize]
mov in_lines_cur0q, [in_lines_cur0q]
.loop:
movh m2, [in_lines_cur0q+offsetq]
movh m3, [in_lines_cur1q+offsetq]
punpcklbw m2, m4
punpcklbw m3, m4
SBUTTERFLY wd, 2, 3, 5
pmaddwd m2, m0
pmaddwd m3, m1
mova [work_lineq+offsetq*4], m2
mova [work_lineq+offsetq*4+mmsize], m3
add offsetq, mmsize/2
sub linesized, mmsize/2
jg .loop
RET
cglobal w3fdif_complex_low, 4, 7, 8, 0, work_line, in_lines_cur0, coef, linesize
movq m0, [coefq]
DEFINE_ARGS work_line, in_lines_cur0, in_lines_cur1, linesize, offset, in_lines_cur2, in_lines_cur3
pshufd m2, m0, q1111
SPLATD m0
pxor m1, m1
mov offsetq, 0
mov in_lines_cur3q, [in_lines_cur0q+gprsize*3]
mov in_lines_cur2q, [in_lines_cur0q+gprsize*2]
mov in_lines_cur1q, [in_lines_cur0q+gprsize]
mov in_lines_cur0q, [in_lines_cur0q]
.loop:
movh m4, [in_lines_cur0q+offsetq]
movh m5, [in_lines_cur1q+offsetq]
punpcklbw m4, m1
punpcklbw m5, m1
SBUTTERFLY wd, 4, 5, 7
pmaddwd m4, m0
pmaddwd m5, m0
movh m6, [in_lines_cur2q+offsetq]
movh m3, [in_lines_cur3q+offsetq]
punpcklbw m6, m1
punpcklbw m3, m1
SBUTTERFLY wd, 6, 3, 7
pmaddwd m6, m2
pmaddwd m3, m2
paddd m4, m6
paddd m5, m3
mova [work_lineq+offsetq*4], m4
mova [work_lineq+offsetq*4+mmsize], m5
add offsetq, mmsize/2
sub linesized, mmsize/2
jg .loop
RET
%if ARCH_X86_64
cglobal w3fdif_simple_high, 5, 9, 8, 0, work_line, in_lines_cur0, in_lines_adj0, coef, linesize
%else
cglobal w3fdif_simple_high, 4, 7, 8, 0, work_line, in_lines_cur0, in_lines_adj0, coef, linesize
%endif
movq m2, [coefq]
%if ARCH_X86_64
DEFINE_ARGS work_line, in_lines_cur0, in_lines_adj0, in_lines_cur1, linesize, offset, in_lines_cur2, in_lines_adj1, in_lines_adj2
xor offsetq, offsetq
%else
DEFINE_ARGS work_line, in_lines_cur0, in_lines_adj0, in_lines_cur1, in_lines_cur2, in_lines_adj1, in_lines_adj2
%define linesized r4mp
%endif
pshufd m0, m2, q0000
SPLATW m2, m2, 2
pxor m7, m7
mov in_lines_cur2q, [in_lines_cur0q+gprsize*2]
mov in_lines_cur1q, [in_lines_cur0q+gprsize]
mov in_lines_cur0q, [in_lines_cur0q]
mov in_lines_adj2q, [in_lines_adj0q+gprsize*2]
mov in_lines_adj1q, [in_lines_adj0q+gprsize]
mov in_lines_adj0q, [in_lines_adj0q]
%if ARCH_X86_32
sub in_lines_cur1q, in_lines_cur0q
sub in_lines_cur2q, in_lines_cur0q
sub in_lines_adj0q, in_lines_cur0q
sub in_lines_adj1q, in_lines_cur0q
sub in_lines_adj2q, in_lines_cur0q
%define offsetq in_lines_cur0q
%endif
.loop:
%if ARCH_X86_64
movh m3, [in_lines_cur0q+offsetq]
%else
movh m3, [in_lines_cur0q]
%endif
movh m4, [in_lines_cur1q+offsetq]
punpcklbw m3, m7
punpcklbw m4, m7
SBUTTERFLY wd, 3, 4, 1
pmaddwd m3, m0
pmaddwd m4, m0
movh m5, [in_lines_adj0q+offsetq]
movh m6, [in_lines_adj1q+offsetq]
punpcklbw m5, m7
punpcklbw m6, m7
SBUTTERFLY wd, 5, 6, 1
pmaddwd m5, m0
pmaddwd m6, m0
paddd m3, m5
paddd m4, m6
movh m5, [in_lines_cur2q+offsetq]
movh m6, [in_lines_adj2q+offsetq]
punpcklbw m5, m7
punpcklbw m6, m7
SBUTTERFLY wd, 5, 6, 1
pmaddwd m5, m2
pmaddwd m6, m2
paddd m3, m5
paddd m4, m6
%if ARCH_X86_64
paddd m3, [work_lineq+offsetq*4]
paddd m4, [work_lineq+offsetq*4+mmsize]
mova [work_lineq+offsetq*4], m3
mova [work_lineq+offsetq*4+mmsize], m4
%else
paddd m3, [work_lineq]
paddd m4, [work_lineq+mmsize]
mova [work_lineq], m3
mova [work_lineq+mmsize], m4
add work_lineq, mmsize*2
%endif
add offsetq, mmsize/2
sub linesized, mmsize/2
jg .loop
RET
%if ARCH_X86_64
cglobal w3fdif_complex_high, 5, 13, 10, 0, work_line, in_lines_cur0, in_lines_adj0, coef, linesize
movq m0, [coefq+0]
movd m4, [coefq+8]
DEFINE_ARGS work_line, in_lines_cur0, in_lines_adj0, in_lines_cur1, linesize, offset, in_lines_cur2, in_lines_cur3, in_lines_cur4, in_lines_adj1, in_lines_adj2, in_lines_adj3, in_lines_adj4
pshufd m1, m0, q1111
SPLATD m0
SPLATW m4, m4
pxor m3, m3
mov offsetq, 0
mov in_lines_cur4q, [in_lines_cur0q+gprsize*4]
mov in_lines_cur3q, [in_lines_cur0q+gprsize*3]
mov in_lines_cur2q, [in_lines_cur0q+gprsize*2]
mov in_lines_cur1q, [in_lines_cur0q+gprsize]
mov in_lines_cur0q, [in_lines_cur0q]
mov in_lines_adj4q, [in_lines_adj0q+gprsize*4]
mov in_lines_adj3q, [in_lines_adj0q+gprsize*3]
mov in_lines_adj2q, [in_lines_adj0q+gprsize*2]
mov in_lines_adj1q, [in_lines_adj0q+gprsize]
mov in_lines_adj0q, [in_lines_adj0q]
.loop:
movh m5, [in_lines_cur0q+offsetq]
movh m6, [in_lines_cur1q+offsetq]
punpcklbw m5, m3
punpcklbw m6, m3
SBUTTERFLY wd, 5, 6, 2
pmaddwd m5, m0
pmaddwd m6, m0
movh m8, [in_lines_cur2q+offsetq]
movh m9, [in_lines_cur3q+offsetq]
punpcklbw m8, m3
punpcklbw m9, m3
SBUTTERFLY wd, 8, 9, 2
pmaddwd m8, m1
pmaddwd m9, m1
paddd m5, m8
paddd m6, m9
movh m8, [in_lines_adj0q+offsetq]
movh m9, [in_lines_adj1q+offsetq]
punpcklbw m8, m3
punpcklbw m9, m3
SBUTTERFLY wd, 8, 9, 2
pmaddwd m8, m0
pmaddwd m9, m0
paddd m5, m8
paddd m6, m9
movh m8, [in_lines_adj2q+offsetq]
movh m9, [in_lines_adj3q+offsetq]
punpcklbw m8, m3
punpcklbw m9, m3
SBUTTERFLY wd, 8, 9, 2
pmaddwd m8, m1
pmaddwd m9, m1
paddd m5, m8
paddd m6, m9
movh m8, [in_lines_cur4q+offsetq]
movh m9, [in_lines_adj4q+offsetq]
punpcklbw m8, m3
punpcklbw m9, m3
SBUTTERFLY wd, 8, 9, 2
pmaddwd m8, m4
pmaddwd m9, m4
paddd m5, m8
paddd m6, m9
paddd m5, [work_lineq+offsetq*4]
paddd m6, [work_lineq+offsetq*4+mmsize]
mova [work_lineq+offsetq*4], m5
mova [work_lineq+offsetq*4+mmsize], m6
add offsetq, mmsize/2
sub linesized, mmsize/2
jg .loop
RET
%endif
+62
View File
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2015 Paul B Mahol
*
* 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/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/w3fdif.h"
void ff_w3fdif_simple_low_sse2(int32_t *work_line,
uint8_t *in_lines_cur[2],
const int16_t *coef, int linesize);
void ff_w3fdif_simple_high_sse2(int32_t *work_line,
uint8_t *in_lines_cur[3],
uint8_t *in_lines_adj[3],
const int16_t *coef, int linesize);
void ff_w3fdif_complex_low_sse2(int32_t *work_line,
uint8_t *in_lines_cur[4],
const int16_t *coef, int linesize);
void ff_w3fdif_complex_high_sse2(int32_t *work_line,
uint8_t *in_lines_cur[5],
uint8_t *in_lines_adj[5],
const int16_t *coef, int linesize);
void ff_w3fdif_scale_sse2(uint8_t *out_pixel, const int32_t *work_pixel,
int linesize, int max);
av_cold void ff_w3fdif_init_x86(W3FDIFDSPContext *dsp, int depth)
{
int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE2(cpu_flags) && depth <= 8) {
dsp->filter_simple_low = ff_w3fdif_simple_low_sse2;
dsp->filter_simple_high = ff_w3fdif_simple_high_sse2;
dsp->filter_complex_low = ff_w3fdif_complex_low_sse2;
dsp->filter_scale = ff_w3fdif_scale_sse2;
}
if (ARCH_X86_64 && EXTERNAL_SSE2(cpu_flags) && depth <= 8) {
dsp->filter_complex_high = ff_w3fdif_complex_high_sse2;
}
}
+43
View File
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 Christian R. Helmrich
* Copyright (c) 2024 Christian Lehmann
* Copyright (c) 2024 Christian Stoffers
*
* 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
*/
/**
* @file
* SIMD initialization for calculation of extended perceptually weighted PSNR (XPSNR).
*
* Authors: Christian Helmrich, Lehmann, and Stoffers, Fraunhofer HHI, Berlin, Germany
*/
#include "libavutil/x86/cpu.h"
#include "libavfilter/xpsnr.h"
uint64_t ff_sse_line_16bit_sse2(const uint8_t *buf, const uint8_t *ref, const int w);
void ff_xpsnr_init_x86(PSNRDSPContext *dsp, const int bpp)
{
if (bpp <= 15) { /* XPSNR always operates with 16-bit internal precision */
const int cpu_flags = av_get_cpu_flags();
if (EXTERNAL_SSE2(cpu_flags))
dsp->sse_line = ff_sse_line_16bit_sse2;
}
}
+235
View File
@@ -0,0 +1,235 @@
;*****************************************************************************
;* x86-optimized functions for yadif filter
;*
;* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
;* Copyright (c) 2013 Daniel Kang <daniel.d.kang@gmail.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/x86/x86util.asm"
SECTION_RODATA
pb_1: times 16 db 1
pw_1: times 8 dw 1
SECTION .text
%macro CHECK 2
movu m2, [curq+t1+%1]
movu m3, [curq+t0+%2]
mova m4, m2
mova m5, m2
pxor m4, m3
pavgb m5, m3
pand m4, [pb_1]
psubusb m5, m4
RSHIFT m5, 1
punpcklbw m5, m7
mova m4, m2
psubusb m2, m3
psubusb m3, m4
pmaxub m2, m3
mova m3, m2
mova m4, m2
RSHIFT m3, 1
RSHIFT m4, 2
punpcklbw m2, m7
punpcklbw m3, m7
punpcklbw m4, m7
paddw m2, m3
paddw m2, m4
%endmacro
%macro CHECK1 0
mova m3, m0
pcmpgtw m3, m2
pminsw m0, m2
mova m6, m3
pand m5, m3
pandn m3, m1
por m3, m5
mova m1, m3
%endmacro
%macro CHECK2 0
paddw m6, [pw_1]
psllw m6, 14
paddsw m2, m6
mova m3, m0
pcmpgtw m3, m2
pminsw m0, m2
pand m5, m3
pandn m3, m1
por m3, m5
mova m1, m3
%endmacro
%macro LOAD 2
movh %1, %2
punpcklbw %1, m7
%endmacro
%macro FILTER 3
.loop%1:
pxor m7, m7
LOAD m0, [curq+t1]
LOAD m1, [curq+t0]
LOAD m2, [%2]
LOAD m3, [%3]
mova m4, m3
paddw m3, m2
psraw m3, 1
mova [rsp+ 0], m0
mova [rsp+16], m3
mova [rsp+32], m1
psubw m2, m4
ABS1 m2, m4
LOAD m3, [prevq+t1]
LOAD m4, [prevq+t0]
psubw m3, m0
psubw m4, m1
ABS1 m3, m5
ABS1 m4, m5
paddw m3, m4
psrlw m2, 1
psrlw m3, 1
pmaxsw m2, m3
LOAD m3, [nextq+t1]
LOAD m4, [nextq+t0]
psubw m3, m0
psubw m4, m1
ABS1 m3, m5
ABS1 m4, m5
paddw m3, m4
psrlw m3, 1
pmaxsw m2, m3
mova [rsp+48], m2
paddw m1, m0
paddw m0, m0
psubw m0, m1
psrlw m1, 1
ABS1 m0, m2
movu m2, [curq+t1-1]
movu m3, [curq+t0-1]
mova m4, m2
psubusb m2, m3
psubusb m3, m4
pmaxub m2, m3
mova m3, m2
psrldq m3, 2
punpcklbw m2, m7
punpcklbw m3, m7
paddw m0, m2
paddw m0, m3
psubw m0, [pw_1]
CHECK -2, 0
CHECK1
CHECK -3, 1
CHECK2
CHECK 0, -2
CHECK1
CHECK 1, -3
CHECK2
mova m6, [rsp+48]
cmp DWORD r8m, 2
jge .end%1
LOAD m2, [%2+t1*2]
LOAD m4, [%3+t1*2]
LOAD m3, [%2+t0*2]
LOAD m5, [%3+t0*2]
paddw m2, m4
paddw m3, m5
psrlw m2, 1
psrlw m3, 1
mova m4, [rsp+ 0]
mova m5, [rsp+16]
mova m7, [rsp+32]
psubw m2, m4
psubw m3, m7
mova m0, m5
psubw m5, m4
psubw m0, m7
mova m4, m2
pminsw m2, m3
pmaxsw m3, m4
pmaxsw m2, m5
pminsw m3, m5
pmaxsw m2, m0
pminsw m3, m0
pxor m4, m4
pmaxsw m6, m3
psubw m4, m2
pmaxsw m6, m4
.end%1:
mova m2, [rsp+16]
mova m3, m2
psubw m2, m6
paddw m3, m6
pmaxsw m1, m2
pminsw m1, m3
packuswb m1, m1
movh [dstq], m1
add dstq, mmsize/2
add prevq, mmsize/2
add curq, mmsize/2
add nextq, mmsize/2
sub DWORD r4m, mmsize/2
jg .loop%1
%endmacro
%macro YADIF 0
%if ARCH_X86_32
cglobal yadif_filter_line, 4, 6, 8, 80, dst, prev, cur, next, w, prefs, \
mrefs, parity, mode
%else
cglobal yadif_filter_line, 4, 7, 8, 80, dst, prev, cur, next, w, prefs, \
mrefs, parity, mode
%endif
%if ARCH_X86_32
mov r4, r5mp
mov r5, r6mp
DECLARE_REG_TMP 4,5
%else
movsxd r5, DWORD r5m
movsxd r6, DWORD r6m
DECLARE_REG_TMP 5,6
%endif
cmp DWORD paritym, 0
je .parity0
FILTER 1, prevq, curq
jmp .ret
.parity0:
FILTER 0, curq, nextq
.ret:
RET
%endmacro
INIT_XMM ssse3
YADIF
INIT_XMM sse2
YADIF
+74
View File
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
*
* 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/cpu.h"
#include "libavutil/x86/cpu.h"
#include "libavfilter/yadif.h"
void ff_yadif_filter_line_sse2(void *dst, void *prev, void *cur,
void *next, int w, int prefs,
int mrefs, int parity, int mode);
void ff_yadif_filter_line_ssse3(void *dst, void *prev, void *cur,
void *next, int w, int prefs,
int mrefs, int parity, int mode);
void ff_yadif_filter_line_16bit_sse2(void *dst, void *prev, void *cur,
void *next, int w, int prefs,
int mrefs, int parity, int mode);
void ff_yadif_filter_line_16bit_ssse3(void *dst, void *prev, void *cur,
void *next, int w, int prefs,
int mrefs, int parity, int mode);
void ff_yadif_filter_line_16bit_sse4(void *dst, void *prev, void *cur,
void *next, int w, int prefs,
int mrefs, int parity, int mode);
void ff_yadif_filter_line_10bit_sse2(void *dst, void *prev, void *cur,
void *next, int w, int prefs,
int mrefs, int parity, int mode);
void ff_yadif_filter_line_10bit_ssse3(void *dst, void *prev, void *cur,
void *next, int w, int prefs,
int mrefs, int parity, int mode);
av_cold void ff_yadif_init_x86(YADIFContext *yadif)
{
int cpu_flags = av_get_cpu_flags();
int bit_depth = (!yadif->csp) ? 8
: yadif->csp->comp[0].depth;
if (bit_depth >= 15) {
if (EXTERNAL_SSE2(cpu_flags))
yadif->filter_line = ff_yadif_filter_line_16bit_sse2;
if (EXTERNAL_SSSE3(cpu_flags))
yadif->filter_line = ff_yadif_filter_line_16bit_ssse3;
if (EXTERNAL_SSE4(cpu_flags))
yadif->filter_line = ff_yadif_filter_line_16bit_sse4;
} else if ( bit_depth >= 9 && bit_depth <= 14) {
if (EXTERNAL_SSE2(cpu_flags))
yadif->filter_line = ff_yadif_filter_line_10bit_sse2;
if (EXTERNAL_SSSE3(cpu_flags))
yadif->filter_line = ff_yadif_filter_line_10bit_ssse3;
} else {
if (EXTERNAL_SSE2(cpu_flags))
yadif->filter_line = ff_yadif_filter_line_sse2;
if (EXTERNAL_SSSE3(cpu_flags))
yadif->filter_line = ff_yadif_filter_line_ssse3;
}
}
+251
View File
@@ -0,0 +1,251 @@
;*****************************************************************************
;* x86-optimized functions for yadif filter
;*
;* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
;* Copyright (c) 2013 Daniel Kang <daniel.d.kang@gmail.com>
;* Copyright (c) 2011-2013 James Darnley <james.darnley@gmail.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/x86/x86util.asm"
SECTION_RODATA
pw_1: times 8 dw 1
SECTION .text
%macro PMAXUW 2
%if cpuflag(sse4)
pmaxuw %1, %2
%else
psubusw %1, %2
paddusw %1, %2
%endif
%endmacro
%macro CHECK 2
movu m2, [curq+t1+%1*2]
movu m3, [curq+t0+%2*2]
mova m4, m2
mova m5, m2
pxor m4, m3
pavgw m5, m3
pand m4, [pw_1]
psubusw m5, m4
RSHIFT m5, 2
mova m4, m2
psubusw m2, m3
psubusw m3, m4
PMAXUW m2, m3
mova m3, m2
mova m4, m2
RSHIFT m3, 2
RSHIFT m4, 4
paddw m2, m3
paddw m2, m4
%endmacro
%macro CHECK1 0
mova m3, m0
pcmpgtw m3, m2
pminsw m0, m2
mova m6, m3
pand m5, m3
pandn m3, m1
por m3, m5
mova m1, m3
%endmacro
; %macro CHECK2 0
; paddw m6, [pw_1]
; psllw m6, 14
; paddsw m2, m6
; mova m3, m0
; pcmpgtw m3, m2
; pminsw m0, m2
; pand m5, m3
; pandn m3, m1
; por m3, m5
; mova m1, m3
; %endmacro
; This version of CHECK2 is required for 14-bit samples. The left-shift trick
; in the old code is not large enough to correctly select pixels or scores.
%macro CHECK2 0
mova m3, m0
pcmpgtw m0, m2
pand m0, m6
mova m6, m0
pand m5, m6
pand m2, m0
pandn m6, m1
pandn m0, m3
por m6, m5
por m0, m2
mova m1, m6
%endmacro
%macro LOAD 2
movu %1, %2
%endmacro
%macro FILTER 3
.loop%1:
pxor m7, m7
LOAD m0, [curq+t1]
LOAD m1, [curq+t0]
LOAD m2, [%2]
LOAD m3, [%3]
mova m4, m3
paddw m3, m2
psraw m3, 1
mova [rsp+ 0], m0
mova [rsp+16], m3
mova [rsp+32], m1
psubw m2, m4
ABS1 m2, m4
LOAD m3, [prevq+t1]
LOAD m4, [prevq+t0]
psubw m3, m0
psubw m4, m1
ABS2 m3, m4, m5, m6
paddw m3, m4
psrlw m2, 1
psrlw m3, 1
pmaxsw m2, m3
LOAD m3, [nextq+t1]
LOAD m4, [nextq+t0]
psubw m3, m0
psubw m4, m1
ABS2 m3, m4, m5, m6
paddw m3, m4
psrlw m3, 1
pmaxsw m2, m3
mova [rsp+48], m2
paddw m1, m0
paddw m0, m0
psubw m0, m1
psrlw m1, 1
ABS1 m0, m2
movu m2, [curq+t1-1*2]
movu m3, [curq+t0-1*2]
mova m4, m2
psubusw m2, m3
psubusw m3, m4
PMAXUW m2, m3
mova m3, m2
RSHIFT m3, 4
paddw m0, m2
paddw m0, m3
psubw m0, [pw_1]
CHECK -2, 0
CHECK1
CHECK -3, 1
CHECK2
CHECK 0, -2
CHECK1
CHECK 1, -3
CHECK2
mova m6, [rsp+48]
cmp DWORD r8m, 2
jge .end%1
LOAD m2, [%2+t1*2]
LOAD m4, [%3+t1*2]
LOAD m3, [%2+t0*2]
LOAD m5, [%3+t0*2]
paddw m2, m4
paddw m3, m5
psrlw m2, 1
psrlw m3, 1
mova m4, [rsp+ 0]
mova m5, [rsp+16]
mova m7, [rsp+32]
psubw m2, m4
psubw m3, m7
mova m0, m5
psubw m5, m4
psubw m0, m7
mova m4, m2
pminsw m2, m3
pmaxsw m3, m4
pmaxsw m2, m5
pminsw m3, m5
pmaxsw m2, m0
pminsw m3, m0
pxor m4, m4
pmaxsw m6, m3
psubw m4, m2
pmaxsw m6, m4
.end%1:
mova m2, [rsp+16]
mova m3, m2
psubw m2, m6
paddw m3, m6
pmaxsw m1, m2
pminsw m1, m3
movu [dstq], m1
add dstq, mmsize-4
add prevq, mmsize-4
add curq, mmsize-4
add nextq, mmsize-4
sub DWORD r4m, mmsize/2-2
jg .loop%1
%endmacro
%macro YADIF 0
%if ARCH_X86_32
cglobal yadif_filter_line_10bit, 4, 6, 8, 80, dst, prev, cur, next, w, \
prefs, mrefs, parity, mode
%else
cglobal yadif_filter_line_10bit, 4, 7, 8, 80, dst, prev, cur, next, w, \
prefs, mrefs, parity, mode
%endif
%if ARCH_X86_32
mov r4, r5mp
mov r5, r6mp
DECLARE_REG_TMP 4,5
%else
movsxd r5, DWORD r5m
movsxd r6, DWORD r6m
DECLARE_REG_TMP 5,6
%endif
cmp DWORD paritym, 0
je .parity0
FILTER 1, prevq, curq
jmp .ret
.parity0:
FILTER 0, curq, nextq
.ret:
RET
%endmacro
INIT_XMM ssse3
YADIF
INIT_XMM sse2
YADIF
+289
View File
@@ -0,0 +1,289 @@
;*****************************************************************************
;* x86-optimized functions for yadif filter
;*
;* Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
;* Copyright (c) 2013 Daniel Kang <daniel.d.kang@gmail.com>
;* Copyright (c) 2011-2013 James Darnley <james.darnley@gmail.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/x86/x86util.asm"
SECTION_RODATA
pw_1: times 8 dw 1
pw_8000: times 8 dw 0x8000
pd_1: times 4 dd 1
pd_8000: times 4 dd 0x8000
SECTION .text
%macro PABS 2
%if cpuflag(ssse3)
pabsd %1, %1
%else
pxor %2, %2
pcmpgtd %2, %1
pxor %1, %2
psubd %1, %2
%endif
%endmacro
%macro PACK 1
%if cpuflag(sse4)
packusdw %1, %1
%else
psubd %1, [pd_8000]
packssdw %1, %1
paddw %1, [pw_8000]
%endif
%endmacro
%macro PMAXUW 2
%if cpuflag(sse4)
pmaxuw %1, %2
%else
psubusw %1, %2
paddusw %1, %2
%endif
%endmacro
%macro CHECK 2
movu m2, [curq+t1+%1*2]
movu m3, [curq+t0+%2*2]
mova m4, m2
mova m5, m2
pxor m4, m3
pavgw m5, m3
pand m4, [pw_1]
psubusw m5, m4
RSHIFT m5, 2
punpcklwd m5, m7
mova m4, m2
psubusw m2, m3
psubusw m3, m4
PMAXUW m2, m3
mova m3, m2
mova m4, m2
RSHIFT m3, 2
RSHIFT m4, 4
punpcklwd m2, m7
punpcklwd m3, m7
punpcklwd m4, m7
paddd m2, m3
paddd m2, m4
%endmacro
%macro CHECK1 0
mova m3, m0
pcmpgtd m3, m2
PMINSD m0, m2, m6
mova m6, m3
pand m5, m3
pandn m3, m1
por m3, m5
mova m1, m3
%endmacro
%macro CHECK2 0
paddd m6, [pd_1]
pslld m6, 30
paddd m2, m6
mova m3, m0
pcmpgtd m3, m2
PMINSD m0, m2, m4
pand m5, m3
pandn m3, m1
por m3, m5
mova m1, m3
%endmacro
; This version of CHECK2 has 3 fewer instructions on sets older than SSE4 but I
; am not sure whether it is any faster. A rewrite or refactor of the filter
; code should make it possible to eliminate the move instruction at the end. It
; exists to satisfy the expectation that the "score" values are in m1.
; %macro CHECK2 0
; mova m3, m0
; pcmpgtd m0, m2
; pand m0, m6
; mova m6, m0
; pand m5, m6
; pand m2, m0
; pandn m6, m1
; pandn m0, m3
; por m6, m5
; por m0, m2
; mova m1, m6
; %endmacro
%macro LOAD 2
movh %1, %2
punpcklwd %1, m7
%endmacro
%macro FILTER 3
.loop%1:
pxor m7, m7
LOAD m0, [curq+t1]
LOAD m1, [curq+t0]
LOAD m2, [%2]
LOAD m3, [%3]
mova m4, m3
paddd m3, m2
psrad m3, 1
mova [rsp+ 0], m0
mova [rsp+16], m3
mova [rsp+32], m1
psubd m2, m4
PABS m2, m4
LOAD m3, [prevq+t1]
LOAD m4, [prevq+t0]
psubd m3, m0
psubd m4, m1
PABS m3, m5
PABS m4, m5
paddd m3, m4
psrld m2, 1
psrld m3, 1
PMAXSD m2, m3, m6
LOAD m3, [nextq+t1]
LOAD m4, [nextq+t0]
psubd m3, m0
psubd m4, m1
PABS m3, m5
PABS m4, m5
paddd m3, m4
psrld m3, 1
PMAXSD m2, m3, m6
mova [rsp+48], m2
paddd m1, m0
paddd m0, m0
psubd m0, m1
psrld m1, 1
PABS m0, m2
movu m2, [curq+t1-1*2]
movu m3, [curq+t0-1*2]
mova m4, m2
psubusw m2, m3
psubusw m3, m4
PMAXUW m2, m3
mova m3, m2
RSHIFT m3, 4
punpcklwd m2, m7
punpcklwd m3, m7
paddd m0, m2
paddd m0, m3
psubd m0, [pd_1]
CHECK -2, 0
CHECK1
CHECK -3, 1
CHECK2
CHECK 0, -2
CHECK1
CHECK 1, -3
CHECK2
mova m6, [rsp+48]
cmp DWORD r8m, 2
jge .end%1
LOAD m2, [%2+t1*2]
LOAD m4, [%3+t1*2]
LOAD m3, [%2+t0*2]
LOAD m5, [%3+t0*2]
paddd m2, m4
paddd m3, m5
psrld m2, 1
psrld m3, 1
mova m4, [rsp+ 0]
mova m5, [rsp+16]
mova m7, [rsp+32]
psubd m2, m4
psubd m3, m7
mova m0, m5
psubd m5, m4
psubd m0, m7
mova m4, m2
PMINSD m2, m3, m7
PMAXSD m3, m4, m7
PMAXSD m2, m5, m7
PMINSD m3, m5, m7
PMAXSD m2, m0, m7
PMINSD m3, m0, m7
pxor m4, m4
PMAXSD m6, m3, m7
psubd m4, m2
PMAXSD m6, m4, m7
.end%1:
mova m2, [rsp+16]
mova m3, m2
psubd m2, m6
paddd m3, m6
PMAXSD m1, m2, m7
PMINSD m1, m3, m7
PACK m1
movh [dstq], m1
add dstq, mmsize/2
add prevq, mmsize/2
add curq, mmsize/2
add nextq, mmsize/2
sub DWORD r4m, mmsize/4
jg .loop%1
%endmacro
%macro YADIF 0
%if ARCH_X86_32
cglobal yadif_filter_line_16bit, 4, 6, 8, 80, dst, prev, cur, next, w, \
prefs, mrefs, parity, mode
%else
cglobal yadif_filter_line_16bit, 4, 7, 8, 80, dst, prev, cur, next, w, \
prefs, mrefs, parity, mode
%endif
%if ARCH_X86_32
mov r4, r5mp
mov r5, r6mp
DECLARE_REG_TMP 4,5
%else
movsxd r5, DWORD r5m
movsxd r6, DWORD r6m
DECLARE_REG_TMP 5,6
%endif
cmp DWORD paritym, 0
je .parity0
FILTER 1, prevq, curq
jmp .ret
.parity0:
FILTER 0, curq, nextq
.ret:
RET
%endmacro
INIT_XMM sse4
YADIF
INIT_XMM ssse3
YADIF
INIT_XMM sse2
YADIF