]> git.sesse.net Git - ffmpeg/blob - libavcodec/ppc/dsputil_ppc.h
More AltiVec MC functions patch by (Romain Dolbeau <dolbeau at irisa dot fr>)
[ffmpeg] / libavcodec / ppc / dsputil_ppc.h
1 /*
2  * Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #ifndef _DSPUTIL_PPC_
20 #define _DSPUTIL_PPC_
21
22 #ifdef POWERPC_TBL_PERFORMANCE_REPORT
23 void powerpc_display_perf_report(void);
24 /* if you add to the enum below, also add to the perfname array
25    in dsputil_ppc.c */
26 enum powerpc_perf_index {
27   altivec_fft_num = 0,
28   altivec_gmc1_num,
29   altivec_dct_unquantize_h263_num,
30   altivec_idct_add_num,
31   altivec_idct_put_num,
32   altivec_put_pixels16_num,
33   altivec_avg_pixels16_num,
34   altivec_avg_pixels8_num,
35   altivec_put_pixels8_xy2_num,
36   altivec_put_no_rnd_pixels8_xy2_num,
37   altivec_put_pixels16_xy2_num,
38   altivec_put_no_rnd_pixels16_xy2_num,
39   powerpc_clear_blocks_dcbz32,
40   powerpc_perf_total
41 };
42 enum powerpc_data_index {
43   powerpc_data_min = 0,
44   powerpc_data_max,
45   powerpc_data_sum,
46   powerpc_data_num,
47   powerpc_data_total
48 };
49 extern unsigned long long perfdata[powerpc_perf_total][powerpc_data_total];
50 #ifdef POWERPC_PERF_USE_PMC
51 extern unsigned long long perfdata_miss[powerpc_perf_total][powerpc_data_total];
52 #endif
53
54 #ifndef POWERPC_PERF_USE_PMC
55 #define POWERPC_GET_CYCLES(a) asm volatile("mftb %0" : "=r" (a))
56 #define POWERPC_TBL_DECLARE(a, cond) register unsigned long tbl_start, tbl_stop
57 #define POWERPC_TBL_START_COUNT(a, cond) do { POWERPC_GET_CYCLES(tbl_start); } while (0)
58 #define POWERPC_TBL_STOP_COUNT(a, cond) do {     \
59   POWERPC_GET_CYCLES(tbl_stop);                  \
60   if (tbl_stop > tbl_start)                      \
61   {                                              \
62     unsigned long diff =  tbl_stop - tbl_start;  \
63     if (cond)                                    \
64     {                                            \
65       if (diff < perfdata[a][powerpc_data_min])  \
66         perfdata[a][powerpc_data_min] = diff;    \
67       if (diff > perfdata[a][powerpc_data_max])  \
68         perfdata[a][powerpc_data_max] = diff;    \
69       perfdata[a][powerpc_data_sum] += diff;     \
70       perfdata[a][powerpc_data_num] ++;          \
71     }                                            \
72   }                                              \
73 } while (0)
74
75 #else /* POWERPC_PERF_USE_PMC */
76 #define POWERPC_GET_CYCLES(a) asm volatile("mfspr %0, 937" : "=r" (a))
77 #define POWERPC_GET_MISS(a) asm volatile("mfspr %0, 938" : "=r" (a))
78 #define POWERPC_TBL_DECLARE(a, cond) register unsigned long cycles_start, cycles_stop, miss_start, miss_stop;
79 #define POWERPC_TBL_START_COUNT(a, cond) do { POWERPC_GET_MISS(miss_start); POWERPC_GET_CYCLES(cycles_start); } while (0)
80 #define POWERPC_TBL_STOP_COUNT(a, cond) do {     \
81   POWERPC_GET_CYCLES(cycles_stop);               \
82   POWERPC_GET_MISS(miss_stop);                   \
83   if (cycles_stop >= cycles_start)               \
84   {                                              \
85     unsigned long diff =                         \
86                 cycles_stop - cycles_start;      \
87     if (cond)                                    \
88     {                                            \
89       if (diff < perfdata[a][powerpc_data_min])  \
90         perfdata[a][powerpc_data_min] = diff;    \
91       if (diff > perfdata[a][powerpc_data_max])  \
92         perfdata[a][powerpc_data_max] = diff;    \
93       perfdata[a][powerpc_data_sum] += diff;     \
94       perfdata[a][powerpc_data_num] ++;          \
95     }                                            \
96   }                                              \
97   if (miss_stop >= miss_start)                   \
98   {                                              \
99     unsigned long diff =                         \
100                 miss_stop - miss_start;          \
101     if (cond)                                    \
102     {                                            \
103       if (diff < perfdata_miss[a][powerpc_data_min]) \
104         perfdata_miss[a][powerpc_data_min] = diff;   \
105       if (diff > perfdata_miss[a][powerpc_data_max]) \
106         perfdata_miss[a][powerpc_data_max] = diff;   \
107       perfdata_miss[a][powerpc_data_sum] += diff;    \
108       perfdata_miss[a][powerpc_data_num] ++;         \
109     }                                            \
110   }                                              \
111 } while (0)
112
113 #endif /* POWERPC_PERF_USE_PMC */
114
115
116 #else /* POWERPC_TBL_PERFORMANCE_REPORT */
117 #define POWERPC_TBL_DECLARE(a, cond)
118 #define POWERPC_TBL_START_COUNT(a, cond)
119 #define POWERPC_TBL_STOP_COUNT(a, cond)
120 #endif /* POWERPC_TBL_PERFORMANCE_REPORT */
121
122 #endif /*  _DSPUTIL_PPC_ */