From: Pierre Edouard Lepere <[email protected]>
Signed-off-by: Anton Khirnov <[email protected]>
---
libavcodec/x86/Makefile | 3 +-
libavcodec/x86/hevc_idct.asm | 180 ++++++++++++++++++++++++++++++++++++++++++
libavcodec/x86/hevcdsp_init.c | 79 ++++++++++++++++++
3 files changed, 261 insertions(+), 1 deletion(-)
create mode 100644 libavcodec/x86/hevc_idct.asm
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index 23a5911..25d0917 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -90,7 +90,8 @@ YASM-OBJS-$(CONFIG_H264QPEL) +=
x86/h264_qpel_8bit.o \
x86/h264_qpel_10bit.o \
x86/fpel.o \
x86/qpel.o
-YASM-OBJS-$(CONFIG_HEVC_DECODER) += x86/hevc_deblock.o
+YASM-OBJS-$(CONFIG_HEVC_DECODER) += x86/hevc_deblock.o \
+ x86/hevc_idct.o
YASM-OBJS-$(CONFIG_HPELDSP) += x86/fpel.o \
x86/hpeldsp.o
YASM-OBJS-$(CONFIG_HUFFYUVDSP) += x86/huffyuvdsp.o
diff --git a/libavcodec/x86/hevc_idct.asm b/libavcodec/x86/hevc_idct.asm
new file mode 100644
index 0000000..bb01496
--- /dev/null
+++ b/libavcodec/x86/hevc_idct.asm
@@ -0,0 +1,180 @@
+; /*
+; * Provide SSE & MMX idct functions for HEVC decoding
+; * Copyright (c) 2014 Pierre-Edouard LEPERE
+; *
+; * This file is part of Libav.
+; *
+; * Libav 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.
+; *
+; * Libav 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 Libav; 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
+max_pixels_10: times 8 dw ((1 << 10)-1)
+dc_add_10: times 4 dd ((1 << 14-10) + 1)
+
+
+SECTION .text
+
+;the idct_dc_add macros and functions were largely inspired by x264 project's
code in the h264_idct.asm file
+
+%macro DC_ADD_INIT 2
+ add %1w, ((1 << 14-8) + 1)
+ sar %1w, (15-8)
+ movd m0, %1d
+ lea %1, [%2*3]
+ SPLATW m0, m0, 0
+ pxor m1, m1
+ psubw m1, m0
+ packuswb m0, m0
+ packuswb m1, m1
+%endmacro
+
+%macro DC_ADD_OP 4
+ %1 m2, [%2 ]
+ %1 m3, [%2+%3 ]
+ %1 m4, [%2+%3*2]
+ %1 m5, [%2+%4 ]
+ paddusb m2, m0
+ paddusb m3, m0
+ paddusb m4, m0
+ paddusb m5, m0
+ psubusb m2, m1
+ psubusb m3, m1
+ psubusb m4, m1
+ psubusb m5, m1
+ %1 [%2 ], m2
+ %1 [%2+%3 ], m3
+ %1 [%2+%3*2], m4
+ %1 [%2+%4 ], m5
+%endmacro
+
+INIT_MMX mmxext
+;------------------------------------------------------------------------------
+; void ff_hevc_idct4_dc_add_8_mmxext(uint8_t *dst, int coeff, ptrdiff_t
stride);
+;------------------------------------------------------------------------------
+%if ARCH_X86_64
+cglobal hevc_idct4_dc_add_8, 3, 4, 6, dst, coeff, stride
+ DC_ADD_INIT r1, r2
+ DC_ADD_OP movh, r0, r2, r1
+ RET
+
+;------------------------------------------------------------------------------
+; void ff_hevc_idct8_dc_add_8_mmxext(uint8_t *dst, int coeff, ptrdiff_t stride)
+;------------------------------------------------------------------------------
+cglobal hevc_idct8_dc_add_8, 3, 4, 6, dst, coeff, stride
+ DC_ADD_INIT r1, r2
+ DC_ADD_OP mova, r0, r2, r1
+ lea r0, [r0+r2*4]
+ DC_ADD_OP mova, r0, r2, r1
+ RET
+%else
+;------------------------------------------------------------------------------
+; void ff_hevc_idct4_dc_add_8_mmxext(uint8_t *dst, int coeff, ptrdiff_t stride)
+;------------------------------------------------------------------------------
+cglobal hevc_idct4_dc_add_8, 2, 3, 6, dst, doeff, stride
+ DC_ADD_INIT r2, r1
+ DC_ADD_OP movh, r0, r1, r2
+ RET
+
+;-----------------------------------------------------------------------------
+; void ff_hevc_idct8_dc_add_8_mmxext(uint8_t *dst, int coeff, ptrdiff_t stride)
+;-----------------------------------------------------------------------------
+cglobal hevc_idct8_dc_add_8, 2, 3, 6, dst, coeff, stride
+ DC_ADD_INIT r2, r1
+ DC_ADD_OP mova, r0, r1, r2
+ lea r0, [r0+r1*4]
+ DC_ADD_OP mova, r0, r1, r2
+ RET
+%endif
+
+
+;-----------------------------------------------------------------------------
+; void ff_hevc_idct16_dc_add_8_sse2(uint8_t *dst, int coeff, ptrdiff_t stride)
+;-----------------------------------------------------------------------------
+INIT_XMM sse2
+cglobal hevc_idct16_dc_add_8, 3, 4, 6, dst, coeff, stride
+ DC_ADD_INIT r1, r2
+ DC_ADD_OP mova, r0, r2, r1
+ lea r0, [r0+r2*4]
+ DC_ADD_OP mova, r0, r2, r1
+ lea r0, [r0+r2*4]
+ DC_ADD_OP mova, r0, r2, r1
+ lea r0, [r0+r2*4]
+ DC_ADD_OP mova, r0, r2, r1
+ RET
+
+;-----------------------------------------------------------------------------
+; void ff_hevc_idct4_dc_add_10_mmxext(pixel *dst, int coeff, int stride)
+;-----------------------------------------------------------------------------
+%macro IDCT_DC_ADD_OP_10 3
+ pxor m5, m5
+ mova m6, [max_pixels_10]
+%if avx_enabled
+ paddw m1, m0, [%1+0 ]
+ paddw m2, m0, [%1+%2 ]
+ paddw m3, m0, [%1+%2*2]
+ paddw m4, m0, [%1+%3 ]
+%else
+ mova m1, [%1+0 ]
+ mova m2, [%1+%2 ]
+ mova m3, [%1+%2*2]
+ mova m4, [%1+%3 ]
+ paddw m1, m0
+ paddw m2, m0
+ paddw m3, m0
+ paddw m4, m0
+%endif
+ CLIPW m1, m5, m6
+ CLIPW m2, m5, m6
+ CLIPW m3, m5, m6
+ CLIPW m4, m5, m6
+ mova [%1+0 ], m1
+ mova [%1+%2 ], m2
+ mova [%1+%2*2], m3
+ mova [%1+%3 ], m4
+%endmacro
+
+INIT_MMX mmxext
+cglobal hevc_idct4_dc_add_10, 3, 3, 7, dst, coeff, stride
+ add coeffw, ((1 << 4) + 1)
+ sar coeffw, 5
+ movd m0, coeffd
+ lea r1, [r2*3]
+ SPLATW m0, m0, 0
+ IDCT_DC_ADD_OP_10 r0, r2, r1
+ RET
+
+;-----------------------------------------------------------------------------
+; void ff_hevc_idct8_dc_add_10(pixel *dst, int coeff, int stride);
+;-----------------------------------------------------------------------------
+%macro IDCT8_DC_ADD 0
+cglobal hevc_idct8_dc_add_10, 3, 4, 7, dst, coeff, stride
+ add coeffw, ((1 << 4) + 1)
+ sar coeffw, 5
+ movd m0, coeffd
+ lea r1, [r2*3]
+ SPLATW m0, m0, 0
+ IDCT_DC_ADD_OP_10 r0, r2, r1
+ lea r0, [r0+r2*4]
+ IDCT_DC_ADD_OP_10 r0, r2, r1
+ RET
+%endmacro
+
+INIT_XMM sse2
+IDCT8_DC_ADD
+%if HAVE_AVX_EXTERNAL
+INIT_XMM avx
+IDCT8_DC_ADD
+%endif
diff --git a/libavcodec/x86/hevcdsp_init.c b/libavcodec/x86/hevcdsp_init.c
index dd3f635..8246e11 100644
--- a/libavcodec/x86/hevcdsp_init.c
+++ b/libavcodec/x86/hevcdsp_init.c
@@ -46,27 +46,106 @@ LFC_FUNCS(uint8_t, 10)
LFL_FUNCS(uint8_t, 8)
LFL_FUNCS(uint8_t, 10)
+#define IDCT_DC_PROTO(size, bitd, opt) \
+void ff_hevc_idct ## size ## _dc_add_ ## bitd ##_## opt(uint8_t *dst, int
coeff, ptrdiff_t stride)
+
+IDCT_DC_PROTO(4, 8, mmxext);
+IDCT_DC_PROTO(8, 8, mmxext);
+IDCT_DC_PROTO(16, 8, sse2);
+IDCT_DC_PROTO(32, 8, sse2);
+
+IDCT_DC_PROTO(4, 10, mmxext);
+IDCT_DC_PROTO(8, 10, sse2);
+IDCT_DC_PROTO(16, 10, sse2);
+IDCT_DC_PROTO(32, 10, sse2);
+IDCT_DC_PROTO(8, 10, avx);
+IDCT_DC_PROTO(16, 10, avx);
+IDCT_DC_PROTO(32, 10, avx);
+
+#if HAVE_SSE2_EXTERNAL
+static void hevc_idct32_dc_add_8_sse2(uint8_t *dst, int coeff, ptrdiff_t
stride)
+{
+ ff_hevc_idct16_dc_add_8_sse2(dst, coeff, stride);
+ ff_hevc_idct16_dc_add_8_sse2(dst + 16, coeff, stride);
+ ff_hevc_idct16_dc_add_8_sse2(dst + 16 * stride, coeff, stride);
+ ff_hevc_idct16_dc_add_8_sse2(dst + 16 * stride + 16, coeff, stride);
+}
+
+static void hevc_idct16_dc_add_10_sse2(uint8_t *dst, int coeff, ptrdiff_t
stride)
+{
+ ff_hevc_idct8_dc_add_10_sse2(dst, coeff, stride);
+ ff_hevc_idct8_dc_add_10_sse2(dst + 16, coeff, stride);
+ ff_hevc_idct8_dc_add_10_sse2(dst + 8 * stride, coeff, stride);
+ ff_hevc_idct8_dc_add_10_sse2(dst + 8 * stride + 16, coeff, stride);
+}
+
+static void hevc_idct32_dc_add_10_sse2(uint8_t *dst, int coeff, ptrdiff_t
stride)
+{
+ hevc_idct16_dc_add_10_sse2(dst, coeff, stride);
+ hevc_idct16_dc_add_10_sse2(dst + 32, coeff, stride);
+ hevc_idct16_dc_add_10_sse2(dst + 16 * stride, coeff, stride);
+ hevc_idct16_dc_add_10_sse2(dst + 16 * stride + 32, coeff, stride);
+}
+#endif //HAVE_SSE2_EXTERNAL
+
+#if HAVE_AVX_EXTERNAL
+static void hevc_idct16_dc_add_10_avx(uint8_t *dst, int coeff, ptrdiff_t
stride)
+{
+ ff_hevc_idct8_dc_add_10_avx(dst, coeff, stride);
+ ff_hevc_idct8_dc_add_10_avx(dst + 16, coeff, stride);
+ ff_hevc_idct8_dc_add_10_avx(dst + 8 * stride, coeff, stride);
+ ff_hevc_idct8_dc_add_10_avx(dst + 8 * stride + 16, coeff, stride);
+}
+
+static void hevc_idct32_dc_add_10_avx(uint8_t *dst, int coeff, ptrdiff_t
stride)
+{
+ hevc_idct16_dc_add_10_avx(dst, coeff, stride);
+ hevc_idct16_dc_add_10_avx(dst + 32, coeff, stride);
+ hevc_idct16_dc_add_10_avx(dst + 16 * stride, coeff, stride);
+ hevc_idct16_dc_add_10_avx(dst + 16 * stride + 32, coeff, stride);
+}
+#endif //HAVE_AVX_EXTERNAL
+
void ff_hevc_dsp_init_x86(HEVCDSPContext *c, const int bit_depth)
{
int mm_flags = av_get_cpu_flags();
if (bit_depth == 8) {
+ if (EXTERNAL_MMXEXT(mm_flags)) {
+ c->transform_dc_add[0] = ff_hevc_idct4_dc_add_8_mmxext;
+ c->transform_dc_add[1] = ff_hevc_idct8_dc_add_8_mmxext;
+ }
if (EXTERNAL_SSE2(mm_flags)) {
c->hevc_v_loop_filter_chroma = ff_hevc_v_loop_filter_chroma_8_sse2;
c->hevc_h_loop_filter_chroma = ff_hevc_h_loop_filter_chroma_8_sse2;
+
+ c->transform_dc_add[2] = ff_hevc_idct16_dc_add_8_sse2;
+ c->transform_dc_add[3] = hevc_idct32_dc_add_8_sse2;
}
if (EXTERNAL_SSSE3(mm_flags) && ARCH_X86_64) {
c->hevc_v_loop_filter_luma = ff_hevc_v_loop_filter_luma_8_ssse3;
c->hevc_h_loop_filter_luma = ff_hevc_h_loop_filter_luma_8_ssse3;
}
} else if (bit_depth == 10) {
+ if (EXTERNAL_MMXEXT(mm_flags)) {
+ c->transform_dc_add[0] = ff_hevc_idct4_dc_add_10_mmxext;
+ }
if (EXTERNAL_SSE2(mm_flags)) {
c->hevc_v_loop_filter_chroma =
ff_hevc_v_loop_filter_chroma_10_sse2;
c->hevc_h_loop_filter_chroma =
ff_hevc_h_loop_filter_chroma_10_sse2;
+
+ c->transform_dc_add[1] = ff_hevc_idct8_dc_add_10_sse2;
+ c->transform_dc_add[2] = hevc_idct16_dc_add_10_sse2;
+ c->transform_dc_add[3] = hevc_idct32_dc_add_10_sse2;
}
if (EXTERNAL_SSSE3(mm_flags) && ARCH_X86_64) {
c->hevc_v_loop_filter_luma = ff_hevc_v_loop_filter_luma_10_ssse3;
c->hevc_h_loop_filter_luma = ff_hevc_h_loop_filter_luma_10_ssse3;
}
+ if (EXTERNAL_AVX(mm_flags)) {
+ c->transform_dc_add[1] = ff_hevc_idct8_dc_add_10_avx;
+ c->transform_dc_add[2] = hevc_idct16_dc_add_10_avx;
+ c->transform_dc_add[3] = hevc_idct32_dc_add_10_avx;
+ }
}
}
--
2.0.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel