yading@11: /* yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #include "config.h" yading@11: yading@11: #include "libavutil/cpu.h" yading@11: #include "libavutil/float_dsp.h" yading@11: #include "cpu.h" yading@11: #include "asm.h" yading@11: yading@11: void ff_vector_fmul_sse(float *dst, const float *src0, const float *src1, yading@11: int len); yading@11: void ff_vector_fmul_avx(float *dst, const float *src0, const float *src1, yading@11: int len); yading@11: yading@11: void ff_vector_fmac_scalar_sse(float *dst, const float *src, float mul, yading@11: int len); yading@11: void ff_vector_fmac_scalar_avx(float *dst, const float *src, float mul, yading@11: int len); yading@11: yading@11: void ff_vector_fmul_scalar_sse(float *dst, const float *src, float mul, yading@11: int len); yading@11: yading@11: void ff_vector_dmul_scalar_sse2(double *dst, const double *src, yading@11: double mul, int len); yading@11: void ff_vector_dmul_scalar_avx(double *dst, const double *src, yading@11: double mul, int len); yading@11: yading@11: void ff_vector_fmul_add_sse(float *dst, const float *src0, const float *src1, yading@11: const float *src2, int len); yading@11: void ff_vector_fmul_add_avx(float *dst, const float *src0, const float *src1, yading@11: const float *src2, int len); yading@11: yading@11: void ff_vector_fmul_reverse_sse(float *dst, const float *src0, yading@11: const float *src1, int len); yading@11: void ff_vector_fmul_reverse_avx(float *dst, const float *src0, yading@11: const float *src1, int len); yading@11: yading@11: float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order); yading@11: yading@11: void ff_butterflies_float_sse(float *src0, float *src1, int len); yading@11: yading@11: #if HAVE_6REGS && HAVE_INLINE_ASM yading@11: static void vector_fmul_window_3dnowext(float *dst, const float *src0, yading@11: const float *src1, const float *win, yading@11: int len) yading@11: { yading@11: x86_reg i = -len * 4; yading@11: x86_reg j = len * 4 - 8; yading@11: __asm__ volatile ( yading@11: "1: \n" yading@11: "pswapd (%5, %1), %%mm1 \n" yading@11: "movq (%5, %0), %%mm0 \n" yading@11: "pswapd (%4, %1), %%mm5 \n" yading@11: "movq (%3, %0), %%mm4 \n" yading@11: "movq %%mm0, %%mm2 \n" yading@11: "movq %%mm1, %%mm3 \n" yading@11: "pfmul %%mm4, %%mm2 \n" // src0[len + i] * win[len + i] yading@11: "pfmul %%mm5, %%mm3 \n" // src1[j] * win[len + j] yading@11: "pfmul %%mm4, %%mm1 \n" // src0[len + i] * win[len + j] yading@11: "pfmul %%mm5, %%mm0 \n" // src1[j] * win[len + i] yading@11: "pfadd %%mm3, %%mm2 \n" yading@11: "pfsub %%mm0, %%mm1 \n" yading@11: "pswapd %%mm2, %%mm2 \n" yading@11: "movq %%mm1, (%2, %0) \n" yading@11: "movq %%mm2, (%2, %1) \n" yading@11: "sub $8, %1 \n" yading@11: "add $8, %0 \n" yading@11: "jl 1b \n" yading@11: "femms \n" yading@11: : "+r"(i), "+r"(j) yading@11: : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len) yading@11: ); yading@11: } yading@11: yading@11: static void vector_fmul_window_sse(float *dst, const float *src0, yading@11: const float *src1, const float *win, int len) yading@11: { yading@11: x86_reg i = -len * 4; yading@11: x86_reg j = len * 4 - 16; yading@11: __asm__ volatile ( yading@11: "1: \n" yading@11: "movaps (%5, %1), %%xmm1 \n" yading@11: "movaps (%5, %0), %%xmm0 \n" yading@11: "movaps (%4, %1), %%xmm5 \n" yading@11: "movaps (%3, %0), %%xmm4 \n" yading@11: "shufps $0x1b, %%xmm1, %%xmm1 \n" yading@11: "shufps $0x1b, %%xmm5, %%xmm5 \n" yading@11: "movaps %%xmm0, %%xmm2 \n" yading@11: "movaps %%xmm1, %%xmm3 \n" yading@11: "mulps %%xmm4, %%xmm2 \n" // src0[len + i] * win[len + i] yading@11: "mulps %%xmm5, %%xmm3 \n" // src1[j] * win[len + j] yading@11: "mulps %%xmm4, %%xmm1 \n" // src0[len + i] * win[len + j] yading@11: "mulps %%xmm5, %%xmm0 \n" // src1[j] * win[len + i] yading@11: "addps %%xmm3, %%xmm2 \n" yading@11: "subps %%xmm0, %%xmm1 \n" yading@11: "shufps $0x1b, %%xmm2, %%xmm2 \n" yading@11: "movaps %%xmm1, (%2, %0) \n" yading@11: "movaps %%xmm2, (%2, %1) \n" yading@11: "sub $16, %1 \n" yading@11: "add $16, %0 \n" yading@11: "jl 1b \n" yading@11: : "+r"(i), "+r"(j) yading@11: : "r"(dst + len), "r"(src0 + len), "r"(src1), "r"(win + len) yading@11: ); yading@11: } yading@11: #endif /* HAVE_6REGS && HAVE_INLINE_ASM */ yading@11: yading@11: void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp) yading@11: { yading@11: int mm_flags = av_get_cpu_flags(); yading@11: yading@11: #if HAVE_6REGS && HAVE_INLINE_ASM yading@11: if (INLINE_AMD3DNOWEXT(mm_flags)) { yading@11: fdsp->vector_fmul_window = vector_fmul_window_3dnowext; yading@11: } yading@11: if (INLINE_SSE(mm_flags)) { yading@11: fdsp->vector_fmul_window = vector_fmul_window_sse; yading@11: } yading@11: #endif yading@11: if (EXTERNAL_SSE(mm_flags)) { yading@11: fdsp->vector_fmul = ff_vector_fmul_sse; yading@11: fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_sse; yading@11: fdsp->vector_fmul_scalar = ff_vector_fmul_scalar_sse; yading@11: fdsp->vector_fmul_add = ff_vector_fmul_add_sse; yading@11: fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_sse; yading@11: fdsp->scalarproduct_float = ff_scalarproduct_float_sse; yading@11: fdsp->butterflies_float = ff_butterflies_float_sse; yading@11: } yading@11: if (EXTERNAL_SSE2(mm_flags)) { yading@11: fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_sse2; yading@11: } yading@11: if (EXTERNAL_AVX(mm_flags)) { yading@11: fdsp->vector_fmul = ff_vector_fmul_avx; yading@11: fdsp->vector_fmac_scalar = ff_vector_fmac_scalar_avx; yading@11: fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_avx; yading@11: fdsp->vector_fmul_add = ff_vector_fmul_add_avx; yading@11: fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_avx; yading@11: } yading@11: }