aboutsummaryrefslogtreecommitdiff
path: root/Src/Winamp/TIMING.cpp
blob: 905ce748559972de653ab46ded4d502630ac54d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/** (c) Nullsoft, Inc.         C O N F I D E N T I A L
 ** Filename: 
 ** Project:
 ** Description:
 ** Author:
 ** Created:
 **/

#include "main.h"
#include "timing.h"

#ifdef TIMING
#ifndef __alpha


static struct {
	unsigned int st_time[2];
	unsigned int cycles;
	unsigned int calls;
} timingInfo[64];

static int timingEnters;

static void rdtsc(unsigned int t[2])
{
	__asm 
	{
		mov esi, t
		_emit 0xf
		_emit 0x31
		mov [esi], eax
		mov [esi+4], edx
	}
}
	
void _timingInit()
{
	memset(timingInfo,0,sizeof(timingInfo));
}

void _timingEnter(int which)
{
//   if (!timingEnters++) __asm cli
   rdtsc(timingInfo[which].st_time);
}

void _timingLeave(int which)
{
   unsigned int t[2];
   rdtsc(t);
//   if (!--timingEnters) __asm sti
   if (t[1]==timingInfo[which].st_time[1])
   {
	   timingInfo[which].cycles += t[0]-timingInfo[which].st_time[0];
   }
   else
   {
	   timingInfo[which].cycles += t[0]+(0xffffffff-timingInfo[which].st_time[0]);
   }
   timingInfo[which].calls++;
}

void _timingPrint()
{
	int x;
	FILE *fp = fopen("C:\\timings.txt","a+t");
	for (x = 0; x < sizeof(timingInfo)/sizeof(timingInfo[0]); x ++)
	{
		if (timingInfo[x].calls)
			fprintf(fp,"%d: %d calls, %d clocks/call\n",x,timingInfo[x].calls,timingInfo[x].cycles/timingInfo[x].calls);
	}
	_timingInit();
	fclose(fp);
}

#endif
#endif