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.

174 lines
5.5KB

  1. /*
  2. * BlackFin DSPUTILS
  3. *
  4. * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
  5. * Copyright (c) 2006 Michael Benjamin <michael.benjamin@analog.com>
  6. *
  7. * This file is part of Libav.
  8. *
  9. * Libav is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * Libav is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with Libav; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include "libavutil/attributes.h"
  24. #include "libavcodec/avcodec.h"
  25. #include "libavcodec/dsputil.h"
  26. #include "dsputil_bfin.h"
  27. int off;
  28. static void bfin_idct_add (uint8_t *dest, int line_size, int16_t *block)
  29. {
  30. ff_bfin_idct (block);
  31. ff_bfin_add_pixels_clamped (block, dest, line_size);
  32. }
  33. static void bfin_idct_put (uint8_t *dest, int line_size, int16_t *block)
  34. {
  35. ff_bfin_idct (block);
  36. ff_bfin_put_pixels_clamped (block, dest, line_size);
  37. }
  38. static void bfin_clear_blocks (int16_t *blocks)
  39. {
  40. // This is just a simple memset.
  41. //
  42. __asm__("P0=192; "
  43. "I0=%0; "
  44. "R0=0; "
  45. "LSETUP(clear_blocks_blkfn_lab,clear_blocks_blkfn_lab)LC0=P0;"
  46. "clear_blocks_blkfn_lab:"
  47. "[I0++]=R0;"
  48. ::"a" (blocks):"P0","I0","R0");
  49. }
  50. static int bfin_pix_abs16 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
  51. {
  52. return ff_bfin_z_sad16x16 (blk1,blk2,line_size,line_size,h);
  53. }
  54. static int bfin_vsad_intra16 (void *c, uint8_t *blk1, uint8_t *dummy, int stride, int h) {
  55. return ff_bfin_z_sad16x16 (blk1,blk1+stride,stride<<1,stride<<1,h);
  56. }
  57. static int bfin_vsad (void *c, uint8_t *blk1, uint8_t *blk2, int stride, int h) {
  58. return ff_bfin_z_sad16x16 (blk1,blk1+stride,stride<<1,stride<<1,h)
  59. + ff_bfin_z_sad16x16 (blk2,blk2+stride,stride<<1,stride<<1,h);
  60. }
  61. static uint8_t vtmp_blk[256] attribute_l1_data_b;
  62. static int bfin_pix_abs16_x2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
  63. {
  64. ff_bfin_put_pixels16uc (vtmp_blk, blk2, blk2+1, 16, line_size, h);
  65. return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
  66. }
  67. static int bfin_pix_abs16_y2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
  68. {
  69. ff_bfin_put_pixels16uc (vtmp_blk, blk2, blk2+line_size, 16, line_size, h);
  70. return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
  71. }
  72. static int bfin_pix_abs16_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
  73. {
  74. ff_bfin_z_put_pixels16_xy2 (vtmp_blk, blk2, 16, line_size, h);
  75. return ff_bfin_z_sad16x16 (blk1, vtmp_blk, line_size, 16, h);
  76. }
  77. static int bfin_pix_abs8 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
  78. {
  79. return ff_bfin_z_sad8x8 (blk1,blk2,line_size,line_size, h);
  80. }
  81. static int bfin_pix_abs8_x2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
  82. {
  83. ff_bfin_put_pixels8uc (vtmp_blk, blk2, blk2+1, 8, line_size, h);
  84. return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
  85. }
  86. static int bfin_pix_abs8_y2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
  87. {
  88. ff_bfin_put_pixels8uc (vtmp_blk, blk2, blk2+line_size, 8, line_size, h);
  89. return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
  90. }
  91. static int bfin_pix_abs8_xy2 (void *c, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
  92. {
  93. ff_bfin_z_put_pixels8_xy2 (vtmp_blk, blk2, 8, line_size, h);
  94. return ff_bfin_z_sad8x8 (blk1, vtmp_blk, line_size, 8, h);
  95. }
  96. /*
  97. decoder optimization
  98. start on 2/11 100 frames of 352x240@25 compiled with no optimization -g debugging
  99. 9.824s ~ 2.44x off
  100. 6.360s ~ 1.58x off with -O2
  101. 5.740s ~ 1.43x off with idcts
  102. 2.64s 2/20 same sman.mp4 decode only
  103. */
  104. av_cold void ff_dsputil_init_bfin(DSPContext *c, AVCodecContext *avctx)
  105. {
  106. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  107. c->diff_pixels = ff_bfin_diff_pixels;
  108. c->put_pixels_clamped = ff_bfin_put_pixels_clamped;
  109. c->add_pixels_clamped = ff_bfin_add_pixels_clamped;
  110. if (!high_bit_depth)
  111. c->get_pixels = ff_bfin_get_pixels;
  112. c->clear_blocks = bfin_clear_blocks;
  113. c->pix_sum = ff_bfin_pix_sum;
  114. c->pix_norm1 = ff_bfin_pix_norm1;
  115. c->sad[0] = bfin_pix_abs16;
  116. c->sad[1] = bfin_pix_abs8;
  117. /* c->vsad[0] = bfin_vsad; */
  118. /* c->vsad[4] = bfin_vsad_intra16; */
  119. /* TODO [0] 16 [1] 8 */
  120. c->pix_abs[0][0] = bfin_pix_abs16;
  121. c->pix_abs[0][1] = bfin_pix_abs16_x2;
  122. c->pix_abs[0][2] = bfin_pix_abs16_y2;
  123. c->pix_abs[0][3] = bfin_pix_abs16_xy2;
  124. c->pix_abs[1][0] = bfin_pix_abs8;
  125. c->pix_abs[1][1] = bfin_pix_abs8_x2;
  126. c->pix_abs[1][2] = bfin_pix_abs8_y2;
  127. c->pix_abs[1][3] = bfin_pix_abs8_xy2;
  128. c->sse[0] = ff_bfin_sse16;
  129. c->sse[1] = ff_bfin_sse8;
  130. c->sse[2] = ff_bfin_sse4;
  131. if (avctx->bits_per_raw_sample <= 8) {
  132. if (avctx->dct_algo == FF_DCT_AUTO)
  133. c->fdct = ff_bfin_fdct;
  134. if (avctx->idct_algo == FF_IDCT_AUTO) {
  135. c->idct_permutation_type = FF_NO_IDCT_PERM;
  136. c->idct = ff_bfin_idct;
  137. c->idct_add = bfin_idct_add;
  138. c->idct_put = bfin_idct_put;
  139. }
  140. }
  141. }