platform ps2, handle audio similar to psp
[picodrive.git] / platform / linux / pprof.h
1 #ifndef __PPROF_H__
2 #define __PPROF_H__
3
4 enum pprof_points {
5   pp_main,
6   pp_frame,
7   pp_draw,
8   pp_sound,
9   pp_m68k,
10   pp_s68k,
11   pp_mem68,
12   pp_z80,
13   pp_msh2,
14   pp_ssh2,
15   pp_memsh,
16   pp_dummy,
17   pp_total_points
18 };
19
20 extern struct pp_counters *pp_counters;
21 extern int *refcounts;
22
23 #ifdef __i386__
24 typedef unsigned long long pp_type;
25
26 static __attribute__((always_inline)) inline unsigned int pprof_get_one(void)
27 {
28   unsigned long long ret;
29   __asm__ __volatile__ ("rdtsc" : "=A" (ret));
30   return (unsigned int)ret;
31 }
32 #define unglitch_timer(x)
33
34 #elif defined(__GP2X__)
35 typedef unsigned long pp_type;
36
37 #if 0
38 // XXX: MMSP2 only, timer sometimes seems to return lower vals?
39 extern volatile unsigned long *gp2x_memregl;
40 #define pprof_get_one() (unsigned int)gp2x_memregl[0x0a00 >> 2]
41 #define unglitch_timer(di) \
42   if ((signed int)(di) < 0) di = 0
43 #else
44 extern unsigned int (*gp2x_get_ticks_us)(void);
45 #define pprof_get_one() gp2x_get_ticks_us()
46 #define unglitch_timer(di) \
47   if ((signed int)(di) < 0) di = 0
48 #endif
49
50 #else
51 #error no timer
52 #endif
53
54 struct pp_counters
55 {
56         pp_type counter[pp_total_points];
57 };
58
59 #define pprof_start(point) { \
60     unsigned int pp_start_##point = pprof_get_one(); refcounts[pp_##point]++
61
62 #define pprof_end(point) \
63     { \
64       unsigned int di = pprof_get_one() - pp_start_##point; \
65       unglitch_timer(di); \
66       if (!--refcounts[pp_##point]) pp_counters->counter[pp_##point] += di; \
67     } \
68   }
69
70 // subtract for recursive stuff
71 #define pprof_end_sub(point) \
72     { \
73       unsigned int di = pprof_get_one() - pp_start_##point; \
74       unglitch_timer(di); \
75       if (--refcounts[pp_##point]) pp_counters->counter[pp_##point] -= di; \
76     } \
77   }
78
79 extern void pprof_init(void);
80 extern void pprof_finish(void);
81
82 #endif // __PPROF_H__