d028574f02022d1ae451408fce3574539c253ca1
[libav.git] / libavcodec / ppc / dsputil_ppc.h
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
21 #ifndef AVCODEC_PPC_DSPUTIL_PPC_H
22 #define AVCODEC_PPC_DSPUTIL_PPC_H
23
24 #include "config.h"
25
26 #if CONFIG_POWERPC_PERF
27 void powerpc_display_perf_report(void);
28 /* the 604* have 2, the G3* have 4, the G4s have 6,
29 and the G5 are completely different (they MUST use
30 ARCH_PPC64, and let's hope all future 64 bis PPC
31 will use the same PMCs... */
32 #define POWERPC_NUM_PMC_ENABLED 6
33 /* if you add to the enum below, also add to the perfname array
34 in dsputil_ppc.c */
35 enum powerpc_perf_index {
36 altivec_fft_num = 0,
37 altivec_gmc1_num,
38 altivec_dct_unquantize_h263_num,
39 altivec_fdct,
40 altivec_idct_add_num,
41 altivec_idct_put_num,
42 altivec_put_pixels16_num,
43 altivec_avg_pixels16_num,
44 altivec_avg_pixels8_num,
45 altivec_put_pixels8_xy2_num,
46 altivec_put_no_rnd_pixels8_xy2_num,
47 altivec_put_pixels16_xy2_num,
48 altivec_put_no_rnd_pixels16_xy2_num,
49 altivec_hadamard8_diff8x8_num,
50 altivec_hadamard8_diff16_num,
51 altivec_avg_pixels8_xy2_num,
52 powerpc_clear_blocks_dcbz32,
53 powerpc_clear_blocks_dcbz128,
54 altivec_put_h264_chroma_mc8_num,
55 altivec_avg_h264_chroma_mc8_num,
56 altivec_put_h264_qpel16_h_lowpass_num,
57 altivec_avg_h264_qpel16_h_lowpass_num,
58 altivec_put_h264_qpel16_v_lowpass_num,
59 altivec_avg_h264_qpel16_v_lowpass_num,
60 altivec_put_h264_qpel16_hv_lowpass_num,
61 altivec_avg_h264_qpel16_hv_lowpass_num,
62 powerpc_perf_total
63 };
64 enum powerpc_data_index {
65 powerpc_data_min = 0,
66 powerpc_data_max,
67 powerpc_data_sum,
68 powerpc_data_num,
69 powerpc_data_total
70 };
71 extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][powerpc_data_total];
72
73 #if !ARCH_PPC64
74 #define POWERP_PMC_DATATYPE unsigned long
75 #define POWERPC_GET_PMC1(a) __asm__ volatile("mfspr %0, 937" : "=r" (a))
76 #define POWERPC_GET_PMC2(a) __asm__ volatile("mfspr %0, 938" : "=r" (a))
77 #if (POWERPC_NUM_PMC_ENABLED > 2)
78 #define POWERPC_GET_PMC3(a) __asm__ volatile("mfspr %0, 941" : "=r" (a))
79 #define POWERPC_GET_PMC4(a) __asm__ volatile("mfspr %0, 942" : "=r" (a))
80 #else
81 #define POWERPC_GET_PMC3(a) do {} while (0)
82 #define POWERPC_GET_PMC4(a) do {} while (0)
83 #endif
84 #if (POWERPC_NUM_PMC_ENABLED > 4)
85 #define POWERPC_GET_PMC5(a) __asm__ volatile("mfspr %0, 929" : "=r" (a))
86 #define POWERPC_GET_PMC6(a) __asm__ volatile("mfspr %0, 930" : "=r" (a))
87 #else
88 #define POWERPC_GET_PMC5(a) do {} while (0)
89 #define POWERPC_GET_PMC6(a) do {} while (0)
90 #endif
91 #else /* ARCH_PPC64 */
92 #define POWERP_PMC_DATATYPE unsigned long long
93 #define POWERPC_GET_PMC1(a) __asm__ volatile("mfspr %0, 771" : "=r" (a))
94 #define POWERPC_GET_PMC2(a) __asm__ volatile("mfspr %0, 772" : "=r" (a))
95 #if (POWERPC_NUM_PMC_ENABLED > 2)
96 #define POWERPC_GET_PMC3(a) __asm__ volatile("mfspr %0, 773" : "=r" (a))
97 #define POWERPC_GET_PMC4(a) __asm__ volatile("mfspr %0, 774" : "=r" (a))
98 #else
99 #define POWERPC_GET_PMC3(a) do {} while (0)
100 #define POWERPC_GET_PMC4(a) do {} while (0)
101 #endif
102 #if (POWERPC_NUM_PMC_ENABLED > 4)
103 #define POWERPC_GET_PMC5(a) __asm__ volatile("mfspr %0, 775" : "=r" (a))
104 #define POWERPC_GET_PMC6(a) __asm__ volatile("mfspr %0, 776" : "=r" (a))
105 #else
106 #define POWERPC_GET_PMC5(a) do {} while (0)
107 #define POWERPC_GET_PMC6(a) do {} while (0)
108 #endif
109 #endif /* ARCH_PPC64 */
110 #define POWERPC_PERF_DECLARE(a, cond) \
111 POWERP_PMC_DATATYPE \
112 pmc_start[POWERPC_NUM_PMC_ENABLED], \
113 pmc_stop[POWERPC_NUM_PMC_ENABLED], \
114 pmc_loop_index;
115 #define POWERPC_PERF_START_COUNT(a, cond) do { \
116 POWERPC_GET_PMC6(pmc_start[5]); \
117 POWERPC_GET_PMC5(pmc_start[4]); \
118 POWERPC_GET_PMC4(pmc_start[3]); \
119 POWERPC_GET_PMC3(pmc_start[2]); \
120 POWERPC_GET_PMC2(pmc_start[1]); \
121 POWERPC_GET_PMC1(pmc_start[0]); \
122 } while (0)
123 #define POWERPC_PERF_STOP_COUNT(a, cond) do { \
124 POWERPC_GET_PMC1(pmc_stop[0]); \
125 POWERPC_GET_PMC2(pmc_stop[1]); \
126 POWERPC_GET_PMC3(pmc_stop[2]); \
127 POWERPC_GET_PMC4(pmc_stop[3]); \
128 POWERPC_GET_PMC5(pmc_stop[4]); \
129 POWERPC_GET_PMC6(pmc_stop[5]); \
130 if (cond) { \
131 for(pmc_loop_index = 0; \
132 pmc_loop_index < POWERPC_NUM_PMC_ENABLED; \
133 pmc_loop_index++) { \
134 if (pmc_stop[pmc_loop_index] >= pmc_start[pmc_loop_index]) { \
135 POWERP_PMC_DATATYPE diff = \
136 pmc_stop[pmc_loop_index] - pmc_start[pmc_loop_index]; \
137 if (diff < perfdata[pmc_loop_index][a][powerpc_data_min]) \
138 perfdata[pmc_loop_index][a][powerpc_data_min] = diff; \
139 if (diff > perfdata[pmc_loop_index][a][powerpc_data_max]) \
140 perfdata[pmc_loop_index][a][powerpc_data_max] = diff; \
141 perfdata[pmc_loop_index][a][powerpc_data_sum] += diff; \
142 perfdata[pmc_loop_index][a][powerpc_data_num] ++; \
143 } \
144 } \
145 } \
146 } while (0)
147 #else /* CONFIG_POWERPC_PERF */
148 // those are needed to avoid empty statements.
149 #define POWERPC_PERF_DECLARE(a, cond) int altivec_placeholder __attribute__ ((unused))
150 #define POWERPC_PERF_START_COUNT(a, cond) do {} while (0)
151 #define POWERPC_PERF_STOP_COUNT(a, cond) do {} while (0)
152 #endif /* CONFIG_POWERPC_PERF */
153
154 #endif /* AVCODEC_PPC_DSPUTIL_PPC_H */