]> git.sesse.net Git - ffmpeg/blob - libavcodec/x86/mpegvideoenc.c
x86: mpegvideoenc: Split optimizations off into a separate file
[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 #if HAVE_SSSE3
34 #define HAVE_SSSE3_BAK
35 #endif
36 #undef HAVE_SSSE3
37 #define HAVE_SSSE3 0
38
39 #undef HAVE_SSE2
40 #undef HAVE_MMXEXT
41 #define HAVE_SSE2 0
42 #define HAVE_MMXEXT 0
43 #define RENAME(a) a ## _MMX
44 #define RENAMEl(a) a ## _mmx
45 #include "mpegvideoenc_template.c"
46
47 #undef HAVE_MMXEXT
48 #define HAVE_MMXEXT 1
49 #undef RENAME
50 #undef RENAMEl
51 #define RENAME(a) a ## _MMX2
52 #define RENAMEl(a) a ## _mmx2
53 #include "mpegvideoenc_template.c"
54
55 #undef HAVE_SSE2
56 #define HAVE_SSE2 1
57 #undef RENAME
58 #undef RENAMEl
59 #define RENAME(a) a ## _SSE2
60 #define RENAMEl(a) a ## _sse2
61 #include "mpegvideoenc_template.c"
62
63 #ifdef HAVE_SSSE3_BAK
64 #undef HAVE_SSSE3
65 #define HAVE_SSSE3 1
66 #undef RENAME
67 #undef RENAMEl
68 #define RENAME(a) a ## _SSSE3
69 #define RENAMEl(a) a ## _sse2
70 #include "mpegvideoenc_template.c"
71 #endif
72
73 #endif /* HAVE_INLINE_ASM */
74
75 void ff_MPV_encode_init_x86(MpegEncContext *s)
76 {
77 #if HAVE_INLINE_ASM
78     int mm_flags = av_get_cpu_flags();
79     const int dct_algo = s->avctx->dct_algo;
80
81     if (dct_algo == FF_DCT_AUTO || dct_algo == FF_DCT_MMX) {
82 #if HAVE_SSSE3
83         if (mm_flags & AV_CPU_FLAG_SSSE3) {
84             s->dct_quantize = dct_quantize_SSSE3;
85         } else
86 #endif
87         if (mm_flags & AV_CPU_FLAG_SSE2) {
88             s->dct_quantize = dct_quantize_SSE2;
89         } else if (mm_flags & AV_CPU_FLAG_MMXEXT) {
90             s->dct_quantize = dct_quantize_MMX2;
91         } else {
92             s->dct_quantize = dct_quantize_MMX;
93         }
94     }
95 #endif /* HAVE_INLINE_ASM */
96 }