You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
5.4KB

  1. /*
  2. * BlackFin MPEGVIDEO OPTIMIZATIONS
  3. *
  4. * Copyright (C) 2007 Marc Hoffman <mmh@pleasantst.com>
  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 "dsputil.h"
  23. #include "mpegvideo.h"
  24. #include "avcodec.h"
  25. #include "dsputil_bfin.h"
  26. extern void ff_bfin_fdct (DCTELEM *block) attribute_l1_text;
  27. static int dct_quantize_bfin (MpegEncContext *s,
  28. DCTELEM *block, int n,
  29. int qscale, int *overflow)
  30. {
  31. int last_non_zero, q, start_i;
  32. const short *qmat;
  33. short *bias;
  34. const uint8_t *scantable= s->intra_scantable.scantable;
  35. short dc;
  36. int max=0;
  37. PROF("fdct",0);
  38. ff_bfin_fdct (block);
  39. EPROF();
  40. PROF("denoise",1);
  41. if(s->dct_error_sum)
  42. s->denoise_dct(s, block);
  43. EPROF();
  44. PROF("quant-init",2);
  45. if (s->mb_intra) {
  46. if (!s->h263_aic) {
  47. if (n < 4)
  48. q = s->y_dc_scale;
  49. else
  50. q = s->c_dc_scale;
  51. q = q << 3;
  52. } else
  53. /* For AIC we skip quant/dequant of INTRADC */
  54. q = 1 << 3;
  55. /* note: block[0] is assumed to be positive */
  56. dc = block[0] = (block[0] + (q >> 1)) / q;
  57. start_i = 1;
  58. last_non_zero = 0;
  59. bias = s->q_intra_matrix16[qscale][1];
  60. qmat = s->q_intra_matrix16[qscale][0];
  61. } else {
  62. start_i = 0;
  63. last_non_zero = -1;
  64. bias = s->q_inter_matrix16[qscale][1];
  65. qmat = s->q_inter_matrix16[qscale][0];
  66. }
  67. EPROF();
  68. PROF("quantize",4);
  69. /* for(i=start_i; i<64; i++) { */
  70. /* sign = (block[i]>>15)|1; */
  71. /* level = ((abs(block[i])+bias[0])*qmat[i])>>16; */
  72. /* if (level < 0) level = 0; */
  73. /* max |= level; */
  74. /* level = level * sign; */
  75. /* block[i] = level; */
  76. /* } */
  77. asm volatile
  78. ("i2=%1;\n\t"
  79. "r1=[%1++]; \n\t"
  80. "r0=r1>>>15 (v); \n\t"
  81. "lsetup (0f,1f) lc0=%3; \n\t"
  82. "0: r0=r0|%4; \n\t"
  83. " r1=abs r1 (v) || r2=[%2++];\n\t"
  84. " r1=r1+|+%5; \n\t"
  85. " r1=max(r1,%6) (v); \n\t"
  86. " r1.h=(a1 =r1.h*r2.h), r1.l=(a0 =r1.l*r2.l) (tfu); \n\t"
  87. " %0=%0|r1; \n\t"
  88. " r0.h=(a1 =r1.h*r0.h), r0.l=(a0 =r1.l*r0.l) (is) || r1=[%1++];\n\t"
  89. "1: r0=r1>>>15 (v) || [i2++]=r0;\n\t"
  90. "r1=%0>>16; \n\t"
  91. "%0=%0|r1; \n\t"
  92. "%0.h=0; \n\t"
  93. : "=&d" (max)
  94. : "b" (block), "b" (qmat), "a" (32), "d" (0x00010001), "d" (bias[0]*0x10001), "d" (0)
  95. : "R0","R1","R2", "I2");
  96. if (start_i == 1) block[0] = dc;
  97. EPROF();
  98. PROF("zzscan",5);
  99. asm volatile
  100. ("r0=b[%1--] (x); \n\t"
  101. "lsetup (0f,1f) lc0=%3; \n\t" /* for(i=63; i>=start_i; i--) { */
  102. "0: p0=r0; \n\t" /* j = scantable[i]; */
  103. " p0=%2+(p0<<1); \n\t" /* if (block[j]) { */
  104. " r0=w[p0]; \n\t" /* last_non_zero = i; */
  105. " cc=r0==0; \n\t" /* break; */
  106. " if !cc jump 2f; \n\t" /* } */
  107. "1: r0=b[%1--] (x); \n\t" /* } */
  108. " %0=%4; \n\t"
  109. " jump 3f; \n\t"
  110. "2: %0=lc0; \n\t"
  111. "3:\n\t"
  112. : "=d" (last_non_zero)
  113. : "a" (scantable+63), "a" (block), "a" (63), "d" (last_non_zero)
  114. : "P0","R0");
  115. EPROF();
  116. *overflow= s->max_qcoeff < max; //overflow might have happened
  117. bfprof();
  118. /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */
  119. if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM)
  120. ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero);
  121. return last_non_zero;
  122. }
  123. void MPV_common_init_bfin (MpegEncContext *s)
  124. {
  125. s->dct_quantize= dct_quantize_bfin;
  126. }