xref: /third_party/ffmpeg/libavcodec/tests/x86/dct.c (revision cabdff1a)
1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * This file is part of FFmpeg.
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
5cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
6cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
7cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
8cabdff1aSopenharmony_ci *
9cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
10cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
11cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12cabdff1aSopenharmony_ci * Lesser General Public License for more details.
13cabdff1aSopenharmony_ci *
14cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
15cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
16cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17cabdff1aSopenharmony_ci */
18cabdff1aSopenharmony_ci
19cabdff1aSopenharmony_ci#include "config.h"
20cabdff1aSopenharmony_ci#include "config_components.h"
21cabdff1aSopenharmony_ci
22cabdff1aSopenharmony_ci#include "libavutil/cpu.h"
23cabdff1aSopenharmony_ci#include "libavutil/mem_internal.h"
24cabdff1aSopenharmony_ci
25cabdff1aSopenharmony_ci#include "libavcodec/x86/fdct.h"
26cabdff1aSopenharmony_ci#include "libavcodec/x86/xvididct.h"
27cabdff1aSopenharmony_ci#include "libavcodec/x86/simple_idct.h"
28cabdff1aSopenharmony_ci
29cabdff1aSopenharmony_ci#if (CONFIG_PRORES_DECODER || CONFIG_PRORES_LGPL_DECODER) && ARCH_X86_64 && HAVE_X86ASM
30cabdff1aSopenharmony_civoid ff_prores_idct_put_10_sse2(uint16_t *dst, int linesize,
31cabdff1aSopenharmony_ci                                int16_t *block, int16_t *qmat);
32cabdff1aSopenharmony_ci
33cabdff1aSopenharmony_ci#define PR_WRAP(INSN) \
34cabdff1aSopenharmony_cistatic void ff_prores_idct_put_10_##INSN##_wrap(int16_t *dst){ \
35cabdff1aSopenharmony_ci    LOCAL_ALIGNED(16, int16_t, qmat, [64]); \
36cabdff1aSopenharmony_ci    LOCAL_ALIGNED(16, int16_t, tmp, [64]); \
37cabdff1aSopenharmony_ci    int i; \
38cabdff1aSopenharmony_ci \
39cabdff1aSopenharmony_ci    for(i=0; i<64; i++){ \
40cabdff1aSopenharmony_ci        qmat[i]=4; \
41cabdff1aSopenharmony_ci        tmp[i]= dst[i]; \
42cabdff1aSopenharmony_ci    } \
43cabdff1aSopenharmony_ci    ff_prores_idct_put_10_##INSN (dst, 16, tmp, qmat); \
44cabdff1aSopenharmony_ci \
45cabdff1aSopenharmony_ci    for(i=0; i<64; i++) { \
46cabdff1aSopenharmony_ci         dst[i] -= 512; \
47cabdff1aSopenharmony_ci    } \
48cabdff1aSopenharmony_ci}
49cabdff1aSopenharmony_ci
50cabdff1aSopenharmony_ciPR_WRAP(sse2)
51cabdff1aSopenharmony_ci
52cabdff1aSopenharmony_ci# if HAVE_AVX_EXTERNAL
53cabdff1aSopenharmony_civoid ff_prores_idct_put_10_avx(uint16_t *dst, int linesize,
54cabdff1aSopenharmony_ci                               int16_t *block, int16_t *qmat);
55cabdff1aSopenharmony_ciPR_WRAP(avx)
56cabdff1aSopenharmony_ci# endif
57cabdff1aSopenharmony_ci
58cabdff1aSopenharmony_ci#endif
59cabdff1aSopenharmony_ci
60cabdff1aSopenharmony_cistatic const struct algo fdct_tab_arch[] = {
61cabdff1aSopenharmony_ci#if HAVE_SSE2_INLINE
62cabdff1aSopenharmony_ci    { "SSE2",   ff_fdct_sse2,   FF_IDCT_PERM_NONE, AV_CPU_FLAG_SSE2 },
63cabdff1aSopenharmony_ci#endif
64cabdff1aSopenharmony_ci    { 0 }
65cabdff1aSopenharmony_ci};
66cabdff1aSopenharmony_ci
67cabdff1aSopenharmony_cistatic const struct algo idct_tab_arch[] = {
68cabdff1aSopenharmony_ci#if CONFIG_MPEG4_DECODER && HAVE_X86ASM
69cabdff1aSopenharmony_ci#if HAVE_SSE2_EXTERNAL
70cabdff1aSopenharmony_ci    { "XVID-SSE2",   ff_xvid_idct_sse2,   FF_IDCT_PERM_SSE2,   AV_CPU_FLAG_SSE2,   1 },
71cabdff1aSopenharmony_ci#endif
72cabdff1aSopenharmony_ci#endif /* CONFIG_MPEG4_DECODER && HAVE_X86ASM */
73cabdff1aSopenharmony_ci#if (CONFIG_PRORES_DECODER || CONFIG_PRORES_LGPL_DECODER) && ARCH_X86_64 && HAVE_X86ASM
74cabdff1aSopenharmony_ci    { "PR-SSE2",     ff_prores_idct_put_10_sse2_wrap, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_SSE2, 1 },
75cabdff1aSopenharmony_ci# if HAVE_AVX_EXTERNAL
76cabdff1aSopenharmony_ci    { "PR-AVX",      ff_prores_idct_put_10_avx_wrap, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_AVX, 1 },
77cabdff1aSopenharmony_ci# endif
78cabdff1aSopenharmony_ci#endif
79cabdff1aSopenharmony_ci#if HAVE_X86ASM
80cabdff1aSopenharmony_ci#if ARCH_X86_64
81cabdff1aSopenharmony_ci#if HAVE_SSE2_EXTERNAL
82cabdff1aSopenharmony_ci    { "SIMPLE8-SSE2",   ff_simple_idct8_sse2,  FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_SSE2},
83cabdff1aSopenharmony_ci    { "SIMPLE10-SSE2",  ff_simple_idct10_sse2, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_SSE2},
84cabdff1aSopenharmony_ci    { "SIMPLE12-SSE2",  ff_simple_idct12_sse2, FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_SSE2, 1 },
85cabdff1aSopenharmony_ci#endif
86cabdff1aSopenharmony_ci#if HAVE_AVX_EXTERNAL
87cabdff1aSopenharmony_ci    { "SIMPLE8-AVX",    ff_simple_idct8_avx,   FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_AVX},
88cabdff1aSopenharmony_ci    { "SIMPLE10-AVX",   ff_simple_idct10_avx,  FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_AVX},
89cabdff1aSopenharmony_ci    { "SIMPLE12-AVX",   ff_simple_idct12_avx,  FF_IDCT_PERM_TRANSPOSE, AV_CPU_FLAG_AVX,  1 },
90cabdff1aSopenharmony_ci#endif
91cabdff1aSopenharmony_ci#endif
92cabdff1aSopenharmony_ci#endif
93cabdff1aSopenharmony_ci    { 0 }
94cabdff1aSopenharmony_ci};
95cabdff1aSopenharmony_ci
96cabdff1aSopenharmony_cistatic const uint8_t idct_simple_mmx_perm[64] = {
97cabdff1aSopenharmony_ci    0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
98cabdff1aSopenharmony_ci    0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
99cabdff1aSopenharmony_ci    0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
100cabdff1aSopenharmony_ci    0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
101cabdff1aSopenharmony_ci    0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
102cabdff1aSopenharmony_ci    0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
103cabdff1aSopenharmony_ci    0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
104cabdff1aSopenharmony_ci    0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
105cabdff1aSopenharmony_ci};
106cabdff1aSopenharmony_ci
107cabdff1aSopenharmony_cistatic const uint8_t idct_sse2_row_perm[8] = { 0, 4, 1, 5, 2, 6, 3, 7 };
108cabdff1aSopenharmony_ci
109cabdff1aSopenharmony_cistatic int permute_x86(int16_t dst[64], const int16_t src[64],
110cabdff1aSopenharmony_ci                       enum idct_permutation_type perm_type)
111cabdff1aSopenharmony_ci{
112cabdff1aSopenharmony_ci    int i;
113cabdff1aSopenharmony_ci
114cabdff1aSopenharmony_ci    switch (perm_type) {
115cabdff1aSopenharmony_ci    case FF_IDCT_PERM_SIMPLE:
116cabdff1aSopenharmony_ci        for (i = 0; i < 64; i++)
117cabdff1aSopenharmony_ci            dst[idct_simple_mmx_perm[i]] = src[i];
118cabdff1aSopenharmony_ci        return 1;
119cabdff1aSopenharmony_ci    case FF_IDCT_PERM_SSE2:
120cabdff1aSopenharmony_ci        for (i = 0; i < 64; i++)
121cabdff1aSopenharmony_ci            dst[(i & 0x38) | idct_sse2_row_perm[i & 7]] = src[i];
122cabdff1aSopenharmony_ci        return 1;
123cabdff1aSopenharmony_ci    }
124cabdff1aSopenharmony_ci
125cabdff1aSopenharmony_ci    return 0;
126cabdff1aSopenharmony_ci}
127