Mercurial > libavcodec.hg
annotate i386/mpegvideo_mmx.c @ 237:75123d30f862 libavcodec
optimized encode_dc() (+2% speed on P3 for mpeg1 intra only encodings)
author | michaelni |
---|---|
date | Wed, 13 Feb 2002 15:26:28 +0000 |
parents | 0b234715e205 |
children | 56ee684c48bb |
rev | line source |
---|---|
8 | 1 /* |
2 * The simplest mpeg encoder (well, it was the simplest!) | |
3 * Copyright (c) 2000,2001 Gerard Lantau. | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation; either version 2 of the License, or | |
8 * (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program; if not, write to the Free Software | |
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 * | |
19 * Optimized for ia32 cpus by Nick Kurshev <nickols_k@mail.ru> | |
200 | 20 * h263 dequantizer by Michael Niedermayer <michaelni@gmx.at> |
8 | 21 */ |
22 | |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
23 #include "../dsputil.h" |
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
24 #include "../mpegvideo.h" |
220 | 25 #include "../avcodec.h" |
26 #include "../mangle.h" | |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
27 |
200 | 28 extern UINT8 zigzag_end[64]; |
206 | 29 extern void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w); |
220 | 30 extern int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale); |
31 | |
32 extern UINT8 zigzag_direct_noperm[64]; | |
33 extern UINT16 inv_zigzag_direct16[64]; | |
34 extern UINT32 inverse[256]; | |
200 | 35 |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
36 #if 0 |
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
37 |
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
38 /* XXX: GL: I don't understand why this function needs optimization |
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
39 (it is called only once per frame!), so I disabled it */ |
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
40 |
8 | 41 void MPV_frame_start(MpegEncContext *s) |
42 { | |
43 if (s->pict_type == B_TYPE) { | |
44 __asm __volatile( | |
45 "movl (%1), %%eax\n\t" | |
46 "movl 4(%1), %%edx\n\t" | |
47 "movl 8(%1), %%ecx\n\t" | |
48 "movl %%eax, (%0)\n\t" | |
49 "movl %%edx, 4(%0)\n\t" | |
50 "movl %%ecx, 8(%0)\n\t" | |
51 : | |
52 :"r"(s->current_picture), "r"(s->aux_picture) | |
53 :"eax","edx","ecx","memory"); | |
54 } else { | |
55 /* swap next and last */ | |
56 __asm __volatile( | |
57 "movl (%1), %%eax\n\t" | |
58 "movl 4(%1), %%edx\n\t" | |
59 "movl 8(%1), %%ecx\n\t" | |
60 "xchgl (%0), %%eax\n\t" | |
61 "xchgl 4(%0), %%edx\n\t" | |
62 "xchgl 8(%0), %%ecx\n\t" | |
63 "movl %%eax, (%1)\n\t" | |
64 "movl %%edx, 4(%1)\n\t" | |
65 "movl %%ecx, 8(%1)\n\t" | |
66 "movl %%eax, (%2)\n\t" | |
67 "movl %%edx, 4(%2)\n\t" | |
68 "movl %%ecx, 8(%2)\n\t" | |
69 : | |
70 :"r"(s->last_picture), "r"(s->next_picture), "r"(s->current_picture) | |
71 :"eax","edx","ecx","memory"); | |
72 } | |
73 } | |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
74 #endif |
8 | 75 |
76 static const unsigned long long int mm_wabs __attribute__ ((aligned(8))) = 0xffffffffffffffffULL; | |
77 static const unsigned long long int mm_wone __attribute__ ((aligned(8))) = 0x0001000100010001ULL; | |
78 | |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
79 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
80 static void dct_unquantize_h263_mmx(MpegEncContext *s, |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
81 DCTELEM *block, int n, int qscale) |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
82 { |
200 | 83 int i, level, qmul, qadd, nCoeffs; |
84 | |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
85 qmul = s->qscale << 1; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
86 qadd = (s->qscale - 1) | 1; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
87 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
88 if (s->mb_intra) { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
89 if (n < 4) |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
90 block[0] = block[0] * s->y_dc_scale; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
91 else |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
92 block[0] = block[0] * s->c_dc_scale; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
93 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
94 for(i=1; i<8; i++) { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
95 level = block[i]; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
96 if (level) { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
97 if (level < 0) { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
98 level = level * qmul - qadd; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
99 } else { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
100 level = level * qmul + qadd; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
101 } |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
102 block[i] = level; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
103 } |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
104 } |
200 | 105 nCoeffs=64; |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
106 } else { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
107 i = 0; |
200 | 108 nCoeffs= zigzag_end[ s->block_last_index[n] ]; |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
109 } |
200 | 110 //printf("%d %d ", qmul, qadd); |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
111 asm volatile( |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
112 "movd %1, %%mm6 \n\t" //qmul |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
113 "packssdw %%mm6, %%mm6 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
114 "packssdw %%mm6, %%mm6 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
115 "movd %2, %%mm5 \n\t" //qadd |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
116 "pxor %%mm7, %%mm7 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
117 "packssdw %%mm5, %%mm5 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
118 "packssdw %%mm5, %%mm5 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
119 "psubw %%mm5, %%mm7 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
120 "pxor %%mm4, %%mm4 \n\t" |
153 | 121 ".balign 16\n\t" |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
122 "1: \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
123 "movq (%0, %3), %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
124 "movq 8(%0, %3), %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
125 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
126 "pmullw %%mm6, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
127 "pmullw %%mm6, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
128 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
129 "movq (%0, %3), %%mm2 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
130 "movq 8(%0, %3), %%mm3 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
131 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
132 "pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
133 "pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
134 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
135 "pxor %%mm2, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
136 "pxor %%mm3, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
137 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
138 "paddw %%mm7, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
139 "paddw %%mm7, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
140 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
141 "pxor %%mm0, %%mm2 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
142 "pxor %%mm1, %%mm3 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
143 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
144 "pcmpeqw %%mm7, %%mm0 \n\t" // block[i] == 0 ? -1 : 0 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
145 "pcmpeqw %%mm7, %%mm1 \n\t" // block[i] == 0 ? -1 : 0 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
146 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
147 "pandn %%mm2, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
148 "pandn %%mm3, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
149 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
150 "movq %%mm0, (%0, %3) \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
151 "movq %%mm1, 8(%0, %3) \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
152 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
153 "addl $16, %3 \n\t" |
200 | 154 "js 1b \n\t" |
155 ::"r" (block+nCoeffs), "g"(qmul), "g" (qadd), "r" (2*(i-nCoeffs)) | |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
156 : "memory" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
157 ); |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
158 } |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
159 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
160 |
8 | 161 /* |
162 NK: | |
163 Note: looking at PARANOID: | |
164 "enable all paranoid tests for rounding, overflows, etc..." | |
165 | |
166 #ifdef PARANOID | |
167 if (level < -2048 || level > 2047) | |
168 fprintf(stderr, "unquant error %d %d\n", i, level); | |
169 #endif | |
170 We can suppose that result of two multiplications can't be greate of 0xFFFF | |
171 i.e. is 16-bit, so we use here only PMULLW instruction and can avoid | |
172 a complex multiplication. | |
173 ===================================================== | |
174 Full formula for multiplication of 2 integer numbers | |
175 which are represent as high:low words: | |
176 input: value1 = high1:low1 | |
177 value2 = high2:low2 | |
178 output: value3 = value1*value2 | |
179 value3=high3:low3 (on overflow: modulus 2^32 wrap-around) | |
180 this mean that for 0x123456 * 0x123456 correct result is 0x766cb0ce4 | |
181 but this algorithm will compute only 0x66cb0ce4 | |
182 this limited by 16-bit size of operands | |
183 --------------------------------- | |
184 tlow1 = high1*low2 | |
185 tlow2 = high2*low1 | |
186 tlow1 = tlow1 + tlow2 | |
187 high3:low3 = low1*low2 | |
188 high3 += tlow1 | |
189 */ | |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
190 static void dct_unquantize_mpeg1_mmx(MpegEncContext *s, |
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
191 DCTELEM *block, int n, int qscale) |
8 | 192 { |
200 | 193 int i, level, nCoeffs; |
8 | 194 const UINT16 *quant_matrix; |
200 | 195 |
196 if(s->alternate_scan) nCoeffs= 64; | |
197 else nCoeffs= nCoeffs= zigzag_end[ s->block_last_index[n] ]; | |
198 | |
8 | 199 if (s->mb_intra) { |
200 if (n < 4) | |
201 block[0] = block[0] * s->y_dc_scale; | |
202 else | |
203 block[0] = block[0] * s->c_dc_scale; | |
200 | 204 /* isnt used anymore (we have a h263 unquantizer since some time) |
205 if (s->out_format == FMT_H263) { | |
8 | 206 i = 1; |
207 goto unquant_even; | |
200 | 208 }*/ |
8 | 209 /* XXX: only mpeg1 */ |
210 quant_matrix = s->intra_matrix; | |
211 i=1; | |
212 /* Align on 4 elements boundary */ | |
213 while(i&3) | |
214 { | |
215 level = block[i]; | |
216 if (level) { | |
217 if (level < 0) level = -level; | |
218 level = (int)(level * qscale * quant_matrix[i]) >> 3; | |
219 level = (level - 1) | 1; | |
220 if (block[i] < 0) level = -level; | |
221 block[i] = level; | |
222 } | |
223 i++; | |
224 } | |
225 __asm __volatile( | |
226 "movd %0, %%mm6\n\t" /* mm6 = qscale | 0 */ | |
227 "punpckldq %%mm6, %%mm6\n\t" /* mm6 = qscale | qscale */ | |
228 "movq %2, %%mm4\n\t" | |
229 "movq %%mm6, %%mm7\n\t" | |
230 "movq %1, %%mm5\n\t" | |
231 "packssdw %%mm6, %%mm7\n\t" /* mm7 = qscale | qscale | qscale | qscale */ | |
232 "pxor %%mm6, %%mm6\n\t" | |
233 ::"g"(qscale),"m"(mm_wone),"m"(mm_wabs):"memory"); | |
200 | 234 for(;i<nCoeffs;i+=4) { |
8 | 235 __asm __volatile( |
236 "movq %1, %%mm0\n\t" | |
237 "movq %%mm7, %%mm1\n\t" | |
238 "movq %%mm0, %%mm2\n\t" | |
239 "movq %%mm0, %%mm3\n\t" | |
240 "pcmpgtw %%mm6, %%mm2\n\t" | |
241 "pmullw %2, %%mm1\n\t" | |
242 "pandn %%mm4, %%mm2\n\t" | |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
243 "por %%mm5, %%mm2\n\t" |
8 | 244 "pmullw %%mm2, %%mm0\n\t" /* mm0 = abs(block[i]). */ |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
245 |
8 | 246 "pcmpeqw %%mm6, %%mm3\n\t" |
247 "pmullw %%mm0, %%mm1\n\t" | |
248 "psraw $3, %%mm1\n\t" | |
249 "psubw %%mm5, %%mm1\n\t" /* block[i] --; */ | |
250 "pandn %%mm4, %%mm3\n\t" /* fake of pcmpneqw : mm0 != 0 then mm1 = -1 */ | |
251 "por %%mm5, %%mm1\n\t" /* block[i] |= 1 */ | |
252 "pmullw %%mm2, %%mm1\n\t" /* change signs again */ | |
253 | |
254 "pand %%mm3, %%mm1\n\t" /* nullify if was zero */ | |
255 "movq %%mm1, %0" | |
256 :"=m"(block[i]) | |
257 :"m"(block[i]), "m"(quant_matrix[i]) | |
258 :"memory"); | |
259 } | |
260 } else { | |
261 i = 0; | |
220 | 262 // unquant_even: |
8 | 263 quant_matrix = s->non_intra_matrix; |
264 /* Align on 4 elements boundary */ | |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
265 while(i&7) |
8 | 266 { |
267 level = block[i]; | |
268 if (level) { | |
269 if (level < 0) level = -level; | |
270 level = (((level << 1) + 1) * qscale * | |
271 ((int) quant_matrix[i])) >> 4; | |
272 level = (level - 1) | 1; | |
273 if(block[i] < 0) level = -level; | |
274 block[i] = level; | |
275 } | |
276 i++; | |
277 } | |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
278 asm volatile( |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
279 "pcmpeqw %%mm7, %%mm7 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
280 "psrlw $15, %%mm7 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
281 "movd %2, %%mm6 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
282 "packssdw %%mm6, %%mm6 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
283 "packssdw %%mm6, %%mm6 \n\t" |
153 | 284 ".balign 16\n\t" |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
285 "1: \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
286 "movq (%0, %3), %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
287 "movq 8(%0, %3), %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
288 "movq (%1, %3), %%mm4 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
289 "movq 8(%1, %3), %%mm5 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
290 "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i] |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
291 "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i] |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
292 "pxor %%mm2, %%mm2 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
293 "pxor %%mm3, %%mm3 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
294 "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
295 "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
296 "pxor %%mm2, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
297 "pxor %%mm3, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
298 "psubw %%mm2, %%mm0 \n\t" // abs(block[i]) |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
299 "psubw %%mm3, %%mm1 \n\t" // abs(block[i]) |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
300 "paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
301 "paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
302 "paddw %%mm7, %%mm0 \n\t" // abs(block[i])*2 + 1 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
303 "paddw %%mm7, %%mm1 \n\t" // abs(block[i])*2 + 1 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
304 "pmullw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
305 "pmullw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
306 "pxor %%mm4, %%mm4 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
307 "pxor %%mm5, %%mm5 \n\t" // FIXME slow |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
308 "pcmpeqw (%0, %3), %%mm4 \n\t" // block[i] == 0 ? -1 : 0 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
309 "pcmpeqw 8(%0, %3), %%mm5 \n\t" // block[i] == 0 ? -1 : 0 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
310 "psraw $4, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
311 "psraw $4, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
312 "psubw %%mm7, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
313 "psubw %%mm7, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
314 "por %%mm7, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
315 "por %%mm7, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
316 "pxor %%mm2, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
317 "pxor %%mm3, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
318 "psubw %%mm2, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
319 "psubw %%mm3, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
320 "pandn %%mm0, %%mm4 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
321 "pandn %%mm1, %%mm5 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
322 "movq %%mm4, (%0, %3) \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
323 "movq %%mm5, 8(%0, %3) \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
324 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
325 "addl $16, %3 \n\t" |
200 | 326 "js 1b \n\t" |
327 ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "g" (qscale), "r" (2*(i-nCoeffs)) | |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
328 : "memory" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
329 ); |
8 | 330 } |
331 } | |
332 | |
206 | 333 /* draw the edges of width 'w' of an image of size width, height |
334 this mmx version can only handle w==8 || w==16 */ | |
335 static void draw_edges_mmx(UINT8 *buf, int wrap, int width, int height, int w) | |
336 { | |
337 UINT8 *ptr, *last_line; | |
338 int i; | |
339 | |
340 last_line = buf + (height - 1) * wrap; | |
341 /* left and right */ | |
342 ptr = buf; | |
343 if(w==8) | |
344 { | |
345 asm volatile( | |
346 "1: \n\t" | |
347 "movd (%0), %%mm0 \n\t" | |
348 "punpcklbw %%mm0, %%mm0 \n\t" | |
349 "punpcklwd %%mm0, %%mm0 \n\t" | |
350 "punpckldq %%mm0, %%mm0 \n\t" | |
351 "movq %%mm0, -8(%0) \n\t" | |
352 "movq -8(%0, %2), %%mm1 \n\t" | |
353 "punpckhbw %%mm1, %%mm1 \n\t" | |
354 "punpckhwd %%mm1, %%mm1 \n\t" | |
355 "punpckhdq %%mm1, %%mm1 \n\t" | |
356 "movq %%mm1, (%0, %2) \n\t" | |
357 "addl %1, %0 \n\t" | |
358 "cmpl %3, %0 \n\t" | |
359 " jb 1b \n\t" | |
360 : "+r" (ptr) | |
361 : "r" (wrap), "r" (width), "r" (ptr + wrap*height) | |
362 ); | |
363 } | |
364 else | |
365 { | |
366 asm volatile( | |
367 "1: \n\t" | |
368 "movd (%0), %%mm0 \n\t" | |
369 "punpcklbw %%mm0, %%mm0 \n\t" | |
370 "punpcklwd %%mm0, %%mm0 \n\t" | |
371 "punpckldq %%mm0, %%mm0 \n\t" | |
372 "movq %%mm0, -8(%0) \n\t" | |
373 "movq %%mm0, -16(%0) \n\t" | |
374 "movq -8(%0, %2), %%mm1 \n\t" | |
375 "punpckhbw %%mm1, %%mm1 \n\t" | |
376 "punpckhwd %%mm1, %%mm1 \n\t" | |
377 "punpckhdq %%mm1, %%mm1 \n\t" | |
378 "movq %%mm1, (%0, %2) \n\t" | |
379 "movq %%mm1, 8(%0, %2) \n\t" | |
380 "addl %1, %0 \n\t" | |
381 "cmpl %3, %0 \n\t" | |
382 " jb 1b \n\t" | |
383 : "+r" (ptr) | |
384 : "r" (wrap), "r" (width), "r" (ptr + wrap*height) | |
385 ); | |
386 } | |
387 | |
388 for(i=0;i<w;i+=4) { | |
389 /* top and bottom (and hopefully also the corners) */ | |
390 ptr= buf - (i + 1) * wrap - w; | |
391 asm volatile( | |
392 "1: \n\t" | |
393 "movq (%1, %0), %%mm0 \n\t" | |
394 "movq %%mm0, (%0) \n\t" | |
395 "movq %%mm0, (%0, %2) \n\t" | |
396 "movq %%mm0, (%0, %2, 2) \n\t" | |
397 "movq %%mm0, (%0, %3) \n\t" | |
398 "addl $8, %0 \n\t" | |
399 "cmpl %4, %0 \n\t" | |
400 " jb 1b \n\t" | |
401 : "+r" (ptr) | |
402 : "r" ((int)buf - (int)ptr - w), "r" (-wrap), "r" (-wrap*3), "r" (ptr+width+2*w) | |
403 ); | |
404 ptr= last_line + (i + 1) * wrap - w; | |
405 asm volatile( | |
406 "1: \n\t" | |
407 "movq (%1, %0), %%mm0 \n\t" | |
408 "movq %%mm0, (%0) \n\t" | |
409 "movq %%mm0, (%0, %2) \n\t" | |
410 "movq %%mm0, (%0, %2, 2) \n\t" | |
411 "movq %%mm0, (%0, %3) \n\t" | |
412 "addl $8, %0 \n\t" | |
413 "cmpl %4, %0 \n\t" | |
414 " jb 1b \n\t" | |
415 : "+r" (ptr) | |
416 : "r" ((int)last_line - (int)ptr - w), "r" (wrap), "r" (wrap*3), "r" (ptr+width+2*w) | |
417 ); | |
418 } | |
419 } | |
420 | |
220 | 421 static volatile int esp_temp; |
422 | |
423 void unused_var_warning_killer(){ | |
424 esp_temp++; | |
425 } | |
426 | |
427 #undef HAVE_MMX2 | |
428 #define RENAME(a) a ## _MMX | |
429 #include "mpegvideo_mmx_template.c" | |
430 | |
431 #define HAVE_MMX2 | |
432 #undef RENAME | |
433 #define RENAME(a) a ## _MMX2 | |
434 #include "mpegvideo_mmx_template.c" | |
206 | 435 |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
436 void MPV_common_init_mmx(MpegEncContext *s) |
8 | 437 { |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
438 if (mm_flags & MM_MMX) { |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
439 if (s->out_format == FMT_H263) |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
440 s->dct_unquantize = dct_unquantize_h263_mmx; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
441 else |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
442 s->dct_unquantize = dct_unquantize_mpeg1_mmx; |
206 | 443 |
444 draw_edges = draw_edges_mmx; | |
220 | 445 |
446 if(mm_flags & MM_MMXEXT){ | |
447 dct_quantize= dct_quantize_MMX2; | |
448 }else{ | |
449 dct_quantize= dct_quantize_MMX; | |
450 } | |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
451 } |
8 | 452 } |