x86: move some inline asm macros to the only places they are used
[libav.git] / libavcodec / x86 / dsputil_mmx.h
CommitLineData
182f56cb
AJ
1/*
2 * MMX optimized DSP utils
3 * Copyright (c) 2007 Aurelien Jacobs <aurel@gnuage.org>
4 *
2912e87a 5 * This file is part of Libav.
182f56cb 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
182f56cb
AJ
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 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
182f56cb
AJ
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
2912e87a 18 * License along with Libav; if not, write to the Free Software
182f56cb
AJ
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
a6493a8f
DB
22#ifndef AVCODEC_X86_DSPUTIL_MMX_H
23#define AVCODEC_X86_DSPUTIL_MMX_H
182f56cb 24
1b77e877 25#include <stdint.h>
245976da 26#include "libavcodec/dsputil.h"
004357a1 27#include "libavutil/x86_cpu.h"
1b77e877 28
5e660449 29typedef struct { uint64_t a, b; } xmm_reg;
fa9b873e 30
43de5065 31extern const uint64_t ff_bone;
43de5065 32extern const uint64_t ff_wtwo;
182f56cb
AJ
33
34extern const uint64_t ff_pdw_80000000[2];
35
8d147f1f 36extern const xmm_reg ff_pw_3;
7af8fbd3 37extern const xmm_reg ff_pw_4;
5e660449
AJ
38extern const xmm_reg ff_pw_5;
39extern const xmm_reg ff_pw_8;
182f56cb 40extern const uint64_t ff_pw_15;
5e660449 41extern const xmm_reg ff_pw_16;
af521abc 42extern const xmm_reg ff_pw_18;
182f56cb 43extern const uint64_t ff_pw_20;
af521abc 44extern const xmm_reg ff_pw_27;
5e660449
AJ
45extern const xmm_reg ff_pw_28;
46extern const xmm_reg ff_pw_32;
182f56cb 47extern const uint64_t ff_pw_42;
af521abc
DC
48extern const uint64_t ff_pw_53;
49extern const xmm_reg ff_pw_63;
5110b25e 50extern const xmm_reg ff_pw_64;
182f56cb
AJ
51extern const uint64_t ff_pw_96;
52extern const uint64_t ff_pw_128;
97d1d009 53extern const uint64_t ff_pw_255;
182f56cb 54
a711eb48 55extern const xmm_reg ff_pb_1;
4af8cdfc 56extern const xmm_reg ff_pb_3;
182f56cb 57extern const uint64_t ff_pb_7;
357f45d9 58extern const uint64_t ff_pb_1F;
182f56cb 59extern const uint64_t ff_pb_3F;
357f45d9 60extern const uint64_t ff_pb_81;
2c166c3a 61extern const xmm_reg ff_pb_A1;
af521abc 62extern const xmm_reg ff_pb_F8;
182f56cb 63extern const uint64_t ff_pb_FC;
af521abc 64extern const xmm_reg ff_pb_FE;
182f56cb
AJ
65
66extern const double ff_pd_1[2];
67extern const double ff_pd_2[2];
68
1835cda6
VP
69#define LOAD4(stride,in,a,b,c,d)\
70 "movq 0*"#stride"+"#in", "#a"\n\t"\
71 "movq 1*"#stride"+"#in", "#b"\n\t"\
72 "movq 2*"#stride"+"#in", "#c"\n\t"\
73 "movq 3*"#stride"+"#in", "#d"\n\t"
74
75#define STORE4(stride,out,a,b,c,d)\
76 "movq "#a", 0*"#stride"+"#out"\n\t"\
77 "movq "#b", 1*"#stride"+"#out"\n\t"\
78 "movq "#c", 2*"#stride"+"#out"\n\t"\
79 "movq "#d", 3*"#stride"+"#out"\n\t"
80
28748a91
CG
81#define SBUTTERFLY(a,b,t,n,m)\
82 "mov" #m " " #a ", " #t " \n\t" /* abcd */\
83 "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\
84 "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */\
85
86#define TRANSPOSE4(a,b,c,d,t)\
87 SBUTTERFLY(a,b,t,wd,q) /* a=aebf t=cgdh */\
88 SBUTTERFLY(c,d,b,wd,q) /* c=imjn b=kolp */\
89 SBUTTERFLY(a,c,d,dq,q) /* a=aeim d=bfjn */\
90 SBUTTERFLY(t,b,c,dq,q) /* t=cgko c=dhlp */
91
357f45d9
DC
92// e,f,g,h can be memory
93// out: a,d,t,c
94#define TRANSPOSE8x4(a,b,c,d,e,f,g,h,t)\
95 "punpcklbw " #e ", " #a " \n\t" /* a0 e0 a1 e1 a2 e2 a3 e3 */\
96 "punpcklbw " #f ", " #b " \n\t" /* b0 f0 b1 f1 b2 f2 b3 f3 */\
97 "punpcklbw " #g ", " #c " \n\t" /* c0 g0 c1 g1 c2 g2 d3 g3 */\
98 "punpcklbw " #h ", " #d " \n\t" /* d0 h0 d1 h1 d2 h2 d3 h3 */\
99 SBUTTERFLY(a, b, t, bw, q) /* a= a0 b0 e0 f0 a1 b1 e1 f1 */\
100 /* t= a2 b2 e2 f2 a3 b3 e3 f3 */\
101 SBUTTERFLY(c, d, b, bw, q) /* c= c0 d0 g0 h0 c1 d1 g1 h1 */\
102 /* b= c2 d2 g2 h2 c3 d3 g3 h3 */\
103 SBUTTERFLY(a, c, d, wd, q) /* a= a0 b0 c0 d0 e0 f0 g0 h0 */\
104 /* d= a1 b1 c1 d1 e1 f1 g1 h1 */\
105 SBUTTERFLY(t, b, c, wd, q) /* t= a2 b2 c2 d2 e2 f2 g2 h2 */\
106 /* c= a3 b3 c3 d3 e3 f3 g3 h3 */
107
b250f9c6 108#if ARCH_X86_64
28748a91
CG
109// permutes 01234567 -> 05736421
110#define TRANSPOSE8(a,b,c,d,e,f,g,h,t)\
111 SBUTTERFLY(a,b,%%xmm8,wd,dqa)\
112 SBUTTERFLY(c,d,b,wd,dqa)\
113 SBUTTERFLY(e,f,d,wd,dqa)\
114 SBUTTERFLY(g,h,f,wd,dqa)\
115 SBUTTERFLY(a,c,h,dq,dqa)\
116 SBUTTERFLY(%%xmm8,b,c,dq,dqa)\
117 SBUTTERFLY(e,g,b,dq,dqa)\
118 SBUTTERFLY(d,f,g,dq,dqa)\
119 SBUTTERFLY(a,e,f,qdq,dqa)\
120 SBUTTERFLY(%%xmm8,d,e,qdq,dqa)\
121 SBUTTERFLY(h,b,d,qdq,dqa)\
122 SBUTTERFLY(c,g,b,qdq,dqa)\
123 "movdqa %%xmm8, "#g" \n\t"
124#else
125#define TRANSPOSE8(a,b,c,d,e,f,g,h,t)\
126 "movdqa "#h", "#t" \n\t"\
127 SBUTTERFLY(a,b,h,wd,dqa)\
128 "movdqa "#h", 16"#t" \n\t"\
129 "movdqa "#t", "#h" \n\t"\
130 SBUTTERFLY(c,d,b,wd,dqa)\
131 SBUTTERFLY(e,f,d,wd,dqa)\
132 SBUTTERFLY(g,h,f,wd,dqa)\
133 SBUTTERFLY(a,c,h,dq,dqa)\
134 "movdqa "#h", "#t" \n\t"\
135 "movdqa 16"#t", "#h" \n\t"\
136 SBUTTERFLY(h,b,c,dq,dqa)\
137 SBUTTERFLY(e,g,b,dq,dqa)\
138 SBUTTERFLY(d,f,g,dq,dqa)\
139 SBUTTERFLY(a,e,f,qdq,dqa)\
140 SBUTTERFLY(h,d,e,qdq,dqa)\
141 "movdqa "#h", 16"#t" \n\t"\
142 "movdqa "#t", "#h" \n\t"\
143 SBUTTERFLY(h,b,d,qdq,dqa)\
144 SBUTTERFLY(c,g,b,qdq,dqa)\
145 "movdqa 16"#t", "#g" \n\t"
146#endif
147
97d1d009 148#define MOVQ_WONE(regd) \
be449fca 149 __asm__ volatile ( \
97d1d009
AJ
150 "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
151 "psrlw $15, %%" #regd ::)
152
9cf0841e
MS
153void ff_dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx);
154void ff_dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
4e36a5b4 155
7e7c4b60
RB
156void ff_add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
157void ff_put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
158void ff_put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
97d1d009 159
f49747e9
MR
160void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride);
161void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride);
162void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride);
163void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride);
164
f49747e9
MR
165void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd);
166void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd);
167
110d0cdc
CG
168void ff_put_rv40_qpel8_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
169void ff_put_rv40_qpel16_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
170void ff_avg_rv40_qpel8_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
171void ff_avg_rv40_qpel16_mc33_mmx(uint8_t *block, uint8_t *pixels, int line_size);
172
f49747e9
MR
173void ff_mmx_idct(DCTELEM *block);
174void ff_mmxext_idct(DCTELEM *block);
175
de4bc44a
VS
176
177void ff_deinterlace_line_mmx(uint8_t *dst,
178 const uint8_t *lum_m4, const uint8_t *lum_m3,
179 const uint8_t *lum_m2, const uint8_t *lum_m1,
180 const uint8_t *lum,
181 int size);
182
183void ff_deinterlace_line_inplace_mmx(const uint8_t *lum_m4,
184 const uint8_t *lum_m3,
185 const uint8_t *lum_m2,
186 const uint8_t *lum_m1,
187 const uint8_t *lum, int size);
188
a6493a8f 189#endif /* AVCODEC_X86_DSPUTIL_MMX_H */