]> git.sesse.net Git - ffmpeg/blob - libavcodec/x86/mpegvideoenc.c
184912da9421fa4ffaf3490de05b4a157cc7d126
[ffmpeg] / libavcodec / x86 / mpegvideoenc.c
1 /*
2  * The simplest mpeg encoder (well, it was the simplest!)
3  * Copyright (c) 2000,2001 Fabrice Bellard
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "libavutil/cpu.h"
23 #include "libavutil/x86/asm.h"
24 #include "libavcodec/avcodec.h"
25 #include "libavcodec/dsputil.h"
26 #include "libavcodec/mpegvideo.h"
27 #include "dsputil_mmx.h"
28
29 #if HAVE_INLINE_ASM
30
31 extern uint16_t ff_inv_zigzag_direct16[64];
32
33 #define COMPILE_TEMPLATE_MMXEXT 0
34 #define COMPILE_TEMPLATE_SSE2   0
35 #define COMPILE_TEMPLATE_SSSE3  0
36 #define RENAME(a) a ## _MMX
37 #define RENAMEl(a) a ## _mmx
38 #include "mpegvideoenc_template.c"
39
40 #undef COMPILE_TEMPLATE_SSSE3
41 #undef COMPILE_TEMPLATE_SSE2
42 #undef COMPILE_TEMPLATE_MMXEXT
43 #define COMPILE_TEMPLATE_MMXEXT 1
44 #define COMPILE_TEMPLATE_SSE2   0
45 #define COMPILE_TEMPLATE_SSSE3  0
46 #undef RENAME
47 #undef RENAMEl
48 #define RENAME(a) a ## _MMX2
49 #define RENAMEl(a) a ## _mmx2
50 #include "mpegvideoenc_template.c"
51
52 #undef COMPILE_TEMPLATE_MMXEXT
53 #undef COMPILE_TEMPLATE_SSE2
54 #undef COMPILE_TEMPLATE_SSSE3
55 #define COMPILE_TEMPLATE_MMXEXT 0
56 #define COMPILE_TEMPLATE_SSE2   1
57 #define COMPILE_TEMPLATE_SSSE3  0
58 #undef RENAME
59 #undef RENAMEl
60 #define RENAME(a) a ## _SSE2
61 #define RENAMEl(a) a ## _sse2
62 #include "mpegvideoenc_template.c"
63
64 #if HAVE_SSSE3
65 #undef COMPILE_TEMPLATE_MMXEXT
66 #undef COMPILE_TEMPLATE_SSE2
67 #undef COMPILE_TEMPLATE_SSSE3
68 #define COMPILE_TEMPLATE_MMXEXT 0
69 #define COMPILE_TEMPLATE_SSE2   1
70 #define COMPILE_TEMPLATE_SSSE3  1
71 #undef RENAME
72 #undef RENAMEl
73 #define RENAME(a) a ## _SSSE3
74 #define RENAMEl(a) a ## _sse2
75 #include "mpegvideoenc_template.c"
76 #endif
77
78 #endif /* HAVE_INLINE_ASM */
79
80 void ff_MPV_encode_init_x86(MpegEncContext *s)
81 {
82 #if HAVE_INLINE_ASM
83     int mm_flags = av_get_cpu_flags();
84     const int dct_algo = s->avctx->dct_algo;
85
86     if (dct_algo == FF_DCT_AUTO || dct_algo == FF_DCT_MMX) {
87 #if HAVE_SSSE3
88         if (mm_flags & AV_CPU_FLAG_SSSE3) {
89             s->dct_quantize = dct_quantize_SSSE3;
90         } else
91 #endif
92         if (mm_flags & AV_CPU_FLAG_SSE2) {
93             s->dct_quantize = dct_quantize_SSE2;
94         } else if (mm_flags & AV_CPU_FLAG_MMXEXT) {
95             s->dct_quantize = dct_quantize_MMX2;
96         } else {
97             s->dct_quantize = dct_quantize_MMX;
98         }
99     }
100 #endif /* HAVE_INLINE_ASM */
101 }