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.

208 lines
7.6KB

  1. /*
  2. * Optimization of some functions from mpegvideo.c for armv5te
  3. * Copyright (c) 2007 Siarhei Siamashka <ssvb@users.sourceforge.net>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "dsputil.h"
  22. #include "mpegvideo.h"
  23. #include "avcodec.h"
  24. #ifdef ENABLE_ARM_TESTS
  25. /**
  26. * h263 dequantizer supplementary function, it is performance critical and needs to
  27. * have optimized implementations for each architecture. Is also used as a reference
  28. * implementation in regression tests
  29. */
  30. static inline void dct_unquantize_h263_helper_c(DCTELEM *block, int qmul, int qadd, int count)
  31. {
  32. int i, level;
  33. for (i = 0; i < count; i++) {
  34. level = block[i];
  35. if (level) {
  36. if (level < 0) {
  37. level = level * qmul - qadd;
  38. } else {
  39. level = level * qmul + qadd;
  40. }
  41. block[i] = level;
  42. }
  43. }
  44. }
  45. #endif
  46. /* GCC 3.1 or higher is required to support symbolic names in assembly code */
  47. #if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
  48. /**
  49. * Special optimized version of dct_unquantize_h263_helper_c, it requires the block
  50. * to be at least 8 bytes aligned, and may process more elements than requested.
  51. * But it is guaranteed to never process more than 64 elements provided that
  52. * xxcount argument is <= 64, so it is safe. This macro is optimized for a common
  53. * distribution of values for nCoeffs (they are mostly multiple of 8 plus one or
  54. * two extra elements). So this macro processes data as 8 elements per loop iteration
  55. * and contains optional 2 elements processing in the end.
  56. *
  57. * Inner loop should take 6 cycles per element on arm926ej-s (Nokia 770)
  58. */
  59. #define dct_unquantize_h263_special_helper_armv5te(xxblock, xxqmul, xxqadd, xxcount) \
  60. ({ DCTELEM *xblock = xxblock; \
  61. int xqmul = xxqmul, xqadd = xxqadd, xcount = xxcount, xtmp; \
  62. int xdata1, xdata2; \
  63. __asm__ __volatile__( \
  64. "subs %[count], %[count], #2 \n\t" \
  65. "ble 2f \n\t" \
  66. "ldrd r4, [%[block], #0] \n\t" \
  67. "1: \n\t" \
  68. "ldrd r6, [%[block], #8] \n\t" \
  69. \
  70. "rsbs %[data1], %[zero], r4, asr #16 \n\t" \
  71. "addgt %[data1], %[qadd], #0 \n\t" \
  72. "rsblt %[data1], %[qadd], #0 \n\t" \
  73. "smlatbne %[data1], r4, %[qmul], %[data1] \n\t" \
  74. \
  75. "rsbs %[data2], %[zero], r5, asr #16 \n\t" \
  76. "addgt %[data2], %[qadd], #0 \n\t" \
  77. "rsblt %[data2], %[qadd], #0 \n\t" \
  78. "smlatbne %[data2], r5, %[qmul], %[data2] \n\t" \
  79. \
  80. "rsbs %[tmp], %[zero], r4, asl #16 \n\t" \
  81. "addgt %[tmp], %[qadd], #0 \n\t" \
  82. "rsblt %[tmp], %[qadd], #0 \n\t" \
  83. "smlabbne r4, r4, %[qmul], %[tmp] \n\t" \
  84. \
  85. "rsbs %[tmp], %[zero], r5, asl #16 \n\t" \
  86. "addgt %[tmp], %[qadd], #0 \n\t" \
  87. "rsblt %[tmp], %[qadd], #0 \n\t" \
  88. "smlabbne r5, r5, %[qmul], %[tmp] \n\t" \
  89. \
  90. "strh r4, [%[block]], #2 \n\t" \
  91. "strh %[data1], [%[block]], #2 \n\t" \
  92. "strh r5, [%[block]], #2 \n\t" \
  93. "strh %[data2], [%[block]], #2 \n\t" \
  94. \
  95. "rsbs %[data1], %[zero], r6, asr #16 \n\t" \
  96. "addgt %[data1], %[qadd], #0 \n\t" \
  97. "rsblt %[data1], %[qadd], #0 \n\t" \
  98. "smlatbne %[data1], r6, %[qmul], %[data1] \n\t" \
  99. \
  100. "rsbs %[data2], %[zero], r7, asr #16 \n\t" \
  101. "addgt %[data2], %[qadd], #0 \n\t" \
  102. "rsblt %[data2], %[qadd], #0 \n\t" \
  103. "smlatbne %[data2], r7, %[qmul], %[data2] \n\t" \
  104. \
  105. "rsbs %[tmp], %[zero], r6, asl #16 \n\t" \
  106. "addgt %[tmp], %[qadd], #0 \n\t" \
  107. "rsblt %[tmp], %[qadd], #0 \n\t" \
  108. "smlabbne r6, r6, %[qmul], %[tmp] \n\t" \
  109. \
  110. "rsbs %[tmp], %[zero], r7, asl #16 \n\t" \
  111. "addgt %[tmp], %[qadd], #0 \n\t" \
  112. "rsblt %[tmp], %[qadd], #0 \n\t" \
  113. "smlabbne r7, r7, %[qmul], %[tmp] \n\t" \
  114. \
  115. "strh r6, [%[block]], #2 \n\t" \
  116. "strh %[data1], [%[block]], #2 \n\t" \
  117. "strh r7, [%[block]], #2 \n\t" \
  118. "strh %[data2], [%[block]], #2 \n\t" \
  119. \
  120. "subs %[count], %[count], #8 \n\t" \
  121. "ldrgtd r4, [%[block], #0] \n\t" /* load data early to avoid load/use pipeline stall */ \
  122. "bgt 1b \n\t" \
  123. \
  124. "adds %[count], %[count], #2 \n\t" \
  125. "ble 3f \n\t" \
  126. "2: \n\t" \
  127. "ldrsh %[data1], [%[block], #0] \n\t" \
  128. "ldrsh %[data2], [%[block], #2] \n\t" \
  129. "mov %[tmp], %[qadd] \n\t" \
  130. "cmp %[data1], #0 \n\t" \
  131. "rsblt %[tmp], %[qadd], #0 \n\t" \
  132. "smlabbne %[data1], %[data1], %[qmul], %[tmp] \n\t" \
  133. "mov %[tmp], %[qadd] \n\t" \
  134. "cmp %[data2], #0 \n\t" \
  135. "rsblt %[tmp], %[qadd], #0 \n\t" \
  136. "smlabbne %[data2], %[data2], %[qmul], %[tmp] \n\t" \
  137. "strh %[data1], [%[block]], #2 \n\t" \
  138. "strh %[data2], [%[block]], #2 \n\t" \
  139. "3: \n\t" \
  140. : [block] "+&r" (xblock), [count] "+&r" (xcount), [tmp] "=&r" (xtmp), \
  141. [data1] "=&r" (xdata1), [data2] "=&r" (xdata2) \
  142. : [qmul] "r" (xqmul), [qadd] "r" (xqadd), [zero] "r" (0) \
  143. : "r4", "r5", "r6", "r7", "cc", "memory" \
  144. ); \
  145. })
  146. static void dct_unquantize_h263_intra_armv5te(MpegEncContext *s,
  147. DCTELEM *block, int n, int qscale)
  148. {
  149. int level, qmul, qadd;
  150. int nCoeffs;
  151. assert(s->block_last_index[n]>=0);
  152. qmul = qscale << 1;
  153. if (!s->h263_aic) {
  154. if (n < 4)
  155. level = block[0] * s->y_dc_scale;
  156. else
  157. level = block[0] * s->c_dc_scale;
  158. qadd = (qscale - 1) | 1;
  159. }else{
  160. qadd = 0;
  161. level = block[0];
  162. }
  163. if(s->ac_pred)
  164. nCoeffs=63;
  165. else
  166. nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
  167. dct_unquantize_h263_special_helper_armv5te(block, qmul, qadd, nCoeffs + 1);
  168. block[0] = level;
  169. }
  170. static void dct_unquantize_h263_inter_armv5te(MpegEncContext *s,
  171. DCTELEM *block, int n, int qscale)
  172. {
  173. int qmul, qadd;
  174. int nCoeffs;
  175. assert(s->block_last_index[n]>=0);
  176. qadd = (qscale - 1) | 1;
  177. qmul = qscale << 1;
  178. nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
  179. dct_unquantize_h263_special_helper_armv5te(block, qmul, qadd, nCoeffs + 1);
  180. }
  181. #define HAVE_DCT_UNQUANTIZE_H263_ARMV5TE_OPTIMIZED
  182. #endif
  183. void MPV_common_init_armv5te(MpegEncContext *s)
  184. {
  185. #ifdef HAVE_DCT_UNQUANTIZE_H263_ARMV5TE_OPTIMIZED
  186. s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_armv5te;
  187. s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_armv5te;
  188. #endif
  189. }