mpegvideoenc_template.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. /*
  2. * MPEG video MMX templates
  3. *
  4. * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include <stdint.h>
  23. #include "libavutil/internal.h"
  24. #include "libavutil/x86/asm.h"
  25. #include "libavcodec/mpegutils.h"
  26. #include "libavcodec/mpegvideo.h"
  27. #include "fdct.h"
  28. #undef MMREG_WIDTH
  29. #undef MM
  30. #undef MOVQ
  31. #undef SPREADW
  32. #undef PMAXW
  33. #undef PMAX
  34. #undef SAVE_SIGN
  35. #undef RESTORE_SIGN
  36. #if COMPILE_TEMPLATE_SSE2
  37. #define MMREG_WIDTH "16"
  38. #define MM "%%xmm"
  39. #define MOVQ "movdqa"
  40. #define SPREADW(a) \
  41. "pshuflw $0, "a", "a" \n\t"\
  42. "punpcklwd "a", "a" \n\t"
  43. #define PMAXW(a,b) "pmaxsw "a", "b" \n\t"
  44. #define PMAX(a,b) \
  45. "movhlps "a", "b" \n\t"\
  46. PMAXW(b, a)\
  47. "pshuflw $0x0E, "a", "b" \n\t"\
  48. PMAXW(b, a)\
  49. "pshuflw $0x01, "a", "b" \n\t"\
  50. PMAXW(b, a)
  51. #else
  52. #define MMREG_WIDTH "8"
  53. #define MM "%%mm"
  54. #define MOVQ "movq"
  55. #if COMPILE_TEMPLATE_MMXEXT
  56. #define SPREADW(a) "pshufw $0, "a", "a" \n\t"
  57. #define PMAXW(a,b) "pmaxsw "a", "b" \n\t"
  58. #define PMAX(a,b) \
  59. "pshufw $0x0E, "a", "b" \n\t"\
  60. PMAXW(b, a)\
  61. "pshufw $0x01, "a", "b" \n\t"\
  62. PMAXW(b, a)
  63. #else
  64. #define SPREADW(a) \
  65. "punpcklwd "a", "a" \n\t"\
  66. "punpcklwd "a", "a" \n\t"
  67. #define PMAXW(a,b) \
  68. "psubusw "a", "b" \n\t"\
  69. "paddw "a", "b" \n\t"
  70. #define PMAX(a,b) \
  71. "movq "a", "b" \n\t"\
  72. "psrlq $32, "a" \n\t"\
  73. PMAXW(b, a)\
  74. "movq "a", "b" \n\t"\
  75. "psrlq $16, "a" \n\t"\
  76. PMAXW(b, a)
  77. #endif
  78. #endif
  79. #if COMPILE_TEMPLATE_SSSE3
  80. #define SAVE_SIGN(a,b) \
  81. "movdqa "b", "a" \n\t"\
  82. "pabsw "b", "b" \n\t"
  83. #define RESTORE_SIGN(a,b) \
  84. "psignw "a", "b" \n\t"
  85. #else
  86. #define SAVE_SIGN(a,b) \
  87. "pxor "a", "a" \n\t"\
  88. "pcmpgtw "b", "a" \n\t" /* block[i] <= 0 ? 0xFF : 0x00 */\
  89. "pxor "a", "b" \n\t"\
  90. "psubw "a", "b" \n\t" /* ABS(block[i]) */
  91. #define RESTORE_SIGN(a,b) \
  92. "pxor "a", "b" \n\t"\
  93. "psubw "a", "b" \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
  94. #endif
  95. static int RENAME(dct_quantize)(MpegEncContext *s,
  96. int16_t *block, int n,
  97. int qscale, int *overflow)
  98. {
  99. x86_reg last_non_zero_p1;
  100. int level=0, q; //=0 is because gcc says uninitialized ...
  101. const uint16_t *qmat, *bias;
  102. LOCAL_ALIGNED_16(int16_t, temp_block, [64]);
  103. av_assert2((7&(int)(&temp_block[0])) == 0); //did gcc align it correctly?
  104. //s->fdct (block);
  105. RENAME_FDCT(ff_fdct)(block); // cannot be anything else ...
  106. if(s->dct_error_sum)
  107. s->denoise_dct(s, block);
  108. if (s->mb_intra) {
  109. int dummy;
  110. if (n < 4){
  111. q = s->y_dc_scale;
  112. bias = s->q_intra_matrix16[qscale][1];
  113. qmat = s->q_intra_matrix16[qscale][0];
  114. }else{
  115. q = s->c_dc_scale;
  116. bias = s->q_chroma_intra_matrix16[qscale][1];
  117. qmat = s->q_chroma_intra_matrix16[qscale][0];
  118. }
  119. /* note: block[0] is assumed to be positive */
  120. if (!s->h263_aic) {
  121. __asm__ volatile (
  122. "mul %%ecx \n\t"
  123. : "=d" (level), "=a"(dummy)
  124. : "a" ((block[0]>>2) + q), "c" (ff_inverse[q<<1])
  125. );
  126. } else
  127. /* For AIC we skip quant/dequant of INTRADC */
  128. level = (block[0] + 4)>>3;
  129. block[0]=0; //avoid fake overflow
  130. // temp_block[0] = (block[0] + (q >> 1)) / q;
  131. last_non_zero_p1 = 1;
  132. } else {
  133. last_non_zero_p1 = 0;
  134. bias = s->q_inter_matrix16[qscale][1];
  135. qmat = s->q_inter_matrix16[qscale][0];
  136. }
  137. if((s->out_format == FMT_H263 || s->out_format == FMT_H261) && s->mpeg_quant==0){
  138. __asm__ volatile(
  139. "movd %%"FF_REG_a", "MM"3 \n\t" // last_non_zero_p1
  140. SPREADW(MM"3")
  141. "pxor "MM"7, "MM"7 \n\t" // 0
  142. "pxor "MM"4, "MM"4 \n\t" // 0
  143. MOVQ" (%2), "MM"5 \n\t" // qmat[0]
  144. "pxor "MM"6, "MM"6 \n\t"
  145. "psubw (%3), "MM"6 \n\t" // -bias[0]
  146. "mov $-128, %%"FF_REG_a" \n\t"
  147. ".p2align 4 \n\t"
  148. "1: \n\t"
  149. MOVQ" (%1, %%"FF_REG_a"), "MM"0 \n\t" // block[i]
  150. SAVE_SIGN(MM"1", MM"0") // ABS(block[i])
  151. "psubusw "MM"6, "MM"0 \n\t" // ABS(block[i]) + bias[0]
  152. "pmulhw "MM"5, "MM"0 \n\t" // (ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16
  153. "por "MM"0, "MM"4 \n\t"
  154. RESTORE_SIGN(MM"1", MM"0") // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
  155. MOVQ" "MM"0, (%5, %%"FF_REG_a") \n\t"
  156. "pcmpeqw "MM"7, "MM"0 \n\t" // out==0 ? 0xFF : 0x00
  157. MOVQ" (%4, %%"FF_REG_a"), "MM"1 \n\t"
  158. MOVQ" "MM"7, (%1, %%"FF_REG_a") \n\t" // 0
  159. "pandn "MM"1, "MM"0 \n\t"
  160. PMAXW(MM"0", MM"3")
  161. "add $"MMREG_WIDTH", %%"FF_REG_a" \n\t"
  162. " js 1b \n\t"
  163. PMAX(MM"3", MM"0")
  164. "movd "MM"3, %%"FF_REG_a" \n\t"
  165. "movzbl %%al, %%eax \n\t" // last_non_zero_p1
  166. : "+a" (last_non_zero_p1)
  167. : "r" (block+64), "r" (qmat), "r" (bias),
  168. "r" (inv_zigzag_direct16 + 64), "r" (temp_block + 64)
  169. XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
  170. "%xmm4", "%xmm5", "%xmm6", "%xmm7")
  171. );
  172. }else{ // FMT_H263
  173. __asm__ volatile(
  174. "movd %%"FF_REG_a", "MM"3 \n\t" // last_non_zero_p1
  175. SPREADW(MM"3")
  176. "pxor "MM"7, "MM"7 \n\t" // 0
  177. "pxor "MM"4, "MM"4 \n\t" // 0
  178. "mov $-128, %%"FF_REG_a" \n\t"
  179. ".p2align 4 \n\t"
  180. "1: \n\t"
  181. MOVQ" (%1, %%"FF_REG_a"), "MM"0 \n\t" // block[i]
  182. SAVE_SIGN(MM"1", MM"0") // ABS(block[i])
  183. MOVQ" (%3, %%"FF_REG_a"), "MM"6 \n\t" // bias[0]
  184. "paddusw "MM"6, "MM"0 \n\t" // ABS(block[i]) + bias[0]
  185. MOVQ" (%2, %%"FF_REG_a"), "MM"5 \n\t" // qmat[i]
  186. "pmulhw "MM"5, "MM"0 \n\t" // (ABS(block[i])*qmat[0] + bias[0]*qmat[0])>>16
  187. "por "MM"0, "MM"4 \n\t"
  188. RESTORE_SIGN(MM"1", MM"0") // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
  189. MOVQ" "MM"0, (%5, %%"FF_REG_a") \n\t"
  190. "pcmpeqw "MM"7, "MM"0 \n\t" // out==0 ? 0xFF : 0x00
  191. MOVQ" (%4, %%"FF_REG_a"), "MM"1 \n\t"
  192. MOVQ" "MM"7, (%1, %%"FF_REG_a") \n\t" // 0
  193. "pandn "MM"1, "MM"0 \n\t"
  194. PMAXW(MM"0", MM"3")
  195. "add $"MMREG_WIDTH", %%"FF_REG_a" \n\t"
  196. " js 1b \n\t"
  197. PMAX(MM"3", MM"0")
  198. "movd "MM"3, %%"FF_REG_a" \n\t"
  199. "movzbl %%al, %%eax \n\t" // last_non_zero_p1
  200. : "+a" (last_non_zero_p1)
  201. : "r" (block+64), "r" (qmat+64), "r" (bias+64),
  202. "r" (inv_zigzag_direct16 + 64), "r" (temp_block + 64)
  203. XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
  204. "%xmm4", "%xmm5", "%xmm6", "%xmm7")
  205. );
  206. }
  207. __asm__ volatile(
  208. "movd %1, "MM"1 \n\t" // max_qcoeff
  209. SPREADW(MM"1")
  210. "psubusw "MM"1, "MM"4 \n\t"
  211. "packuswb "MM"4, "MM"4 \n\t"
  212. #if COMPILE_TEMPLATE_SSE2
  213. "packsswb "MM"4, "MM"4 \n\t"
  214. #endif
  215. "movd "MM"4, %0 \n\t" // *overflow
  216. : "=g" (*overflow)
  217. : "g" (s->max_qcoeff)
  218. );
  219. if(s->mb_intra) block[0]= level;
  220. else block[0]= temp_block[0];
  221. if (s->idsp.perm_type == FF_IDCT_PERM_SIMPLE) {
  222. if(last_non_zero_p1 <= 1) goto end;
  223. block[0x08] = temp_block[0x01]; block[0x10] = temp_block[0x08];
  224. block[0x20] = temp_block[0x10];
  225. if(last_non_zero_p1 <= 4) goto end;
  226. block[0x18] = temp_block[0x09]; block[0x04] = temp_block[0x02];
  227. block[0x09] = temp_block[0x03];
  228. if(last_non_zero_p1 <= 7) goto end;
  229. block[0x14] = temp_block[0x0A]; block[0x28] = temp_block[0x11];
  230. block[0x12] = temp_block[0x18]; block[0x02] = temp_block[0x20];
  231. if(last_non_zero_p1 <= 11) goto end;
  232. block[0x1A] = temp_block[0x19]; block[0x24] = temp_block[0x12];
  233. block[0x19] = temp_block[0x0B]; block[0x01] = temp_block[0x04];
  234. block[0x0C] = temp_block[0x05];
  235. if(last_non_zero_p1 <= 16) goto end;
  236. block[0x11] = temp_block[0x0C]; block[0x29] = temp_block[0x13];
  237. block[0x16] = temp_block[0x1A]; block[0x0A] = temp_block[0x21];
  238. block[0x30] = temp_block[0x28]; block[0x22] = temp_block[0x30];
  239. block[0x38] = temp_block[0x29]; block[0x06] = temp_block[0x22];
  240. if(last_non_zero_p1 <= 24) goto end;
  241. block[0x1B] = temp_block[0x1B]; block[0x21] = temp_block[0x14];
  242. block[0x1C] = temp_block[0x0D]; block[0x05] = temp_block[0x06];
  243. block[0x0D] = temp_block[0x07]; block[0x15] = temp_block[0x0E];
  244. block[0x2C] = temp_block[0x15]; block[0x13] = temp_block[0x1C];
  245. if(last_non_zero_p1 <= 32) goto end;
  246. block[0x0B] = temp_block[0x23]; block[0x34] = temp_block[0x2A];
  247. block[0x2A] = temp_block[0x31]; block[0x32] = temp_block[0x38];
  248. block[0x3A] = temp_block[0x39]; block[0x26] = temp_block[0x32];
  249. block[0x39] = temp_block[0x2B]; block[0x03] = temp_block[0x24];
  250. if(last_non_zero_p1 <= 40) goto end;
  251. block[0x1E] = temp_block[0x1D]; block[0x25] = temp_block[0x16];
  252. block[0x1D] = temp_block[0x0F]; block[0x2D] = temp_block[0x17];
  253. block[0x17] = temp_block[0x1E]; block[0x0E] = temp_block[0x25];
  254. block[0x31] = temp_block[0x2C]; block[0x2B] = temp_block[0x33];
  255. if(last_non_zero_p1 <= 48) goto end;
  256. block[0x36] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
  257. block[0x23] = temp_block[0x34]; block[0x3C] = temp_block[0x2D];
  258. block[0x07] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
  259. block[0x0F] = temp_block[0x27]; block[0x35] = temp_block[0x2E];
  260. if(last_non_zero_p1 <= 56) goto end;
  261. block[0x2E] = temp_block[0x35]; block[0x33] = temp_block[0x3C];
  262. block[0x3E] = temp_block[0x3D]; block[0x27] = temp_block[0x36];
  263. block[0x3D] = temp_block[0x2F]; block[0x2F] = temp_block[0x37];
  264. block[0x37] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
  265. }else if(s->idsp.perm_type == FF_IDCT_PERM_LIBMPEG2){
  266. if(last_non_zero_p1 <= 1) goto end;
  267. block[0x04] = temp_block[0x01];
  268. block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
  269. if(last_non_zero_p1 <= 4) goto end;
  270. block[0x0C] = temp_block[0x09]; block[0x01] = temp_block[0x02];
  271. block[0x05] = temp_block[0x03];
  272. if(last_non_zero_p1 <= 7) goto end;
  273. block[0x09] = temp_block[0x0A]; block[0x14] = temp_block[0x11];
  274. block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
  275. if(last_non_zero_p1 <= 11) goto end;
  276. block[0x1C] = temp_block[0x19];
  277. block[0x11] = temp_block[0x12]; block[0x0D] = temp_block[0x0B];
  278. block[0x02] = temp_block[0x04]; block[0x06] = temp_block[0x05];
  279. if(last_non_zero_p1 <= 16) goto end;
  280. block[0x0A] = temp_block[0x0C]; block[0x15] = temp_block[0x13];
  281. block[0x19] = temp_block[0x1A]; block[0x24] = temp_block[0x21];
  282. block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
  283. block[0x2C] = temp_block[0x29]; block[0x21] = temp_block[0x22];
  284. if(last_non_zero_p1 <= 24) goto end;
  285. block[0x1D] = temp_block[0x1B]; block[0x12] = temp_block[0x14];
  286. block[0x0E] = temp_block[0x0D]; block[0x03] = temp_block[0x06];
  287. block[0x07] = temp_block[0x07]; block[0x0B] = temp_block[0x0E];
  288. block[0x16] = temp_block[0x15]; block[0x1A] = temp_block[0x1C];
  289. if(last_non_zero_p1 <= 32) goto end;
  290. block[0x25] = temp_block[0x23]; block[0x29] = temp_block[0x2A];
  291. block[0x34] = temp_block[0x31]; block[0x38] = temp_block[0x38];
  292. block[0x3C] = temp_block[0x39]; block[0x31] = temp_block[0x32];
  293. block[0x2D] = temp_block[0x2B]; block[0x22] = temp_block[0x24];
  294. if(last_non_zero_p1 <= 40) goto end;
  295. block[0x1E] = temp_block[0x1D]; block[0x13] = temp_block[0x16];
  296. block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
  297. block[0x1B] = temp_block[0x1E]; block[0x26] = temp_block[0x25];
  298. block[0x2A] = temp_block[0x2C]; block[0x35] = temp_block[0x33];
  299. if(last_non_zero_p1 <= 48) goto end;
  300. block[0x39] = temp_block[0x3A]; block[0x3D] = temp_block[0x3B];
  301. block[0x32] = temp_block[0x34]; block[0x2E] = temp_block[0x2D];
  302. block[0x23] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
  303. block[0x27] = temp_block[0x27]; block[0x2B] = temp_block[0x2E];
  304. if(last_non_zero_p1 <= 56) goto end;
  305. block[0x36] = temp_block[0x35]; block[0x3A] = temp_block[0x3C];
  306. block[0x3E] = temp_block[0x3D]; block[0x33] = temp_block[0x36];
  307. block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
  308. block[0x3B] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
  309. } else if (s->idsp.perm_type == FF_IDCT_PERM_NONE) {
  310. if(last_non_zero_p1 <= 1) goto end;
  311. block[0x01] = temp_block[0x01];
  312. block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
  313. if(last_non_zero_p1 <= 4) goto end;
  314. block[0x09] = temp_block[0x09]; block[0x02] = temp_block[0x02];
  315. block[0x03] = temp_block[0x03];
  316. if(last_non_zero_p1 <= 7) goto end;
  317. block[0x0A] = temp_block[0x0A]; block[0x11] = temp_block[0x11];
  318. block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
  319. if(last_non_zero_p1 <= 11) goto end;
  320. block[0x19] = temp_block[0x19];
  321. block[0x12] = temp_block[0x12]; block[0x0B] = temp_block[0x0B];
  322. block[0x04] = temp_block[0x04]; block[0x05] = temp_block[0x05];
  323. if(last_non_zero_p1 <= 16) goto end;
  324. block[0x0C] = temp_block[0x0C]; block[0x13] = temp_block[0x13];
  325. block[0x1A] = temp_block[0x1A]; block[0x21] = temp_block[0x21];
  326. block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
  327. block[0x29] = temp_block[0x29]; block[0x22] = temp_block[0x22];
  328. if(last_non_zero_p1 <= 24) goto end;
  329. block[0x1B] = temp_block[0x1B]; block[0x14] = temp_block[0x14];
  330. block[0x0D] = temp_block[0x0D]; block[0x06] = temp_block[0x06];
  331. block[0x07] = temp_block[0x07]; block[0x0E] = temp_block[0x0E];
  332. block[0x15] = temp_block[0x15]; block[0x1C] = temp_block[0x1C];
  333. if(last_non_zero_p1 <= 32) goto end;
  334. block[0x23] = temp_block[0x23]; block[0x2A] = temp_block[0x2A];
  335. block[0x31] = temp_block[0x31]; block[0x38] = temp_block[0x38];
  336. block[0x39] = temp_block[0x39]; block[0x32] = temp_block[0x32];
  337. block[0x2B] = temp_block[0x2B]; block[0x24] = temp_block[0x24];
  338. if(last_non_zero_p1 <= 40) goto end;
  339. block[0x1D] = temp_block[0x1D]; block[0x16] = temp_block[0x16];
  340. block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
  341. block[0x1E] = temp_block[0x1E]; block[0x25] = temp_block[0x25];
  342. block[0x2C] = temp_block[0x2C]; block[0x33] = temp_block[0x33];
  343. if(last_non_zero_p1 <= 48) goto end;
  344. block[0x3A] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
  345. block[0x34] = temp_block[0x34]; block[0x2D] = temp_block[0x2D];
  346. block[0x26] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
  347. block[0x27] = temp_block[0x27]; block[0x2E] = temp_block[0x2E];
  348. if(last_non_zero_p1 <= 56) goto end;
  349. block[0x35] = temp_block[0x35]; block[0x3C] = temp_block[0x3C];
  350. block[0x3D] = temp_block[0x3D]; block[0x36] = temp_block[0x36];
  351. block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
  352. block[0x3E] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
  353. } else if (s->idsp.perm_type == FF_IDCT_PERM_TRANSPOSE) {
  354. if(last_non_zero_p1 <= 1) goto end;
  355. block[0x08] = temp_block[0x01];
  356. block[0x01] = temp_block[0x08]; block[0x02] = temp_block[0x10];
  357. if(last_non_zero_p1 <= 4) goto end;
  358. block[0x09] = temp_block[0x09]; block[0x10] = temp_block[0x02];
  359. block[0x18] = temp_block[0x03];
  360. if(last_non_zero_p1 <= 7) goto end;
  361. block[0x11] = temp_block[0x0A]; block[0x0A] = temp_block[0x11];
  362. block[0x03] = temp_block[0x18]; block[0x04] = temp_block[0x20];
  363. if(last_non_zero_p1 <= 11) goto end;
  364. block[0x0B] = temp_block[0x19];
  365. block[0x12] = temp_block[0x12]; block[0x19] = temp_block[0x0B];
  366. block[0x20] = temp_block[0x04]; block[0x28] = temp_block[0x05];
  367. if(last_non_zero_p1 <= 16) goto end;
  368. block[0x21] = temp_block[0x0C]; block[0x1A] = temp_block[0x13];
  369. block[0x13] = temp_block[0x1A]; block[0x0C] = temp_block[0x21];
  370. block[0x05] = temp_block[0x28]; block[0x06] = temp_block[0x30];
  371. block[0x0D] = temp_block[0x29]; block[0x14] = temp_block[0x22];
  372. if(last_non_zero_p1 <= 24) goto end;
  373. block[0x1B] = temp_block[0x1B]; block[0x22] = temp_block[0x14];
  374. block[0x29] = temp_block[0x0D]; block[0x30] = temp_block[0x06];
  375. block[0x38] = temp_block[0x07]; block[0x31] = temp_block[0x0E];
  376. block[0x2A] = temp_block[0x15]; block[0x23] = temp_block[0x1C];
  377. if(last_non_zero_p1 <= 32) goto end;
  378. block[0x1C] = temp_block[0x23]; block[0x15] = temp_block[0x2A];
  379. block[0x0E] = temp_block[0x31]; block[0x07] = temp_block[0x38];
  380. block[0x0F] = temp_block[0x39]; block[0x16] = temp_block[0x32];
  381. block[0x1D] = temp_block[0x2B]; block[0x24] = temp_block[0x24];
  382. if(last_non_zero_p1 <= 40) goto end;
  383. block[0x2B] = temp_block[0x1D]; block[0x32] = temp_block[0x16];
  384. block[0x39] = temp_block[0x0F]; block[0x3A] = temp_block[0x17];
  385. block[0x33] = temp_block[0x1E]; block[0x2C] = temp_block[0x25];
  386. block[0x25] = temp_block[0x2C]; block[0x1E] = temp_block[0x33];
  387. if(last_non_zero_p1 <= 48) goto end;
  388. block[0x17] = temp_block[0x3A]; block[0x1F] = temp_block[0x3B];
  389. block[0x26] = temp_block[0x34]; block[0x2D] = temp_block[0x2D];
  390. block[0x34] = temp_block[0x26]; block[0x3B] = temp_block[0x1F];
  391. block[0x3C] = temp_block[0x27]; block[0x35] = temp_block[0x2E];
  392. if(last_non_zero_p1 <= 56) goto end;
  393. block[0x2E] = temp_block[0x35]; block[0x27] = temp_block[0x3C];
  394. block[0x2F] = temp_block[0x3D]; block[0x36] = temp_block[0x36];
  395. block[0x3D] = temp_block[0x2F]; block[0x3E] = temp_block[0x37];
  396. block[0x37] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
  397. } else {
  398. av_log(s, AV_LOG_DEBUG, "s->idsp.perm_type: %d\n",
  399. (int)s->idsp.perm_type);
  400. av_assert0(s->idsp.perm_type == FF_IDCT_PERM_NONE ||
  401. s->idsp.perm_type == FF_IDCT_PERM_LIBMPEG2 ||
  402. s->idsp.perm_type == FF_IDCT_PERM_SIMPLE ||
  403. s->idsp.perm_type == FF_IDCT_PERM_TRANSPOSE);
  404. }
  405. end:
  406. return last_non_zero_p1 - 1;
  407. }