Mercurial > libavcodec.hg
annotate i386/mpegvideo_mmx.c @ 248:56ee684c48bb libavcodec
- H.263+ decoder support for Advanded INTRA Coding (buggy)
author | pulento |
---|---|
date | Mon, 18 Feb 2002 19:33:27 +0000 |
parents | 0b234715e205 |
children | 42a0b7b16738 |
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; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
220
diff
changeset
|
86 if (s->h263_aic && s->mb_intra) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
220
diff
changeset
|
87 qadd = 0; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
220
diff
changeset
|
88 else |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
220
diff
changeset
|
89 qadd = (s->qscale - 1) | 1; |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
90 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
91 if (s->mb_intra) { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
92 if (n < 4) |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
93 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
|
94 else |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
95 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
|
96 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
97 for(i=1; i<8; i++) { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
98 level = block[i]; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
99 if (level) { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
100 if (level < 0) { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
101 level = level * qmul - qadd; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
102 } else { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
103 level = level * qmul + qadd; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
104 } |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
105 block[i] = level; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
106 } |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
107 } |
200 | 108 nCoeffs=64; |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
109 } else { |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
110 i = 0; |
200 | 111 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
|
112 } |
200 | 113 //printf("%d %d ", qmul, qadd); |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
114 asm volatile( |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
115 "movd %1, %%mm6 \n\t" //qmul |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
116 "packssdw %%mm6, %%mm6 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
117 "packssdw %%mm6, %%mm6 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
118 "movd %2, %%mm5 \n\t" //qadd |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
119 "pxor %%mm7, %%mm7 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
120 "packssdw %%mm5, %%mm5 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
121 "packssdw %%mm5, %%mm5 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
122 "psubw %%mm5, %%mm7 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
123 "pxor %%mm4, %%mm4 \n\t" |
153 | 124 ".balign 16\n\t" |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
125 "1: \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
126 "movq (%0, %3), %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
127 "movq 8(%0, %3), %%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 "pmullw %%mm6, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
130 "pmullw %%mm6, %%mm1 \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 "movq (%0, %3), %%mm2 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
133 "movq 8(%0, %3), %%mm3 \n\t" |
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 "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
|
136 "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
|
137 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
138 "pxor %%mm2, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
139 "pxor %%mm3, %%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 "paddw %%mm7, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
142 "paddw %%mm7, %%mm1 \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 "pxor %%mm0, %%mm2 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
145 "pxor %%mm1, %%mm3 \n\t" |
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 "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
|
148 "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
|
149 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
150 "pandn %%mm2, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
151 "pandn %%mm3, %%mm1 \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 "movq %%mm0, (%0, %3) \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
154 "movq %%mm1, 8(%0, %3) \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
155 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
156 "addl $16, %3 \n\t" |
200 | 157 "js 1b \n\t" |
158 ::"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
|
159 : "memory" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
160 ); |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
161 } |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
162 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
163 |
8 | 164 /* |
165 NK: | |
166 Note: looking at PARANOID: | |
167 "enable all paranoid tests for rounding, overflows, etc..." | |
168 | |
169 #ifdef PARANOID | |
170 if (level < -2048 || level > 2047) | |
171 fprintf(stderr, "unquant error %d %d\n", i, level); | |
172 #endif | |
173 We can suppose that result of two multiplications can't be greate of 0xFFFF | |
174 i.e. is 16-bit, so we use here only PMULLW instruction and can avoid | |
175 a complex multiplication. | |
176 ===================================================== | |
177 Full formula for multiplication of 2 integer numbers | |
178 which are represent as high:low words: | |
179 input: value1 = high1:low1 | |
180 value2 = high2:low2 | |
181 output: value3 = value1*value2 | |
182 value3=high3:low3 (on overflow: modulus 2^32 wrap-around) | |
183 this mean that for 0x123456 * 0x123456 correct result is 0x766cb0ce4 | |
184 but this algorithm will compute only 0x66cb0ce4 | |
185 this limited by 16-bit size of operands | |
186 --------------------------------- | |
187 tlow1 = high1*low2 | |
188 tlow2 = high2*low1 | |
189 tlow1 = tlow1 + tlow2 | |
190 high3:low3 = low1*low2 | |
191 high3 += tlow1 | |
192 */ | |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
193 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
|
194 DCTELEM *block, int n, int qscale) |
8 | 195 { |
200 | 196 int i, level, nCoeffs; |
8 | 197 const UINT16 *quant_matrix; |
200 | 198 |
199 if(s->alternate_scan) nCoeffs= 64; | |
200 else nCoeffs= nCoeffs= zigzag_end[ s->block_last_index[n] ]; | |
201 | |
8 | 202 if (s->mb_intra) { |
203 if (n < 4) | |
204 block[0] = block[0] * s->y_dc_scale; | |
205 else | |
206 block[0] = block[0] * s->c_dc_scale; | |
200 | 207 /* isnt used anymore (we have a h263 unquantizer since some time) |
208 if (s->out_format == FMT_H263) { | |
8 | 209 i = 1; |
210 goto unquant_even; | |
200 | 211 }*/ |
8 | 212 /* XXX: only mpeg1 */ |
213 quant_matrix = s->intra_matrix; | |
214 i=1; | |
215 /* Align on 4 elements boundary */ | |
216 while(i&3) | |
217 { | |
218 level = block[i]; | |
219 if (level) { | |
220 if (level < 0) level = -level; | |
221 level = (int)(level * qscale * quant_matrix[i]) >> 3; | |
222 level = (level - 1) | 1; | |
223 if (block[i] < 0) level = -level; | |
224 block[i] = level; | |
225 } | |
226 i++; | |
227 } | |
228 __asm __volatile( | |
229 "movd %0, %%mm6\n\t" /* mm6 = qscale | 0 */ | |
230 "punpckldq %%mm6, %%mm6\n\t" /* mm6 = qscale | qscale */ | |
231 "movq %2, %%mm4\n\t" | |
232 "movq %%mm6, %%mm7\n\t" | |
233 "movq %1, %%mm5\n\t" | |
234 "packssdw %%mm6, %%mm7\n\t" /* mm7 = qscale | qscale | qscale | qscale */ | |
235 "pxor %%mm6, %%mm6\n\t" | |
236 ::"g"(qscale),"m"(mm_wone),"m"(mm_wabs):"memory"); | |
200 | 237 for(;i<nCoeffs;i+=4) { |
8 | 238 __asm __volatile( |
239 "movq %1, %%mm0\n\t" | |
240 "movq %%mm7, %%mm1\n\t" | |
241 "movq %%mm0, %%mm2\n\t" | |
242 "movq %%mm0, %%mm3\n\t" | |
243 "pcmpgtw %%mm6, %%mm2\n\t" | |
244 "pmullw %2, %%mm1\n\t" | |
245 "pandn %%mm4, %%mm2\n\t" | |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
246 "por %%mm5, %%mm2\n\t" |
8 | 247 "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
|
248 |
8 | 249 "pcmpeqw %%mm6, %%mm3\n\t" |
250 "pmullw %%mm0, %%mm1\n\t" | |
251 "psraw $3, %%mm1\n\t" | |
252 "psubw %%mm5, %%mm1\n\t" /* block[i] --; */ | |
253 "pandn %%mm4, %%mm3\n\t" /* fake of pcmpneqw : mm0 != 0 then mm1 = -1 */ | |
254 "por %%mm5, %%mm1\n\t" /* block[i] |= 1 */ | |
255 "pmullw %%mm2, %%mm1\n\t" /* change signs again */ | |
256 | |
257 "pand %%mm3, %%mm1\n\t" /* nullify if was zero */ | |
258 "movq %%mm1, %0" | |
259 :"=m"(block[i]) | |
260 :"m"(block[i]), "m"(quant_matrix[i]) | |
261 :"memory"); | |
262 } | |
263 } else { | |
264 i = 0; | |
220 | 265 // unquant_even: |
8 | 266 quant_matrix = s->non_intra_matrix; |
267 /* Align on 4 elements boundary */ | |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
268 while(i&7) |
8 | 269 { |
270 level = block[i]; | |
271 if (level) { | |
272 if (level < 0) level = -level; | |
273 level = (((level << 1) + 1) * qscale * | |
274 ((int) quant_matrix[i])) >> 4; | |
275 level = (level - 1) | 1; | |
276 if(block[i] < 0) level = -level; | |
277 block[i] = level; | |
278 } | |
279 i++; | |
280 } | |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
281 asm volatile( |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
282 "pcmpeqw %%mm7, %%mm7 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
283 "psrlw $15, %%mm7 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
284 "movd %2, %%mm6 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
285 "packssdw %%mm6, %%mm6 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
286 "packssdw %%mm6, %%mm6 \n\t" |
153 | 287 ".balign 16\n\t" |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
288 "1: \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
289 "movq (%0, %3), %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
290 "movq 8(%0, %3), %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
291 "movq (%1, %3), %%mm4 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
292 "movq 8(%1, %3), %%mm5 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
293 "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
|
294 "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
|
295 "pxor %%mm2, %%mm2 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
296 "pxor %%mm3, %%mm3 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
297 "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
|
298 "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
|
299 "pxor %%mm2, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
300 "pxor %%mm3, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
301 "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
|
302 "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
|
303 "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
|
304 "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
|
305 "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
|
306 "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
|
307 "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
|
308 "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
|
309 "pxor %%mm4, %%mm4 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
310 "pxor %%mm5, %%mm5 \n\t" // FIXME slow |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
311 "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
|
312 "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
|
313 "psraw $4, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
314 "psraw $4, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
315 "psubw %%mm7, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
316 "psubw %%mm7, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
317 "por %%mm7, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
318 "por %%mm7, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
319 "pxor %%mm2, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
320 "pxor %%mm3, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
321 "psubw %%mm2, %%mm0 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
322 "psubw %%mm3, %%mm1 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
323 "pandn %%mm0, %%mm4 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
324 "pandn %%mm1, %%mm5 \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
325 "movq %%mm4, (%0, %3) \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
326 "movq %%mm5, 8(%0, %3) \n\t" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
327 |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
328 "addl $16, %3 \n\t" |
200 | 329 "js 1b \n\t" |
330 ::"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
|
331 : "memory" |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
332 ); |
8 | 333 } |
334 } | |
335 | |
206 | 336 /* draw the edges of width 'w' of an image of size width, height |
337 this mmx version can only handle w==8 || w==16 */ | |
338 static void draw_edges_mmx(UINT8 *buf, int wrap, int width, int height, int w) | |
339 { | |
340 UINT8 *ptr, *last_line; | |
341 int i; | |
342 | |
343 last_line = buf + (height - 1) * wrap; | |
344 /* left and right */ | |
345 ptr = buf; | |
346 if(w==8) | |
347 { | |
348 asm volatile( | |
349 "1: \n\t" | |
350 "movd (%0), %%mm0 \n\t" | |
351 "punpcklbw %%mm0, %%mm0 \n\t" | |
352 "punpcklwd %%mm0, %%mm0 \n\t" | |
353 "punpckldq %%mm0, %%mm0 \n\t" | |
354 "movq %%mm0, -8(%0) \n\t" | |
355 "movq -8(%0, %2), %%mm1 \n\t" | |
356 "punpckhbw %%mm1, %%mm1 \n\t" | |
357 "punpckhwd %%mm1, %%mm1 \n\t" | |
358 "punpckhdq %%mm1, %%mm1 \n\t" | |
359 "movq %%mm1, (%0, %2) \n\t" | |
360 "addl %1, %0 \n\t" | |
361 "cmpl %3, %0 \n\t" | |
362 " jb 1b \n\t" | |
363 : "+r" (ptr) | |
364 : "r" (wrap), "r" (width), "r" (ptr + wrap*height) | |
365 ); | |
366 } | |
367 else | |
368 { | |
369 asm volatile( | |
370 "1: \n\t" | |
371 "movd (%0), %%mm0 \n\t" | |
372 "punpcklbw %%mm0, %%mm0 \n\t" | |
373 "punpcklwd %%mm0, %%mm0 \n\t" | |
374 "punpckldq %%mm0, %%mm0 \n\t" | |
375 "movq %%mm0, -8(%0) \n\t" | |
376 "movq %%mm0, -16(%0) \n\t" | |
377 "movq -8(%0, %2), %%mm1 \n\t" | |
378 "punpckhbw %%mm1, %%mm1 \n\t" | |
379 "punpckhwd %%mm1, %%mm1 \n\t" | |
380 "punpckhdq %%mm1, %%mm1 \n\t" | |
381 "movq %%mm1, (%0, %2) \n\t" | |
382 "movq %%mm1, 8(%0, %2) \n\t" | |
383 "addl %1, %0 \n\t" | |
384 "cmpl %3, %0 \n\t" | |
385 " jb 1b \n\t" | |
386 : "+r" (ptr) | |
387 : "r" (wrap), "r" (width), "r" (ptr + wrap*height) | |
388 ); | |
389 } | |
390 | |
391 for(i=0;i<w;i+=4) { | |
392 /* top and bottom (and hopefully also the corners) */ | |
393 ptr= buf - (i + 1) * wrap - w; | |
394 asm volatile( | |
395 "1: \n\t" | |
396 "movq (%1, %0), %%mm0 \n\t" | |
397 "movq %%mm0, (%0) \n\t" | |
398 "movq %%mm0, (%0, %2) \n\t" | |
399 "movq %%mm0, (%0, %2, 2) \n\t" | |
400 "movq %%mm0, (%0, %3) \n\t" | |
401 "addl $8, %0 \n\t" | |
402 "cmpl %4, %0 \n\t" | |
403 " jb 1b \n\t" | |
404 : "+r" (ptr) | |
405 : "r" ((int)buf - (int)ptr - w), "r" (-wrap), "r" (-wrap*3), "r" (ptr+width+2*w) | |
406 ); | |
407 ptr= last_line + (i + 1) * wrap - w; | |
408 asm volatile( | |
409 "1: \n\t" | |
410 "movq (%1, %0), %%mm0 \n\t" | |
411 "movq %%mm0, (%0) \n\t" | |
412 "movq %%mm0, (%0, %2) \n\t" | |
413 "movq %%mm0, (%0, %2, 2) \n\t" | |
414 "movq %%mm0, (%0, %3) \n\t" | |
415 "addl $8, %0 \n\t" | |
416 "cmpl %4, %0 \n\t" | |
417 " jb 1b \n\t" | |
418 : "+r" (ptr) | |
419 : "r" ((int)last_line - (int)ptr - w), "r" (wrap), "r" (wrap*3), "r" (ptr+width+2*w) | |
420 ); | |
421 } | |
422 } | |
423 | |
220 | 424 static volatile int esp_temp; |
425 | |
426 void unused_var_warning_killer(){ | |
427 esp_temp++; | |
428 } | |
429 | |
430 #undef HAVE_MMX2 | |
431 #define RENAME(a) a ## _MMX | |
432 #include "mpegvideo_mmx_template.c" | |
433 | |
434 #define HAVE_MMX2 | |
435 #undef RENAME | |
436 #define RENAME(a) a ## _MMX2 | |
437 #include "mpegvideo_mmx_template.c" | |
206 | 438 |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
439 void MPV_common_init_mmx(MpegEncContext *s) |
8 | 440 { |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
441 if (mm_flags & MM_MMX) { |
145
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
442 if (s->out_format == FMT_H263) |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
443 s->dct_unquantize = dct_unquantize_h263_mmx; |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
444 else |
bd1adece8280
dct_unquantize_h263_mmx() by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
14
diff
changeset
|
445 s->dct_unquantize = dct_unquantize_mpeg1_mmx; |
206 | 446 |
447 draw_edges = draw_edges_mmx; | |
220 | 448 |
449 if(mm_flags & MM_MMXEXT){ | |
450 dct_quantize= dct_quantize_MMX2; | |
451 }else{ | |
452 dct_quantize= dct_quantize_MMX; | |
453 } | |
14
8ceb13af9cb6
renamed - use of s->dct_unquantize function pointer - SHOULD add faster h263 mmx specific unquantization stuff
glantau
parents:
8
diff
changeset
|
454 } |
8 | 455 } |