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