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.

260 lines
8.1KB

  1. /*
  2. * Copyright (c) 2002 Brian Foley
  3. * Copyright (c) 2002 Dieter Shirley
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "../dsputil.h"
  20. #include "dsputil_ppc.h"
  21. #ifdef HAVE_ALTIVEC
  22. #include "dsputil_altivec.h"
  23. #endif
  24. extern void idct_put_altivec(uint8_t *dest, int line_size, int16_t *block);
  25. extern void idct_add_altivec(uint8_t *dest, int line_size, int16_t *block);
  26. int mm_flags = 0;
  27. int mm_support(void)
  28. {
  29. int result = 0;
  30. #if HAVE_ALTIVEC
  31. if (has_altivec()) {
  32. result |= MM_ALTIVEC;
  33. }
  34. #endif /* result */
  35. return result;
  36. }
  37. #ifdef POWERPC_TBL_PERFORMANCE_REPORT
  38. unsigned long long perfdata[powerpc_perf_total][powerpc_data_total];
  39. /* list below must match enum in dsputil_ppc.h */
  40. static unsigned char* perfname[] = {
  41. "fft_calc_altivec",
  42. "gmc1_altivec",
  43. "dct_unquantize_h263_altivec",
  44. "idct_add_altivec",
  45. "idct_put_altivec",
  46. "put_pixels16_altivec",
  47. "avg_pixels16_altivec",
  48. "avg_pixels8_altivec",
  49. "put_pixels8_xy2_altivec",
  50. "put_no_rnd_pixels8_xy2_altivec",
  51. "put_pixels16_xy2_altivec",
  52. "put_no_rnd_pixels16_xy2_altivec",
  53. "clear_blocks_dcbz32_ppc"
  54. };
  55. #ifdef POWERPC_PERF_USE_PMC
  56. unsigned long long perfdata_miss[powerpc_perf_total][powerpc_data_total];
  57. #endif
  58. #include <stdio.h>
  59. #endif
  60. #ifdef POWERPC_TBL_PERFORMANCE_REPORT
  61. void powerpc_display_perf_report(void)
  62. {
  63. int i;
  64. #ifndef POWERPC_PERF_USE_PMC
  65. fprintf(stderr, "PowerPC performance report\n Values are from the Time Base register, and represent 4 bus cycles.\n");
  66. #else /* POWERPC_PERF_USE_PMC */
  67. fprintf(stderr, "PowerPC performance report\n Values are from the PMC registers, and represent whatever the registers are set to record.\n");
  68. #endif /* POWERPC_PERF_USE_PMC */
  69. for(i = 0 ; i < powerpc_perf_total ; i++)
  70. {
  71. if (perfdata[i][powerpc_data_num] != (unsigned long long)0)
  72. fprintf(stderr, " Function \"%s\" (pmc1):\n\tmin: %llu\n\tmax: %llu\n\tavg: %1.2lf (%llu)\n",
  73. perfname[i],
  74. perfdata[i][powerpc_data_min],
  75. perfdata[i][powerpc_data_max],
  76. (double)perfdata[i][powerpc_data_sum] /
  77. (double)perfdata[i][powerpc_data_num],
  78. perfdata[i][powerpc_data_num]);
  79. #ifdef POWERPC_PERF_USE_PMC
  80. if (perfdata_miss[i][powerpc_data_num] != (unsigned long long)0)
  81. fprintf(stderr, " Function \"%s\" (pmc2):\n\tmin: %llu\n\tmax: %llu\n\tavg: %1.2lf (%llu)\n",
  82. perfname[i],
  83. perfdata_miss[i][powerpc_data_min],
  84. perfdata_miss[i][powerpc_data_max],
  85. (double)perfdata_miss[i][powerpc_data_sum] /
  86. (double)perfdata_miss[i][powerpc_data_num],
  87. perfdata_miss[i][powerpc_data_num]);
  88. #endif
  89. }
  90. }
  91. #endif /* POWERPC_TBL_PERFORMANCE_REPORT */
  92. /* ***** WARNING ***** WARNING ***** WARNING ***** */
  93. /*
  94. clear_blocks_dcbz32_ppc will not work properly
  95. on PowerPC processors with a cache line size
  96. not equal to 32 bytes.
  97. Fortunately all processor used by Apple up to
  98. at least the 7450 (aka second generation G4)
  99. use 32 bytes cache line.
  100. This is due to the use of the 'dcbz' instruction.
  101. It simply clear to zero a single cache line,
  102. so you need to know the cache line size to use it !
  103. It's absurd, but it's fast...
  104. */
  105. void clear_blocks_dcbz32_ppc(DCTELEM *blocks)
  106. {
  107. POWERPC_TBL_DECLARE(powerpc_clear_blocks_dcbz32, 1);
  108. register int misal = ((unsigned long)blocks & 0x00000010);
  109. register int i = 0;
  110. POWERPC_TBL_START_COUNT(powerpc_clear_blocks_dcbz32, 1);
  111. #if 1
  112. if (misal) {
  113. ((unsigned long*)blocks)[0] = 0L;
  114. ((unsigned long*)blocks)[1] = 0L;
  115. ((unsigned long*)blocks)[2] = 0L;
  116. ((unsigned long*)blocks)[3] = 0L;
  117. i += 16;
  118. }
  119. for ( ; i < sizeof(DCTELEM)*6*64 ; i += 32) {
  120. asm volatile("dcbz %0,%1" : : "r" (blocks), "r" (i) : "memory");
  121. }
  122. if (misal) {
  123. ((unsigned long*)blocks)[188] = 0L;
  124. ((unsigned long*)blocks)[189] = 0L;
  125. ((unsigned long*)blocks)[190] = 0L;
  126. ((unsigned long*)blocks)[191] = 0L;
  127. i += 16;
  128. }
  129. #else
  130. memset(blocks, 0, sizeof(DCTELEM)*6*64);
  131. #endif
  132. POWERPC_TBL_STOP_COUNT(powerpc_clear_blocks_dcbz32, 1);
  133. }
  134. /* check dcbz report how many bytes are set to 0 by dcbz */
  135. long check_dcbz_effect(void)
  136. {
  137. register char *fakedata = (char*)av_malloc(1024);
  138. register char *fakedata_middle;
  139. register long zero = 0;
  140. register long i = 0;
  141. long count = 0;
  142. if (!fakedata)
  143. {
  144. return 0L;
  145. }
  146. fakedata_middle = (fakedata + 512);
  147. memset(fakedata, 0xFF, 1024);
  148. asm volatile("dcbz %0, %1" : : "r" (fakedata_middle), "r" (zero));
  149. for (i = 0; i < 1024 ; i ++)
  150. {
  151. if (fakedata[i] == (char)0)
  152. count++;
  153. }
  154. av_free(fakedata);
  155. return count;
  156. }
  157. void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx)
  158. {
  159. // Common optimisations whether Altivec or not
  160. switch (check_dcbz_effect()) {
  161. case 32:
  162. c->clear_blocks = clear_blocks_dcbz32_ppc;
  163. break;
  164. default:
  165. break;
  166. }
  167. #if HAVE_ALTIVEC
  168. if (has_altivec()) {
  169. mm_flags |= MM_ALTIVEC;
  170. // Altivec specific optimisations
  171. c->pix_abs16x16_x2 = pix_abs16x16_x2_altivec;
  172. c->pix_abs16x16_y2 = pix_abs16x16_y2_altivec;
  173. c->pix_abs16x16_xy2 = pix_abs16x16_xy2_altivec;
  174. c->pix_abs16x16 = pix_abs16x16_altivec;
  175. c->pix_abs8x8 = pix_abs8x8_altivec;
  176. c->sad[0]= sad16x16_altivec;
  177. c->sad[1]= sad8x8_altivec;
  178. c->pix_norm1 = pix_norm1_altivec;
  179. c->sse[1]= sse8_altivec;
  180. c->sse[0]= sse16_altivec;
  181. c->pix_sum = pix_sum_altivec;
  182. c->diff_pixels = diff_pixels_altivec;
  183. c->get_pixels = get_pixels_altivec;
  184. // next one disabled as it's untested.
  185. #if 0
  186. c->add_bytes= add_bytes_altivec;
  187. #endif /* 0 */
  188. c->put_pixels_tab[0][0] = put_pixels16_altivec;
  189. c->avg_pixels_tab[0][0] = avg_pixels16_altivec;
  190. // next one disabled as it's untested.
  191. #if 0
  192. c->avg_pixels_tab[1][0] = avg_pixels8_altivec;
  193. #endif /* 0 */
  194. c->put_pixels_tab[1][3] = put_pixels8_xy2_altivec;
  195. c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_altivec;
  196. c->put_pixels_tab[0][3] = put_pixels16_xy2_altivec;
  197. c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_altivec;
  198. c->gmc1 = gmc1_altivec;
  199. if ((avctx->idct_algo == FF_IDCT_AUTO) ||
  200. (avctx->idct_algo == FF_IDCT_ALTIVEC))
  201. {
  202. c->idct_put = idct_put_altivec;
  203. c->idct_add = idct_add_altivec;
  204. #ifndef ALTIVEC_USE_REFERENCE_C_CODE
  205. c->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
  206. #else /* ALTIVEC_USE_REFERENCE_C_CODE */
  207. c->idct_permutation_type = FF_NO_IDCT_PERM;
  208. #endif /* ALTIVEC_USE_REFERENCE_C_CODE */
  209. }
  210. #ifdef POWERPC_TBL_PERFORMANCE_REPORT
  211. {
  212. int i;
  213. for (i = 0 ; i < powerpc_perf_total ; i++)
  214. {
  215. perfdata[i][powerpc_data_min] = 0xFFFFFFFFFFFFFFFF;
  216. perfdata[i][powerpc_data_max] = 0x0000000000000000;
  217. perfdata[i][powerpc_data_sum] = 0x0000000000000000;
  218. perfdata[i][powerpc_data_num] = 0x0000000000000000;
  219. #ifdef POWERPC_PERF_USE_PMC
  220. perfdata_miss[i][powerpc_data_min] = 0xFFFFFFFFFFFFFFFF;
  221. perfdata_miss[i][powerpc_data_max] = 0x0000000000000000;
  222. perfdata_miss[i][powerpc_data_sum] = 0x0000000000000000;
  223. perfdata_miss[i][powerpc_data_num] = 0x0000000000000000;
  224. #endif /* POWERPC_PERF_USE_PMC */
  225. }
  226. }
  227. #endif /* POWERPC_TBL_PERFORMANCE_REPORT */
  228. } else
  229. #endif /* HAVE_ALTIVEC */
  230. {
  231. // Non-AltiVec PPC optimisations
  232. // ... pending ...
  233. }
  234. }