dsputil_ppc.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVCODEC_PPC_DSPUTIL_PPC_H
  21. #define AVCODEC_PPC_DSPUTIL_PPC_H
  22. #include "config.h"
  23. #if CONFIG_POWERPC_PERF
  24. void powerpc_display_perf_report(void);
  25. /* the 604* have 2, the G3* have 4, the G4s have 6,
  26. and the G5 are completely different (they MUST use
  27. HAVE_PPC64, and let's hope all future 64 bis PPC
  28. will use the same PMCs... */
  29. #define POWERPC_NUM_PMC_ENABLED 6
  30. /* if you add to the enum below, also add to the perfname array
  31. in dsputil_ppc.c */
  32. enum powerpc_perf_index {
  33. altivec_fft_num = 0,
  34. altivec_gmc1_num,
  35. altivec_dct_unquantize_h263_num,
  36. altivec_fdct,
  37. altivec_idct_add_num,
  38. altivec_idct_put_num,
  39. altivec_put_pixels16_num,
  40. altivec_avg_pixels16_num,
  41. altivec_avg_pixels8_num,
  42. altivec_put_pixels8_xy2_num,
  43. altivec_put_no_rnd_pixels8_xy2_num,
  44. altivec_put_pixels16_xy2_num,
  45. altivec_put_no_rnd_pixels16_xy2_num,
  46. altivec_hadamard8_diff8x8_num,
  47. altivec_hadamard8_diff16_num,
  48. altivec_avg_pixels8_xy2_num,
  49. powerpc_clear_blocks_dcbz32,
  50. powerpc_clear_blocks_dcbz128,
  51. altivec_put_h264_chroma_mc8_num,
  52. altivec_avg_h264_chroma_mc8_num,
  53. altivec_put_h264_qpel16_h_lowpass_num,
  54. altivec_avg_h264_qpel16_h_lowpass_num,
  55. altivec_put_h264_qpel16_v_lowpass_num,
  56. altivec_avg_h264_qpel16_v_lowpass_num,
  57. altivec_put_h264_qpel16_hv_lowpass_num,
  58. altivec_avg_h264_qpel16_hv_lowpass_num,
  59. powerpc_perf_total
  60. };
  61. enum powerpc_data_index {
  62. powerpc_data_min = 0,
  63. powerpc_data_max,
  64. powerpc_data_sum,
  65. powerpc_data_num,
  66. powerpc_data_total
  67. };
  68. extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][powerpc_data_total];
  69. #if !HAVE_PPC64
  70. #define POWERP_PMC_DATATYPE unsigned long
  71. #define POWERPC_GET_PMC1(a) __asm__ volatile("mfspr %0, 937" : "=r" (a))
  72. #define POWERPC_GET_PMC2(a) __asm__ volatile("mfspr %0, 938" : "=r" (a))
  73. #if (POWERPC_NUM_PMC_ENABLED > 2)
  74. #define POWERPC_GET_PMC3(a) __asm__ volatile("mfspr %0, 941" : "=r" (a))
  75. #define POWERPC_GET_PMC4(a) __asm__ volatile("mfspr %0, 942" : "=r" (a))
  76. #else
  77. #define POWERPC_GET_PMC3(a) do {} while (0)
  78. #define POWERPC_GET_PMC4(a) do {} while (0)
  79. #endif
  80. #if (POWERPC_NUM_PMC_ENABLED > 4)
  81. #define POWERPC_GET_PMC5(a) __asm__ volatile("mfspr %0, 929" : "=r" (a))
  82. #define POWERPC_GET_PMC6(a) __asm__ volatile("mfspr %0, 930" : "=r" (a))
  83. #else
  84. #define POWERPC_GET_PMC5(a) do {} while (0)
  85. #define POWERPC_GET_PMC6(a) do {} while (0)
  86. #endif
  87. #else /* HAVE_PPC64 */
  88. #define POWERP_PMC_DATATYPE unsigned long long
  89. #define POWERPC_GET_PMC1(a) __asm__ volatile("mfspr %0, 771" : "=r" (a))
  90. #define POWERPC_GET_PMC2(a) __asm__ volatile("mfspr %0, 772" : "=r" (a))
  91. #if (POWERPC_NUM_PMC_ENABLED > 2)
  92. #define POWERPC_GET_PMC3(a) __asm__ volatile("mfspr %0, 773" : "=r" (a))
  93. #define POWERPC_GET_PMC4(a) __asm__ volatile("mfspr %0, 774" : "=r" (a))
  94. #else
  95. #define POWERPC_GET_PMC3(a) do {} while (0)
  96. #define POWERPC_GET_PMC4(a) do {} while (0)
  97. #endif
  98. #if (POWERPC_NUM_PMC_ENABLED > 4)
  99. #define POWERPC_GET_PMC5(a) __asm__ volatile("mfspr %0, 775" : "=r" (a))
  100. #define POWERPC_GET_PMC6(a) __asm__ volatile("mfspr %0, 776" : "=r" (a))
  101. #else
  102. #define POWERPC_GET_PMC5(a) do {} while (0)
  103. #define POWERPC_GET_PMC6(a) do {} while (0)
  104. #endif
  105. #endif /* HAVE_PPC64 */
  106. #define POWERPC_PERF_DECLARE(a, cond) \
  107. POWERP_PMC_DATATYPE \
  108. pmc_start[POWERPC_NUM_PMC_ENABLED], \
  109. pmc_stop[POWERPC_NUM_PMC_ENABLED], \
  110. pmc_loop_index;
  111. #define POWERPC_PERF_START_COUNT(a, cond) do { \
  112. POWERPC_GET_PMC6(pmc_start[5]); \
  113. POWERPC_GET_PMC5(pmc_start[4]); \
  114. POWERPC_GET_PMC4(pmc_start[3]); \
  115. POWERPC_GET_PMC3(pmc_start[2]); \
  116. POWERPC_GET_PMC2(pmc_start[1]); \
  117. POWERPC_GET_PMC1(pmc_start[0]); \
  118. } while (0)
  119. #define POWERPC_PERF_STOP_COUNT(a, cond) do { \
  120. POWERPC_GET_PMC1(pmc_stop[0]); \
  121. POWERPC_GET_PMC2(pmc_stop[1]); \
  122. POWERPC_GET_PMC3(pmc_stop[2]); \
  123. POWERPC_GET_PMC4(pmc_stop[3]); \
  124. POWERPC_GET_PMC5(pmc_stop[4]); \
  125. POWERPC_GET_PMC6(pmc_stop[5]); \
  126. if (cond) { \
  127. for(pmc_loop_index = 0; \
  128. pmc_loop_index < POWERPC_NUM_PMC_ENABLED; \
  129. pmc_loop_index++) { \
  130. if (pmc_stop[pmc_loop_index] >= pmc_start[pmc_loop_index]) { \
  131. POWERP_PMC_DATATYPE diff = \
  132. pmc_stop[pmc_loop_index] - pmc_start[pmc_loop_index]; \
  133. if (diff < perfdata[pmc_loop_index][a][powerpc_data_min]) \
  134. perfdata[pmc_loop_index][a][powerpc_data_min] = diff; \
  135. if (diff > perfdata[pmc_loop_index][a][powerpc_data_max]) \
  136. perfdata[pmc_loop_index][a][powerpc_data_max] = diff; \
  137. perfdata[pmc_loop_index][a][powerpc_data_sum] += diff; \
  138. perfdata[pmc_loop_index][a][powerpc_data_num] ++; \
  139. } \
  140. } \
  141. } \
  142. } while (0)
  143. #else /* CONFIG_POWERPC_PERF */
  144. // those are needed to avoid empty statements.
  145. #define POWERPC_PERF_DECLARE(a, cond) int altivec_placeholder __attribute__ ((unused))
  146. #define POWERPC_PERF_START_COUNT(a, cond) do {} while (0)
  147. #define POWERPC_PERF_STOP_COUNT(a, cond) do {} while (0)
  148. #endif /* CONFIG_POWERPC_PERF */
  149. #endif /* AVCODEC_PPC_DSPUTIL_PPC_H */