FFmpeg  4.0
inline_asm.h
Go to the documentation of this file.
1 /*
2  * inline assembly helper macros
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVCODEC_X86_INLINE_ASM_H
22 #define AVCODEC_X86_INLINE_ASM_H
23 
24 #include "constants.h"
25 
26 #define MOVQ_WONE(regd) \
27  __asm__ volatile ( \
28  "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
29  "psrlw $15, %%" #regd ::)
30 
31 #define JUMPALIGN() __asm__ volatile (".p2align 3"::)
32 #define MOVQ_ZERO(regd) __asm__ volatile ("pxor %%"#regd", %%"#regd ::)
33 
34 #define MOVQ_BFE(regd) \
35  __asm__ volatile ( \
36  "pcmpeqd %%"#regd", %%"#regd" \n\t" \
37  "paddb %%"#regd", %%"#regd" \n\t" ::)
38 
39 #ifndef PIC
40 #define MOVQ_WTWO(regd) __asm__ volatile ("movq %0, %%"#regd" \n\t" :: "m"(ff_pw_2))
41 #else
42 // for shared library it's better to use this way for accessing constants
43 // pcmpeqd -> -1
44 #define MOVQ_WTWO(regd) \
45  __asm__ volatile ( \
46  "pcmpeqd %%"#regd", %%"#regd" \n\t" \
47  "psrlw $15, %%"#regd" \n\t" \
48  "psllw $1, %%"#regd" \n\t"::)
49 
50 #endif
51 
52 // using regr as temporary and for the output result
53 // first argument is unmodified and second is trashed
54 // regfe is supposed to contain 0xfefefefefefefefe
55 #define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
56  "movq "#rega", "#regr" \n\t" \
57  "pand "#regb", "#regr" \n\t" \
58  "pxor "#rega", "#regb" \n\t" \
59  "pand "#regfe", "#regb" \n\t" \
60  "psrlq $1, "#regb" \n\t" \
61  "paddb "#regb", "#regr" \n\t"
62 
63 #define PAVGB_MMX(rega, regb, regr, regfe) \
64  "movq "#rega", "#regr" \n\t" \
65  "por "#regb", "#regr" \n\t" \
66  "pxor "#rega", "#regb" \n\t" \
67  "pand "#regfe", "#regb" \n\t" \
68  "psrlq $1, "#regb" \n\t" \
69  "psubb "#regb", "#regr" \n\t"
70 
71 // mm6 is supposed to contain 0xfefefefefefefefe
72 #define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
73  "movq "#rega", "#regr" \n\t" \
74  "movq "#regc", "#regp" \n\t" \
75  "pand "#regb", "#regr" \n\t" \
76  "pand "#regd", "#regp" \n\t" \
77  "pxor "#rega", "#regb" \n\t" \
78  "pxor "#regc", "#regd" \n\t" \
79  "pand %%mm6, "#regb" \n\t" \
80  "pand %%mm6, "#regd" \n\t" \
81  "psrlq $1, "#regb" \n\t" \
82  "psrlq $1, "#regd" \n\t" \
83  "paddb "#regb", "#regr" \n\t" \
84  "paddb "#regd", "#regp" \n\t"
85 
86 #define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
87  "movq "#rega", "#regr" \n\t" \
88  "movq "#regc", "#regp" \n\t" \
89  "por "#regb", "#regr" \n\t" \
90  "por "#regd", "#regp" \n\t" \
91  "pxor "#rega", "#regb" \n\t" \
92  "pxor "#regc", "#regd" \n\t" \
93  "pand %%mm6, "#regb" \n\t" \
94  "pand %%mm6, "#regd" \n\t" \
95  "psrlq $1, "#regd" \n\t" \
96  "psrlq $1, "#regb" \n\t" \
97  "psubb "#regb", "#regr" \n\t" \
98  "psubb "#regd", "#regp" \n\t"
99 
100 #endif /* AVCODEC_X86_INLINE_ASM_H */