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"
61 "punpcklwd "a", "a" \n\t"\
62 "punpcklwd "a", "a" \n\t"
64 "psubusw "a", "b" \n\t"\
68 "psrlq $32, "a" \n\t"\
71 "psrlq $16, "a" \n\t"\
76 #if COMPILE_TEMPLATE_SSSE3
77 #define SAVE_SIGN(a,b) \
78 "movdqa "b", "a" \n\t"\
80 #define RESTORE_SIGN(a,b) \
81 "psignw "a", "b" \n\t"
83 #define SAVE_SIGN(a,b) \
85 "pcmpgtw "b", "a" \n\t" \
88 #define RESTORE_SIGN(a,b) \
90 "psubw "a", "b" \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
94 int16_t *
block,
int n,
99 const uint16_t *qmat, *
bias;
102 av_assert2((7&(uintptr_t)(&temp_block[0])) == 0);
105 RENAME_FDCT(ff_fdct)(
block);
114 bias =
s->q_intra_matrix16[qscale][1];
115 qmat =
s->q_intra_matrix16[qscale][0];
118 bias =
s->q_chroma_intra_matrix16[qscale][1];
119 qmat =
s->q_chroma_intra_matrix16[qscale][0];
134 last_non_zero_p1 = 1;
136 last_non_zero_p1 = 0;
137 bias =
s->q_inter_matrix16[qscale][1];
138 qmat =
s->q_inter_matrix16[qscale][0];
144 "movd %%"FF_REG_a
", "MM"3 \n\t"
146 "pxor "MM"7, "MM"7 \n\t"
147 "pxor "MM"4, "MM"4 \n\t"
149 "pxor "MM"6, "MM"6 \n\t"
150 "psubw (%3), "MM"6 \n\t"
151 "mov $-128, %%"FF_REG_a
" \n\t"
154 MOVQ" (%1, %%"FF_REG_a
"), "MM"0 \n\t"
156 "psubusw "MM"6, "MM"0 \n\t"
157 "pmulhw "MM"5, "MM"0 \n\t"
158 "por "MM"0, "MM"4 \n\t"
160 MOVQ" "MM"0, (%5, %%"FF_REG_a
") \n\t"
161 "pcmpeqw "MM"7, "MM"0 \n\t"
162 MOVQ" (%4, %%"FF_REG_a
"), "MM"1 \n\t"
163 MOVQ" "MM"7, (%1, %%"FF_REG_a
") \n\t"
164 "pandn "MM"1, "MM"0 \n\t"
169 "movd "MM"3, %%"FF_REG_a
" \n\t"
170 "movzbl %%al, %%eax \n\t"
171 :
"+a" (last_non_zero_p1)
172 :
"r" (
block+64),
"r" (qmat),
"r" (
bias),
175 "%xmm4",
"%xmm5",
"%xmm6",
"%xmm7")
179 "movd %%"FF_REG_a
", "MM"3 \n\t"
181 "pxor "MM"7, "MM"7 \n\t"
182 "pxor "MM"4, "MM"4 \n\t"
183 "mov $-128, %%"FF_REG_a
" \n\t"
186 MOVQ" (%1, %%"FF_REG_a
"), "MM"0 \n\t"
188 MOVQ" (%3, %%"FF_REG_a
"), "MM"6 \n\t"
189 "paddusw "MM"6, "MM"0 \n\t"
190 MOVQ" (%2, %%"FF_REG_a
"), "MM"5 \n\t"
191 "pmulhw "MM"5, "MM"0 \n\t"
192 "por "MM"0, "MM"4 \n\t"
194 MOVQ" "MM"0, (%5, %%"FF_REG_a
") \n\t"
195 "pcmpeqw "MM"7, "MM"0 \n\t"
196 MOVQ" (%4, %%"FF_REG_a
"), "MM"1 \n\t"
197 MOVQ" "MM"7, (%1, %%"FF_REG_a
") \n\t"
198 "pandn "MM"1, "MM"0 \n\t"
203 "movd "MM"3, %%"FF_REG_a
" \n\t"
204 "movzbl %%al, %%eax \n\t"
205 :
"+a" (last_non_zero_p1)
206 :
"r" (
block+64),
"r" (qmat+64),
"r" (
bias+64),
209 "%xmm4",
"%xmm5",
"%xmm6",
"%xmm7")
213 "movd %1, "MM"1 \n\t"
215 "psubusw "MM"1, "MM"4 \n\t"
216 "packuswb "MM"4, "MM"4 \n\t"
217 #if COMPILE_TEMPLATE_SSE2
218 "packsswb "MM"4, "MM"4 \n\t"
220 "movd "MM"4, %0 \n\t"
222 :
"g" (
s->max_qcoeff)
226 else block[0]= temp_block[0];
229 if(last_non_zero_p1 <= 1)
goto end;
230 block[0x08] = temp_block[0x01];
block[0x10] = temp_block[0x08];
231 block[0x20] = temp_block[0x10];
232 if(last_non_zero_p1 <= 4)
goto end;
233 block[0x18] = temp_block[0x09];
block[0x04] = temp_block[0x02];
234 block[0x09] = temp_block[0x03];
235 if(last_non_zero_p1 <= 7)
goto end;
236 block[0x14] = temp_block[0x0A];
block[0x28] = temp_block[0x11];
237 block[0x12] = temp_block[0x18];
block[0x02] = temp_block[0x20];
238 if(last_non_zero_p1 <= 11)
goto end;
239 block[0x1A] = temp_block[0x19];
block[0x24] = temp_block[0x12];
240 block[0x19] = temp_block[0x0B];
block[0x01] = temp_block[0x04];
241 block[0x0C] = temp_block[0x05];
242 if(last_non_zero_p1 <= 16)
goto end;
243 block[0x11] = temp_block[0x0C];
block[0x29] = temp_block[0x13];
244 block[0x16] = temp_block[0x1A];
block[0x0A] = temp_block[0x21];
245 block[0x30] = temp_block[0x28];
block[0x22] = temp_block[0x30];
246 block[0x38] = temp_block[0x29];
block[0x06] = temp_block[0x22];
247 if(last_non_zero_p1 <= 24)
goto end;
248 block[0x1B] = temp_block[0x1B];
block[0x21] = temp_block[0x14];
249 block[0x1C] = temp_block[0x0D];
block[0x05] = temp_block[0x06];
250 block[0x0D] = temp_block[0x07];
block[0x15] = temp_block[0x0E];
251 block[0x2C] = temp_block[0x15];
block[0x13] = temp_block[0x1C];
252 if(last_non_zero_p1 <= 32)
goto end;
253 block[0x0B] = temp_block[0x23];
block[0x34] = temp_block[0x2A];
254 block[0x2A] = temp_block[0x31];
block[0x32] = temp_block[0x38];
255 block[0x3A] = temp_block[0x39];
block[0x26] = temp_block[0x32];
256 block[0x39] = temp_block[0x2B];
block[0x03] = temp_block[0x24];
257 if(last_non_zero_p1 <= 40)
goto end;
258 block[0x1E] = temp_block[0x1D];
block[0x25] = temp_block[0x16];
259 block[0x1D] = temp_block[0x0F];
block[0x2D] = temp_block[0x17];
260 block[0x17] = temp_block[0x1E];
block[0x0E] = temp_block[0x25];
261 block[0x31] = temp_block[0x2C];
block[0x2B] = temp_block[0x33];
262 if(last_non_zero_p1 <= 48)
goto end;
263 block[0x36] = temp_block[0x3A];
block[0x3B] = temp_block[0x3B];
264 block[0x23] = temp_block[0x34];
block[0x3C] = temp_block[0x2D];
265 block[0x07] = temp_block[0x26];
block[0x1F] = temp_block[0x1F];
266 block[0x0F] = temp_block[0x27];
block[0x35] = temp_block[0x2E];
267 if(last_non_zero_p1 <= 56)
goto end;
268 block[0x2E] = temp_block[0x35];
block[0x33] = temp_block[0x3C];
269 block[0x3E] = temp_block[0x3D];
block[0x27] = temp_block[0x36];
270 block[0x3D] = temp_block[0x2F];
block[0x2F] = temp_block[0x37];
271 block[0x37] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
273 if(last_non_zero_p1 <= 1)
goto end;
274 block[0x04] = temp_block[0x01];
275 block[0x08] = temp_block[0x08];
block[0x10] = temp_block[0x10];
276 if(last_non_zero_p1 <= 4)
goto end;
277 block[0x0C] = temp_block[0x09];
block[0x01] = temp_block[0x02];
278 block[0x05] = temp_block[0x03];
279 if(last_non_zero_p1 <= 7)
goto end;
280 block[0x09] = temp_block[0x0A];
block[0x14] = temp_block[0x11];
281 block[0x18] = temp_block[0x18];
block[0x20] = temp_block[0x20];
282 if(last_non_zero_p1 <= 11)
goto end;
283 block[0x1C] = temp_block[0x19];
284 block[0x11] = temp_block[0x12];
block[0x0D] = temp_block[0x0B];
285 block[0x02] = temp_block[0x04];
block[0x06] = temp_block[0x05];
286 if(last_non_zero_p1 <= 16)
goto end;
287 block[0x0A] = temp_block[0x0C];
block[0x15] = temp_block[0x13];
288 block[0x19] = temp_block[0x1A];
block[0x24] = temp_block[0x21];
289 block[0x28] = temp_block[0x28];
block[0x30] = temp_block[0x30];
290 block[0x2C] = temp_block[0x29];
block[0x21] = temp_block[0x22];
291 if(last_non_zero_p1 <= 24)
goto end;
292 block[0x1D] = temp_block[0x1B];
block[0x12] = temp_block[0x14];
293 block[0x0E] = temp_block[0x0D];
block[0x03] = temp_block[0x06];
294 block[0x07] = temp_block[0x07];
block[0x0B] = temp_block[0x0E];
295 block[0x16] = temp_block[0x15];
block[0x1A] = temp_block[0x1C];
296 if(last_non_zero_p1 <= 32)
goto end;
297 block[0x25] = temp_block[0x23];
block[0x29] = temp_block[0x2A];
298 block[0x34] = temp_block[0x31];
block[0x38] = temp_block[0x38];
299 block[0x3C] = temp_block[0x39];
block[0x31] = temp_block[0x32];
300 block[0x2D] = temp_block[0x2B];
block[0x22] = temp_block[0x24];
301 if(last_non_zero_p1 <= 40)
goto end;
302 block[0x1E] = temp_block[0x1D];
block[0x13] = temp_block[0x16];
303 block[0x0F] = temp_block[0x0F];
block[0x17] = temp_block[0x17];
304 block[0x1B] = temp_block[0x1E];
block[0x26] = temp_block[0x25];
305 block[0x2A] = temp_block[0x2C];
block[0x35] = temp_block[0x33];
306 if(last_non_zero_p1 <= 48)
goto end;
307 block[0x39] = temp_block[0x3A];
block[0x3D] = temp_block[0x3B];
308 block[0x32] = temp_block[0x34];
block[0x2E] = temp_block[0x2D];
309 block[0x23] = temp_block[0x26];
block[0x1F] = temp_block[0x1F];
310 block[0x27] = temp_block[0x27];
block[0x2B] = temp_block[0x2E];
311 if(last_non_zero_p1 <= 56)
goto end;
312 block[0x36] = temp_block[0x35];
block[0x3A] = temp_block[0x3C];
313 block[0x3E] = temp_block[0x3D];
block[0x33] = temp_block[0x36];
314 block[0x2F] = temp_block[0x2F];
block[0x37] = temp_block[0x37];
315 block[0x3B] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
317 if(last_non_zero_p1 <= 1)
goto end;
318 block[0x01] = temp_block[0x01];
319 block[0x08] = temp_block[0x08];
block[0x10] = temp_block[0x10];
320 if(last_non_zero_p1 <= 4)
goto end;
321 block[0x09] = temp_block[0x09];
block[0x02] = temp_block[0x02];
322 block[0x03] = temp_block[0x03];
323 if(last_non_zero_p1 <= 7)
goto end;
324 block[0x0A] = temp_block[0x0A];
block[0x11] = temp_block[0x11];
325 block[0x18] = temp_block[0x18];
block[0x20] = temp_block[0x20];
326 if(last_non_zero_p1 <= 11)
goto end;
327 block[0x19] = temp_block[0x19];
328 block[0x12] = temp_block[0x12];
block[0x0B] = temp_block[0x0B];
329 block[0x04] = temp_block[0x04];
block[0x05] = temp_block[0x05];
330 if(last_non_zero_p1 <= 16)
goto end;
331 block[0x0C] = temp_block[0x0C];
block[0x13] = temp_block[0x13];
332 block[0x1A] = temp_block[0x1A];
block[0x21] = temp_block[0x21];
333 block[0x28] = temp_block[0x28];
block[0x30] = temp_block[0x30];
334 block[0x29] = temp_block[0x29];
block[0x22] = temp_block[0x22];
335 if(last_non_zero_p1 <= 24)
goto end;
336 block[0x1B] = temp_block[0x1B];
block[0x14] = temp_block[0x14];
337 block[0x0D] = temp_block[0x0D];
block[0x06] = temp_block[0x06];
338 block[0x07] = temp_block[0x07];
block[0x0E] = temp_block[0x0E];
339 block[0x15] = temp_block[0x15];
block[0x1C] = temp_block[0x1C];
340 if(last_non_zero_p1 <= 32)
goto end;
341 block[0x23] = temp_block[0x23];
block[0x2A] = temp_block[0x2A];
342 block[0x31] = temp_block[0x31];
block[0x38] = temp_block[0x38];
343 block[0x39] = temp_block[0x39];
block[0x32] = temp_block[0x32];
344 block[0x2B] = temp_block[0x2B];
block[0x24] = temp_block[0x24];
345 if(last_non_zero_p1 <= 40)
goto end;
346 block[0x1D] = temp_block[0x1D];
block[0x16] = temp_block[0x16];
347 block[0x0F] = temp_block[0x0F];
block[0x17] = temp_block[0x17];
348 block[0x1E] = temp_block[0x1E];
block[0x25] = temp_block[0x25];
349 block[0x2C] = temp_block[0x2C];
block[0x33] = temp_block[0x33];
350 if(last_non_zero_p1 <= 48)
goto end;
351 block[0x3A] = temp_block[0x3A];
block[0x3B] = temp_block[0x3B];
352 block[0x34] = temp_block[0x34];
block[0x2D] = temp_block[0x2D];
353 block[0x26] = temp_block[0x26];
block[0x1F] = temp_block[0x1F];
354 block[0x27] = temp_block[0x27];
block[0x2E] = temp_block[0x2E];
355 if(last_non_zero_p1 <= 56)
goto end;
356 block[0x35] = temp_block[0x35];
block[0x3C] = temp_block[0x3C];
357 block[0x3D] = temp_block[0x3D];
block[0x36] = temp_block[0x36];
358 block[0x2F] = temp_block[0x2F];
block[0x37] = temp_block[0x37];
359 block[0x3E] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
361 if(last_non_zero_p1 <= 1)
goto end;
362 block[0x08] = temp_block[0x01];
363 block[0x01] = temp_block[0x08];
block[0x02] = temp_block[0x10];
364 if(last_non_zero_p1 <= 4)
goto end;
365 block[0x09] = temp_block[0x09];
block[0x10] = temp_block[0x02];
366 block[0x18] = temp_block[0x03];
367 if(last_non_zero_p1 <= 7)
goto end;
368 block[0x11] = temp_block[0x0A];
block[0x0A] = temp_block[0x11];
369 block[0x03] = temp_block[0x18];
block[0x04] = temp_block[0x20];
370 if(last_non_zero_p1 <= 11)
goto end;
371 block[0x0B] = temp_block[0x19];
372 block[0x12] = temp_block[0x12];
block[0x19] = temp_block[0x0B];
373 block[0x20] = temp_block[0x04];
block[0x28] = temp_block[0x05];
374 if(last_non_zero_p1 <= 16)
goto end;
375 block[0x21] = temp_block[0x0C];
block[0x1A] = temp_block[0x13];
376 block[0x13] = temp_block[0x1A];
block[0x0C] = temp_block[0x21];
377 block[0x05] = temp_block[0x28];
block[0x06] = temp_block[0x30];
378 block[0x0D] = temp_block[0x29];
block[0x14] = temp_block[0x22];
379 if(last_non_zero_p1 <= 24)
goto end;
380 block[0x1B] = temp_block[0x1B];
block[0x22] = temp_block[0x14];
381 block[0x29] = temp_block[0x0D];
block[0x30] = temp_block[0x06];
382 block[0x38] = temp_block[0x07];
block[0x31] = temp_block[0x0E];
383 block[0x2A] = temp_block[0x15];
block[0x23] = temp_block[0x1C];
384 if(last_non_zero_p1 <= 32)
goto end;
385 block[0x1C] = temp_block[0x23];
block[0x15] = temp_block[0x2A];
386 block[0x0E] = temp_block[0x31];
block[0x07] = temp_block[0x38];
387 block[0x0F] = temp_block[0x39];
block[0x16] = temp_block[0x32];
388 block[0x1D] = temp_block[0x2B];
block[0x24] = temp_block[0x24];
389 if(last_non_zero_p1 <= 40)
goto end;
390 block[0x2B] = temp_block[0x1D];
block[0x32] = temp_block[0x16];
391 block[0x39] = temp_block[0x0F];
block[0x3A] = temp_block[0x17];
392 block[0x33] = temp_block[0x1E];
block[0x2C] = temp_block[0x25];
393 block[0x25] = temp_block[0x2C];
block[0x1E] = temp_block[0x33];
394 if(last_non_zero_p1 <= 48)
goto end;
395 block[0x17] = temp_block[0x3A];
block[0x1F] = temp_block[0x3B];
396 block[0x26] = temp_block[0x34];
block[0x2D] = temp_block[0x2D];
397 block[0x34] = temp_block[0x26];
block[0x3B] = temp_block[0x1F];
398 block[0x3C] = temp_block[0x27];
block[0x35] = temp_block[0x2E];
399 if(last_non_zero_p1 <= 56)
goto end;
400 block[0x2E] = temp_block[0x35];
block[0x27] = temp_block[0x3C];
401 block[0x2F] = temp_block[0x3D];
block[0x36] = temp_block[0x36];
402 block[0x3D] = temp_block[0x2F];
block[0x3E] = temp_block[0x37];
403 block[0x37] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
406 (
int)
s->idsp.perm_type);
413 return last_non_zero_p1 - 1;