41 #if COMPILE_TEMPLATE_SSE2
42 #define MMREG_WIDTH "16"
46 "pshuflw $0, "a", "a" \n\t"\
47 "punpcklwd "a", "a" \n\t"
48 #define PMAXW(a,b) "pmaxsw "a", "b" \n\t"
50 "movhlps "a", "b" \n\t"\
52 "pshuflw $0x0E, "a", "b" \n\t"\
54 "pshuflw $0x01, "a", "b" \n\t"\
57 #define MMREG_WIDTH "8"
60 #if COMPILE_TEMPLATE_MMXEXT
61 #define SPREADW(a) "pshufw $0, "a", "a" \n\t"
62 #define PMAXW(a,b) "pmaxsw "a", "b" \n\t"
64 "pshufw $0x0E, "a", "b" \n\t"\
66 "pshufw $0x01, "a", "b" \n\t"\
70 "punpcklwd "a", "a" \n\t"\
71 "punpcklwd "a", "a" \n\t"
73 "psubusw "a", "b" \n\t"\
77 "psrlq $32, "a" \n\t"\
80 "psrlq $16, "a" \n\t"\
86 #if COMPILE_TEMPLATE_SSSE3
87 #define SAVE_SIGN(a,b) \
88 "movdqa "b", "a" \n\t"\
90 #define RESTORE_SIGN(a,b) \
91 "psignw "a", "b" \n\t"
93 #define SAVE_SIGN(a,b) \
95 "pcmpgtw "b", "a" \n\t" \
98 #define RESTORE_SIGN(a,b) \
100 "psubw "a", "b" \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
104 int16_t *
block,
int n,
109 const uint16_t *qmat, *bias;
112 av_assert2((7&(uintptr_t)(&temp_block[0])) == 0);
115 RENAME_FDCT(ff_fdct)(
block);
124 bias =
s->q_intra_matrix16[qscale][1];
125 qmat =
s->q_intra_matrix16[qscale][0];
128 bias =
s->q_chroma_intra_matrix16[qscale][1];
129 qmat =
s->q_chroma_intra_matrix16[qscale][0];
144 last_non_zero_p1 = 1;
146 last_non_zero_p1 = 0;
147 bias =
s->q_inter_matrix16[qscale][1];
148 qmat =
s->q_inter_matrix16[qscale][0];
154 "movd %%"FF_REG_a
", "MM"3 \n\t"
156 "pxor "MM"7, "MM"7 \n\t"
157 "pxor "MM"4, "MM"4 \n\t"
159 "pxor "MM"6, "MM"6 \n\t"
160 "psubw (%3), "MM"6 \n\t"
161 "mov $-128, %%"FF_REG_a
" \n\t"
164 MOVQ" (%1, %%"FF_REG_a
"), "MM"0 \n\t"
166 "psubusw "MM"6, "MM"0 \n\t"
167 "pmulhw "MM"5, "MM"0 \n\t"
168 "por "MM"0, "MM"4 \n\t"
170 MOVQ" "MM"0, (%5, %%"FF_REG_a
") \n\t"
171 "pcmpeqw "MM"7, "MM"0 \n\t"
172 MOVQ" (%4, %%"FF_REG_a
"), "MM"1 \n\t"
173 MOVQ" "MM"7, (%1, %%"FF_REG_a
") \n\t"
174 "pandn "MM"1, "MM"0 \n\t"
179 "movd "MM"3, %%"FF_REG_a
" \n\t"
180 "movzbl %%al, %%eax \n\t"
181 :
"+a" (last_non_zero_p1)
182 :
"r" (
block+64),
"r" (qmat),
"r" (bias),
185 "%xmm4",
"%xmm5",
"%xmm6",
"%xmm7")
189 "movd %%"FF_REG_a
", "MM"3 \n\t"
191 "pxor "MM"7, "MM"7 \n\t"
192 "pxor "MM"4, "MM"4 \n\t"
193 "mov $-128, %%"FF_REG_a
" \n\t"
196 MOVQ" (%1, %%"FF_REG_a
"), "MM"0 \n\t"
198 MOVQ" (%3, %%"FF_REG_a
"), "MM"6 \n\t"
199 "paddusw "MM"6, "MM"0 \n\t"
200 MOVQ" (%2, %%"FF_REG_a
"), "MM"5 \n\t"
201 "pmulhw "MM"5, "MM"0 \n\t"
202 "por "MM"0, "MM"4 \n\t"
204 MOVQ" "MM"0, (%5, %%"FF_REG_a
") \n\t"
205 "pcmpeqw "MM"7, "MM"0 \n\t"
206 MOVQ" (%4, %%"FF_REG_a
"), "MM"1 \n\t"
207 MOVQ" "MM"7, (%1, %%"FF_REG_a
") \n\t"
208 "pandn "MM"1, "MM"0 \n\t"
213 "movd "MM"3, %%"FF_REG_a
" \n\t"
214 "movzbl %%al, %%eax \n\t"
215 :
"+a" (last_non_zero_p1)
216 :
"r" (
block+64),
"r" (qmat+64),
"r" (bias+64),
219 "%xmm4",
"%xmm5",
"%xmm6",
"%xmm7")
223 "movd %1, "MM"1 \n\t"
225 "psubusw "MM"1, "MM"4 \n\t"
226 "packuswb "MM"4, "MM"4 \n\t"
227 #if COMPILE_TEMPLATE_SSE2
228 "packsswb "MM"4, "MM"4 \n\t"
230 "movd "MM"4, %0 \n\t"
232 :
"g" (
s->max_qcoeff)
236 else block[0]= temp_block[0];
239 if(last_non_zero_p1 <= 1)
goto end;
240 block[0x08] = temp_block[0x01];
block[0x10] = temp_block[0x08];
241 block[0x20] = temp_block[0x10];
242 if(last_non_zero_p1 <= 4)
goto end;
243 block[0x18] = temp_block[0x09];
block[0x04] = temp_block[0x02];
244 block[0x09] = temp_block[0x03];
245 if(last_non_zero_p1 <= 7)
goto end;
246 block[0x14] = temp_block[0x0A];
block[0x28] = temp_block[0x11];
247 block[0x12] = temp_block[0x18];
block[0x02] = temp_block[0x20];
248 if(last_non_zero_p1 <= 11)
goto end;
249 block[0x1A] = temp_block[0x19];
block[0x24] = temp_block[0x12];
250 block[0x19] = temp_block[0x0B];
block[0x01] = temp_block[0x04];
251 block[0x0C] = temp_block[0x05];
252 if(last_non_zero_p1 <= 16)
goto end;
253 block[0x11] = temp_block[0x0C];
block[0x29] = temp_block[0x13];
254 block[0x16] = temp_block[0x1A];
block[0x0A] = temp_block[0x21];
255 block[0x30] = temp_block[0x28];
block[0x22] = temp_block[0x30];
256 block[0x38] = temp_block[0x29];
block[0x06] = temp_block[0x22];
257 if(last_non_zero_p1 <= 24)
goto end;
258 block[0x1B] = temp_block[0x1B];
block[0x21] = temp_block[0x14];
259 block[0x1C] = temp_block[0x0D];
block[0x05] = temp_block[0x06];
260 block[0x0D] = temp_block[0x07];
block[0x15] = temp_block[0x0E];
261 block[0x2C] = temp_block[0x15];
block[0x13] = temp_block[0x1C];
262 if(last_non_zero_p1 <= 32)
goto end;
263 block[0x0B] = temp_block[0x23];
block[0x34] = temp_block[0x2A];
264 block[0x2A] = temp_block[0x31];
block[0x32] = temp_block[0x38];
265 block[0x3A] = temp_block[0x39];
block[0x26] = temp_block[0x32];
266 block[0x39] = temp_block[0x2B];
block[0x03] = temp_block[0x24];
267 if(last_non_zero_p1 <= 40)
goto end;
268 block[0x1E] = temp_block[0x1D];
block[0x25] = temp_block[0x16];
269 block[0x1D] = temp_block[0x0F];
block[0x2D] = temp_block[0x17];
270 block[0x17] = temp_block[0x1E];
block[0x0E] = temp_block[0x25];
271 block[0x31] = temp_block[0x2C];
block[0x2B] = temp_block[0x33];
272 if(last_non_zero_p1 <= 48)
goto end;
273 block[0x36] = temp_block[0x3A];
block[0x3B] = temp_block[0x3B];
274 block[0x23] = temp_block[0x34];
block[0x3C] = temp_block[0x2D];
275 block[0x07] = temp_block[0x26];
block[0x1F] = temp_block[0x1F];
276 block[0x0F] = temp_block[0x27];
block[0x35] = temp_block[0x2E];
277 if(last_non_zero_p1 <= 56)
goto end;
278 block[0x2E] = temp_block[0x35];
block[0x33] = temp_block[0x3C];
279 block[0x3E] = temp_block[0x3D];
block[0x27] = temp_block[0x36];
280 block[0x3D] = temp_block[0x2F];
block[0x2F] = temp_block[0x37];
281 block[0x37] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
283 if(last_non_zero_p1 <= 1)
goto end;
284 block[0x04] = temp_block[0x01];
285 block[0x08] = temp_block[0x08];
block[0x10] = temp_block[0x10];
286 if(last_non_zero_p1 <= 4)
goto end;
287 block[0x0C] = temp_block[0x09];
block[0x01] = temp_block[0x02];
288 block[0x05] = temp_block[0x03];
289 if(last_non_zero_p1 <= 7)
goto end;
290 block[0x09] = temp_block[0x0A];
block[0x14] = temp_block[0x11];
291 block[0x18] = temp_block[0x18];
block[0x20] = temp_block[0x20];
292 if(last_non_zero_p1 <= 11)
goto end;
293 block[0x1C] = temp_block[0x19];
294 block[0x11] = temp_block[0x12];
block[0x0D] = temp_block[0x0B];
295 block[0x02] = temp_block[0x04];
block[0x06] = temp_block[0x05];
296 if(last_non_zero_p1 <= 16)
goto end;
297 block[0x0A] = temp_block[0x0C];
block[0x15] = temp_block[0x13];
298 block[0x19] = temp_block[0x1A];
block[0x24] = temp_block[0x21];
299 block[0x28] = temp_block[0x28];
block[0x30] = temp_block[0x30];
300 block[0x2C] = temp_block[0x29];
block[0x21] = temp_block[0x22];
301 if(last_non_zero_p1 <= 24)
goto end;
302 block[0x1D] = temp_block[0x1B];
block[0x12] = temp_block[0x14];
303 block[0x0E] = temp_block[0x0D];
block[0x03] = temp_block[0x06];
304 block[0x07] = temp_block[0x07];
block[0x0B] = temp_block[0x0E];
305 block[0x16] = temp_block[0x15];
block[0x1A] = temp_block[0x1C];
306 if(last_non_zero_p1 <= 32)
goto end;
307 block[0x25] = temp_block[0x23];
block[0x29] = temp_block[0x2A];
308 block[0x34] = temp_block[0x31];
block[0x38] = temp_block[0x38];
309 block[0x3C] = temp_block[0x39];
block[0x31] = temp_block[0x32];
310 block[0x2D] = temp_block[0x2B];
block[0x22] = temp_block[0x24];
311 if(last_non_zero_p1 <= 40)
goto end;
312 block[0x1E] = temp_block[0x1D];
block[0x13] = temp_block[0x16];
313 block[0x0F] = temp_block[0x0F];
block[0x17] = temp_block[0x17];
314 block[0x1B] = temp_block[0x1E];
block[0x26] = temp_block[0x25];
315 block[0x2A] = temp_block[0x2C];
block[0x35] = temp_block[0x33];
316 if(last_non_zero_p1 <= 48)
goto end;
317 block[0x39] = temp_block[0x3A];
block[0x3D] = temp_block[0x3B];
318 block[0x32] = temp_block[0x34];
block[0x2E] = temp_block[0x2D];
319 block[0x23] = temp_block[0x26];
block[0x1F] = temp_block[0x1F];
320 block[0x27] = temp_block[0x27];
block[0x2B] = temp_block[0x2E];
321 if(last_non_zero_p1 <= 56)
goto end;
322 block[0x36] = temp_block[0x35];
block[0x3A] = temp_block[0x3C];
323 block[0x3E] = temp_block[0x3D];
block[0x33] = temp_block[0x36];
324 block[0x2F] = temp_block[0x2F];
block[0x37] = temp_block[0x37];
325 block[0x3B] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
327 if(last_non_zero_p1 <= 1)
goto end;
328 block[0x01] = temp_block[0x01];
329 block[0x08] = temp_block[0x08];
block[0x10] = temp_block[0x10];
330 if(last_non_zero_p1 <= 4)
goto end;
331 block[0x09] = temp_block[0x09];
block[0x02] = temp_block[0x02];
332 block[0x03] = temp_block[0x03];
333 if(last_non_zero_p1 <= 7)
goto end;
334 block[0x0A] = temp_block[0x0A];
block[0x11] = temp_block[0x11];
335 block[0x18] = temp_block[0x18];
block[0x20] = temp_block[0x20];
336 if(last_non_zero_p1 <= 11)
goto end;
337 block[0x19] = temp_block[0x19];
338 block[0x12] = temp_block[0x12];
block[0x0B] = temp_block[0x0B];
339 block[0x04] = temp_block[0x04];
block[0x05] = temp_block[0x05];
340 if(last_non_zero_p1 <= 16)
goto end;
341 block[0x0C] = temp_block[0x0C];
block[0x13] = temp_block[0x13];
342 block[0x1A] = temp_block[0x1A];
block[0x21] = temp_block[0x21];
343 block[0x28] = temp_block[0x28];
block[0x30] = temp_block[0x30];
344 block[0x29] = temp_block[0x29];
block[0x22] = temp_block[0x22];
345 if(last_non_zero_p1 <= 24)
goto end;
346 block[0x1B] = temp_block[0x1B];
block[0x14] = temp_block[0x14];
347 block[0x0D] = temp_block[0x0D];
block[0x06] = temp_block[0x06];
348 block[0x07] = temp_block[0x07];
block[0x0E] = temp_block[0x0E];
349 block[0x15] = temp_block[0x15];
block[0x1C] = temp_block[0x1C];
350 if(last_non_zero_p1 <= 32)
goto end;
351 block[0x23] = temp_block[0x23];
block[0x2A] = temp_block[0x2A];
352 block[0x31] = temp_block[0x31];
block[0x38] = temp_block[0x38];
353 block[0x39] = temp_block[0x39];
block[0x32] = temp_block[0x32];
354 block[0x2B] = temp_block[0x2B];
block[0x24] = temp_block[0x24];
355 if(last_non_zero_p1 <= 40)
goto end;
356 block[0x1D] = temp_block[0x1D];
block[0x16] = temp_block[0x16];
357 block[0x0F] = temp_block[0x0F];
block[0x17] = temp_block[0x17];
358 block[0x1E] = temp_block[0x1E];
block[0x25] = temp_block[0x25];
359 block[0x2C] = temp_block[0x2C];
block[0x33] = temp_block[0x33];
360 if(last_non_zero_p1 <= 48)
goto end;
361 block[0x3A] = temp_block[0x3A];
block[0x3B] = temp_block[0x3B];
362 block[0x34] = temp_block[0x34];
block[0x2D] = temp_block[0x2D];
363 block[0x26] = temp_block[0x26];
block[0x1F] = temp_block[0x1F];
364 block[0x27] = temp_block[0x27];
block[0x2E] = temp_block[0x2E];
365 if(last_non_zero_p1 <= 56)
goto end;
366 block[0x35] = temp_block[0x35];
block[0x3C] = temp_block[0x3C];
367 block[0x3D] = temp_block[0x3D];
block[0x36] = temp_block[0x36];
368 block[0x2F] = temp_block[0x2F];
block[0x37] = temp_block[0x37];
369 block[0x3E] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
371 if(last_non_zero_p1 <= 1)
goto end;
372 block[0x08] = temp_block[0x01];
373 block[0x01] = temp_block[0x08];
block[0x02] = temp_block[0x10];
374 if(last_non_zero_p1 <= 4)
goto end;
375 block[0x09] = temp_block[0x09];
block[0x10] = temp_block[0x02];
376 block[0x18] = temp_block[0x03];
377 if(last_non_zero_p1 <= 7)
goto end;
378 block[0x11] = temp_block[0x0A];
block[0x0A] = temp_block[0x11];
379 block[0x03] = temp_block[0x18];
block[0x04] = temp_block[0x20];
380 if(last_non_zero_p1 <= 11)
goto end;
381 block[0x0B] = temp_block[0x19];
382 block[0x12] = temp_block[0x12];
block[0x19] = temp_block[0x0B];
383 block[0x20] = temp_block[0x04];
block[0x28] = temp_block[0x05];
384 if(last_non_zero_p1 <= 16)
goto end;
385 block[0x21] = temp_block[0x0C];
block[0x1A] = temp_block[0x13];
386 block[0x13] = temp_block[0x1A];
block[0x0C] = temp_block[0x21];
387 block[0x05] = temp_block[0x28];
block[0x06] = temp_block[0x30];
388 block[0x0D] = temp_block[0x29];
block[0x14] = temp_block[0x22];
389 if(last_non_zero_p1 <= 24)
goto end;
390 block[0x1B] = temp_block[0x1B];
block[0x22] = temp_block[0x14];
391 block[0x29] = temp_block[0x0D];
block[0x30] = temp_block[0x06];
392 block[0x38] = temp_block[0x07];
block[0x31] = temp_block[0x0E];
393 block[0x2A] = temp_block[0x15];
block[0x23] = temp_block[0x1C];
394 if(last_non_zero_p1 <= 32)
goto end;
395 block[0x1C] = temp_block[0x23];
block[0x15] = temp_block[0x2A];
396 block[0x0E] = temp_block[0x31];
block[0x07] = temp_block[0x38];
397 block[0x0F] = temp_block[0x39];
block[0x16] = temp_block[0x32];
398 block[0x1D] = temp_block[0x2B];
block[0x24] = temp_block[0x24];
399 if(last_non_zero_p1 <= 40)
goto end;
400 block[0x2B] = temp_block[0x1D];
block[0x32] = temp_block[0x16];
401 block[0x39] = temp_block[0x0F];
block[0x3A] = temp_block[0x17];
402 block[0x33] = temp_block[0x1E];
block[0x2C] = temp_block[0x25];
403 block[0x25] = temp_block[0x2C];
block[0x1E] = temp_block[0x33];
404 if(last_non_zero_p1 <= 48)
goto end;
405 block[0x17] = temp_block[0x3A];
block[0x1F] = temp_block[0x3B];
406 block[0x26] = temp_block[0x34];
block[0x2D] = temp_block[0x2D];
407 block[0x34] = temp_block[0x26];
block[0x3B] = temp_block[0x1F];
408 block[0x3C] = temp_block[0x27];
block[0x35] = temp_block[0x2E];
409 if(last_non_zero_p1 <= 56)
goto end;
410 block[0x2E] = temp_block[0x35];
block[0x27] = temp_block[0x3C];
411 block[0x2F] = temp_block[0x3D];
block[0x36] = temp_block[0x36];
412 block[0x3D] = temp_block[0x2F];
block[0x3E] = temp_block[0x37];
413 block[0x37] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
416 (
int)
s->idsp.perm_type);
423 return last_non_zero_p1 - 1;