PPC970 patch + cpu-specific tuning support by (Romain Dolbeau <dolbeau at irisa dot...
[libav.git] / 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_clear_blocks_dcbz128,
41 powerpc_perf_total
42 };
43 enum powerpc_data_index {
44 powerpc_data_min = 0,
45 powerpc_data_max,
46 powerpc_data_sum,
47 powerpc_data_num,
48 powerpc_data_total
49 };
50 extern unsigned long long perfdata[powerpc_perf_total][powerpc_data_total];
51 #ifdef POWERPC_PERF_USE_PMC
52 extern unsigned long long perfdata_miss[powerpc_perf_total][powerpc_data_total];
53 #endif
54
55 #ifndef POWERPC_PERF_USE_PMC
56 #define POWERPC_GET_CYCLES(a) asm volatile("mftb %0" : "=r" (a))
57 #define POWERPC_TBL_DECLARE(a, cond) register unsigned long tbl_start, tbl_stop
58 #define POWERPC_TBL_START_COUNT(a, cond) do { POWERPC_GET_CYCLES(tbl_start); } while (0)
59 #define POWERPC_TBL_STOP_COUNT(a, cond) do { \
60 POWERPC_GET_CYCLES(tbl_stop); \
61 if (tbl_stop > tbl_start) \
62 { \
63 unsigned long diff = tbl_stop - tbl_start; \
64 if (cond) \
65 { \
66 if (diff < perfdata[a][powerpc_data_min]) \
67 perfdata[a][powerpc_data_min] = diff; \
68 if (diff > perfdata[a][powerpc_data_max]) \
69 perfdata[a][powerpc_data_max] = diff; \
70 perfdata[a][powerpc_data_sum] += diff; \
71 perfdata[a][powerpc_data_num] ++; \
72 } \
73 } \
74 } while (0)
75
76 #else /* POWERPC_PERF_USE_PMC */
77 #define POWERPC_GET_CYCLES(a) asm volatile("mfspr %0, 937" : "=r" (a))
78 #define POWERPC_GET_MISS(a) asm volatile("mfspr %0, 938" : "=r" (a))
79 #define POWERPC_TBL_DECLARE(a, cond) register unsigned long cycles_start, cycles_stop, miss_start, miss_stop
80 #define POWERPC_TBL_START_COUNT(a, cond) do { POWERPC_GET_MISS(miss_start); POWERPC_GET_CYCLES(cycles_start); } while (0)
81 #define POWERPC_TBL_STOP_COUNT(a, cond) do { \
82 POWERPC_GET_CYCLES(cycles_stop); \
83 POWERPC_GET_MISS(miss_stop); \
84 if (cycles_stop >= cycles_start) \
85 { \
86 unsigned long diff = \
87 cycles_stop - cycles_start; \
88 if (cond) \
89 { \
90 if (diff < perfdata[a][powerpc_data_min]) \
91 perfdata[a][powerpc_data_min] = diff; \
92 if (diff > perfdata[a][powerpc_data_max]) \
93 perfdata[a][powerpc_data_max] = diff; \
94 perfdata[a][powerpc_data_sum] += diff; \
95 perfdata[a][powerpc_data_num] ++; \
96 } \
97 } \
98 if (miss_stop >= miss_start) \
99 { \
100 unsigned long diff = \
101 miss_stop - miss_start; \
102 if (cond) \
103 { \
104 if (diff < perfdata_miss[a][powerpc_data_min]) \
105 perfdata_miss[a][powerpc_data_min] = diff; \
106 if (diff > perfdata_miss[a][powerpc_data_max]) \
107 perfdata_miss[a][powerpc_data_max] = diff; \
108 perfdata_miss[a][powerpc_data_sum] += diff; \
109 perfdata_miss[a][powerpc_data_num] ++; \
110 } \
111 } \
112 } while (0)
113
114 #endif /* POWERPC_PERF_USE_PMC */
115
116
117 #else /* POWERPC_TBL_PERFORMANCE_REPORT */
118 // those are needed to avoid empty statements.
119 #define POWERPC_TBL_DECLARE(a, cond) int altivec_placeholder __attribute__ ((unused))
120 #define POWERPC_TBL_START_COUNT(a, cond) do {} while (0)
121 #define POWERPC_TBL_STOP_COUNT(a, cond) do {} while (0)
122 #endif /* POWERPC_TBL_PERFORMANCE_REPORT */
123
124 #endif /* _DSPUTIL_PPC_ */