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];
230 if(last_non_zero_p1 <= 1)
goto end;
231 block[0x08] = temp_block[0x01];
block[0x10] = temp_block[0x08];
232 block[0x20] = temp_block[0x10];
233 if(last_non_zero_p1 <= 4)
goto end;
234 block[0x18] = temp_block[0x09];
block[0x04] = temp_block[0x02];
235 block[0x09] = temp_block[0x03];
236 if(last_non_zero_p1 <= 7)
goto end;
237 block[0x14] = temp_block[0x0A];
block[0x28] = temp_block[0x11];
238 block[0x12] = temp_block[0x18];
block[0x02] = temp_block[0x20];
239 if(last_non_zero_p1 <= 11)
goto end;
240 block[0x1A] = temp_block[0x19];
block[0x24] = temp_block[0x12];
241 block[0x19] = temp_block[0x0B];
block[0x01] = temp_block[0x04];
242 block[0x0C] = temp_block[0x05];
243 if(last_non_zero_p1 <= 16)
goto end;
244 block[0x11] = temp_block[0x0C];
block[0x29] = temp_block[0x13];
245 block[0x16] = temp_block[0x1A];
block[0x0A] = temp_block[0x21];
246 block[0x30] = temp_block[0x28];
block[0x22] = temp_block[0x30];
247 block[0x38] = temp_block[0x29];
block[0x06] = temp_block[0x22];
248 if(last_non_zero_p1 <= 24)
goto end;
249 block[0x1B] = temp_block[0x1B];
block[0x21] = temp_block[0x14];
250 block[0x1C] = temp_block[0x0D];
block[0x05] = temp_block[0x06];
251 block[0x0D] = temp_block[0x07];
block[0x15] = temp_block[0x0E];
252 block[0x2C] = temp_block[0x15];
block[0x13] = temp_block[0x1C];
253 if(last_non_zero_p1 <= 32)
goto end;
254 block[0x0B] = temp_block[0x23];
block[0x34] = temp_block[0x2A];
255 block[0x2A] = temp_block[0x31];
block[0x32] = temp_block[0x38];
256 block[0x3A] = temp_block[0x39];
block[0x26] = temp_block[0x32];
257 block[0x39] = temp_block[0x2B];
block[0x03] = temp_block[0x24];
258 if(last_non_zero_p1 <= 40)
goto end;
259 block[0x1E] = temp_block[0x1D];
block[0x25] = temp_block[0x16];
260 block[0x1D] = temp_block[0x0F];
block[0x2D] = temp_block[0x17];
261 block[0x17] = temp_block[0x1E];
block[0x0E] = temp_block[0x25];
262 block[0x31] = temp_block[0x2C];
block[0x2B] = temp_block[0x33];
263 if(last_non_zero_p1 <= 48)
goto end;
264 block[0x36] = temp_block[0x3A];
block[0x3B] = temp_block[0x3B];
265 block[0x23] = temp_block[0x34];
block[0x3C] = temp_block[0x2D];
266 block[0x07] = temp_block[0x26];
block[0x1F] = temp_block[0x1F];
267 block[0x0F] = temp_block[0x27];
block[0x35] = temp_block[0x2E];
268 if(last_non_zero_p1 <= 56)
goto end;
269 block[0x2E] = temp_block[0x35];
block[0x33] = temp_block[0x3C];
270 block[0x3E] = temp_block[0x3D];
block[0x27] = temp_block[0x36];
271 block[0x3D] = temp_block[0x2F];
block[0x2F] = temp_block[0x37];
272 block[0x37] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
274 if(last_non_zero_p1 <= 1)
goto end;
275 block[0x04] = temp_block[0x01];
276 block[0x08] = temp_block[0x08];
block[0x10] = temp_block[0x10];
277 if(last_non_zero_p1 <= 4)
goto end;
278 block[0x0C] = temp_block[0x09];
block[0x01] = temp_block[0x02];
279 block[0x05] = temp_block[0x03];
280 if(last_non_zero_p1 <= 7)
goto end;
281 block[0x09] = temp_block[0x0A];
block[0x14] = temp_block[0x11];
282 block[0x18] = temp_block[0x18];
block[0x20] = temp_block[0x20];
283 if(last_non_zero_p1 <= 11)
goto end;
284 block[0x1C] = temp_block[0x19];
285 block[0x11] = temp_block[0x12];
block[0x0D] = temp_block[0x0B];
286 block[0x02] = temp_block[0x04];
block[0x06] = temp_block[0x05];
287 if(last_non_zero_p1 <= 16)
goto end;
288 block[0x0A] = temp_block[0x0C];
block[0x15] = temp_block[0x13];
289 block[0x19] = temp_block[0x1A];
block[0x24] = temp_block[0x21];
290 block[0x28] = temp_block[0x28];
block[0x30] = temp_block[0x30];
291 block[0x2C] = temp_block[0x29];
block[0x21] = temp_block[0x22];
292 if(last_non_zero_p1 <= 24)
goto end;
293 block[0x1D] = temp_block[0x1B];
block[0x12] = temp_block[0x14];
294 block[0x0E] = temp_block[0x0D];
block[0x03] = temp_block[0x06];
295 block[0x07] = temp_block[0x07];
block[0x0B] = temp_block[0x0E];
296 block[0x16] = temp_block[0x15];
block[0x1A] = temp_block[0x1C];
297 if(last_non_zero_p1 <= 32)
goto end;
298 block[0x25] = temp_block[0x23];
block[0x29] = temp_block[0x2A];
299 block[0x34] = temp_block[0x31];
block[0x38] = temp_block[0x38];
300 block[0x3C] = temp_block[0x39];
block[0x31] = temp_block[0x32];
301 block[0x2D] = temp_block[0x2B];
block[0x22] = temp_block[0x24];
302 if(last_non_zero_p1 <= 40)
goto end;
303 block[0x1E] = temp_block[0x1D];
block[0x13] = temp_block[0x16];
304 block[0x0F] = temp_block[0x0F];
block[0x17] = temp_block[0x17];
305 block[0x1B] = temp_block[0x1E];
block[0x26] = temp_block[0x25];
306 block[0x2A] = temp_block[0x2C];
block[0x35] = temp_block[0x33];
307 if(last_non_zero_p1 <= 48)
goto end;
308 block[0x39] = temp_block[0x3A];
block[0x3D] = temp_block[0x3B];
309 block[0x32] = temp_block[0x34];
block[0x2E] = temp_block[0x2D];
310 block[0x23] = temp_block[0x26];
block[0x1F] = temp_block[0x1F];
311 block[0x27] = temp_block[0x27];
block[0x2B] = temp_block[0x2E];
312 if(last_non_zero_p1 <= 56)
goto end;
313 block[0x36] = temp_block[0x35];
block[0x3A] = temp_block[0x3C];
314 block[0x3E] = temp_block[0x3D];
block[0x33] = temp_block[0x36];
315 block[0x2F] = temp_block[0x2F];
block[0x37] = temp_block[0x37];
316 block[0x3B] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
318 if(last_non_zero_p1 <= 1)
goto end;
319 block[0x01] = temp_block[0x01];
320 block[0x08] = temp_block[0x08];
block[0x10] = temp_block[0x10];
321 if(last_non_zero_p1 <= 4)
goto end;
322 block[0x09] = temp_block[0x09];
block[0x02] = temp_block[0x02];
323 block[0x03] = temp_block[0x03];
324 if(last_non_zero_p1 <= 7)
goto end;
325 block[0x0A] = temp_block[0x0A];
block[0x11] = temp_block[0x11];
326 block[0x18] = temp_block[0x18];
block[0x20] = temp_block[0x20];
327 if(last_non_zero_p1 <= 11)
goto end;
328 block[0x19] = temp_block[0x19];
329 block[0x12] = temp_block[0x12];
block[0x0B] = temp_block[0x0B];
330 block[0x04] = temp_block[0x04];
block[0x05] = temp_block[0x05];
331 if(last_non_zero_p1 <= 16)
goto end;
332 block[0x0C] = temp_block[0x0C];
block[0x13] = temp_block[0x13];
333 block[0x1A] = temp_block[0x1A];
block[0x21] = temp_block[0x21];
334 block[0x28] = temp_block[0x28];
block[0x30] = temp_block[0x30];
335 block[0x29] = temp_block[0x29];
block[0x22] = temp_block[0x22];
336 if(last_non_zero_p1 <= 24)
goto end;
337 block[0x1B] = temp_block[0x1B];
block[0x14] = temp_block[0x14];
338 block[0x0D] = temp_block[0x0D];
block[0x06] = temp_block[0x06];
339 block[0x07] = temp_block[0x07];
block[0x0E] = temp_block[0x0E];
340 block[0x15] = temp_block[0x15];
block[0x1C] = temp_block[0x1C];
341 if(last_non_zero_p1 <= 32)
goto end;
342 block[0x23] = temp_block[0x23];
block[0x2A] = temp_block[0x2A];
343 block[0x31] = temp_block[0x31];
block[0x38] = temp_block[0x38];
344 block[0x39] = temp_block[0x39];
block[0x32] = temp_block[0x32];
345 block[0x2B] = temp_block[0x2B];
block[0x24] = temp_block[0x24];
346 if(last_non_zero_p1 <= 40)
goto end;
347 block[0x1D] = temp_block[0x1D];
block[0x16] = temp_block[0x16];
348 block[0x0F] = temp_block[0x0F];
block[0x17] = temp_block[0x17];
349 block[0x1E] = temp_block[0x1E];
block[0x25] = temp_block[0x25];
350 block[0x2C] = temp_block[0x2C];
block[0x33] = temp_block[0x33];
351 if(last_non_zero_p1 <= 48)
goto end;
352 block[0x3A] = temp_block[0x3A];
block[0x3B] = temp_block[0x3B];
353 block[0x34] = temp_block[0x34];
block[0x2D] = temp_block[0x2D];
354 block[0x26] = temp_block[0x26];
block[0x1F] = temp_block[0x1F];
355 block[0x27] = temp_block[0x27];
block[0x2E] = temp_block[0x2E];
356 if(last_non_zero_p1 <= 56)
goto end;
357 block[0x35] = temp_block[0x35];
block[0x3C] = temp_block[0x3C];
358 block[0x3D] = temp_block[0x3D];
block[0x36] = temp_block[0x36];
359 block[0x2F] = temp_block[0x2F];
block[0x37] = temp_block[0x37];
360 block[0x3E] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
362 if(last_non_zero_p1 <= 1)
goto end;
363 block[0x08] = temp_block[0x01];
364 block[0x01] = temp_block[0x08];
block[0x02] = temp_block[0x10];
365 if(last_non_zero_p1 <= 4)
goto end;
366 block[0x09] = temp_block[0x09];
block[0x10] = temp_block[0x02];
367 block[0x18] = temp_block[0x03];
368 if(last_non_zero_p1 <= 7)
goto end;
369 block[0x11] = temp_block[0x0A];
block[0x0A] = temp_block[0x11];
370 block[0x03] = temp_block[0x18];
block[0x04] = temp_block[0x20];
371 if(last_non_zero_p1 <= 11)
goto end;
372 block[0x0B] = temp_block[0x19];
373 block[0x12] = temp_block[0x12];
block[0x19] = temp_block[0x0B];
374 block[0x20] = temp_block[0x04];
block[0x28] = temp_block[0x05];
375 if(last_non_zero_p1 <= 16)
goto end;
376 block[0x21] = temp_block[0x0C];
block[0x1A] = temp_block[0x13];
377 block[0x13] = temp_block[0x1A];
block[0x0C] = temp_block[0x21];
378 block[0x05] = temp_block[0x28];
block[0x06] = temp_block[0x30];
379 block[0x0D] = temp_block[0x29];
block[0x14] = temp_block[0x22];
380 if(last_non_zero_p1 <= 24)
goto end;
381 block[0x1B] = temp_block[0x1B];
block[0x22] = temp_block[0x14];
382 block[0x29] = temp_block[0x0D];
block[0x30] = temp_block[0x06];
383 block[0x38] = temp_block[0x07];
block[0x31] = temp_block[0x0E];
384 block[0x2A] = temp_block[0x15];
block[0x23] = temp_block[0x1C];
385 if(last_non_zero_p1 <= 32)
goto end;
386 block[0x1C] = temp_block[0x23];
block[0x15] = temp_block[0x2A];
387 block[0x0E] = temp_block[0x31];
block[0x07] = temp_block[0x38];
388 block[0x0F] = temp_block[0x39];
block[0x16] = temp_block[0x32];
389 block[0x1D] = temp_block[0x2B];
block[0x24] = temp_block[0x24];
390 if(last_non_zero_p1 <= 40)
goto end;
391 block[0x2B] = temp_block[0x1D];
block[0x32] = temp_block[0x16];
392 block[0x39] = temp_block[0x0F];
block[0x3A] = temp_block[0x17];
393 block[0x33] = temp_block[0x1E];
block[0x2C] = temp_block[0x25];
394 block[0x25] = temp_block[0x2C];
block[0x1E] = temp_block[0x33];
395 if(last_non_zero_p1 <= 48)
goto end;
396 block[0x17] = temp_block[0x3A];
block[0x1F] = temp_block[0x3B];
397 block[0x26] = temp_block[0x34];
block[0x2D] = temp_block[0x2D];
398 block[0x34] = temp_block[0x26];
block[0x3B] = temp_block[0x1F];
399 block[0x3C] = temp_block[0x27];
block[0x35] = temp_block[0x2E];
400 if(last_non_zero_p1 <= 56)
goto end;
401 block[0x2E] = temp_block[0x35];
block[0x27] = temp_block[0x3C];
402 block[0x2F] = temp_block[0x3D];
block[0x36] = temp_block[0x36];
403 block[0x3D] = temp_block[0x2F];
block[0x3E] = temp_block[0x37];
404 block[0x37] = temp_block[0x3E];
block[0x3F] = temp_block[0x3F];
407 (
int)
s->idsp.perm_type);
414 return last_non_zero_p1 - 1;