Mercurial > mplayer.hg
comparison TOOLS/fastmemcpybench.c @ 28868:a10ddae3de31
whitespace cosmetics:
- Remove all tabs and trailing whitespace.
- Indent with 4 spaces.
- K&R-ify and prettyprint some parts.
author | diego |
---|---|
date | Mon, 09 Mar 2009 11:28:31 +0000 |
parents | 07c168210a73 |
children | 04a232eb5f0d |
comparison
equal
deleted
inserted
replaced
28867:c7ac52e4b228 | 28868:a10ddae3de31 |
---|---|
1 /* | 1 /* |
2 fastmemcpybench.c used to benchmark fastmemcpy.h code from libvo. | 2 fastmemcpybench.c used to benchmark fastmemcpy.h code from libvo. |
3 | 3 |
4 Note: this code can not be used on PentMMX-PII because they contain | 4 Note: this code can not be used on PentMMX-PII because they contain |
5 a bug in rdtsc. For Intel processors since P6(PII) rdpmc should be used | 5 a bug in rdtsc. For Intel processors since P6(PII) rdpmc should be used |
6 instead. For PIII it's disputable and seems bug was fixed but I don't | 6 instead. For PIII it's disputable and seems bug was fixed but I don't |
7 tested it. | 7 tested it. |
8 */ | 8 */ |
25 #ifdef CONFIG_MGA | 25 #ifdef CONFIG_MGA |
26 | 26 |
27 #include "drivers/mga_vid.h" | 27 #include "drivers/mga_vid.h" |
28 | 28 |
29 static mga_vid_config_t mga_vid_config; | 29 static mga_vid_config_t mga_vid_config; |
30 static unsigned char* frame=NULL; | 30 static unsigned char* frame = NULL; |
31 static int f; | 31 static int f; |
32 | 32 |
33 static int mga_init(void) | 33 static int mga_init(void) |
34 { | 34 { |
35 f = open("/dev/mga_vid",O_RDWR); | 35 f = open("/dev/mga_vid", O_RDWR); |
36 if(f == -1) | 36 if (f == -1) { |
37 { | 37 fprintf(stderr, "Couldn't open /dev/mga_vid\n"); |
38 fprintf(stderr,"Couldn't open /dev/mga_vid\n"); | 38 return -1; |
39 return -1; | 39 } |
40 } | |
41 | 40 |
42 mga_vid_config.num_frames=1; | 41 mga_vid_config.num_frames = 1; |
43 mga_vid_config.frame_size=ARR_SIZE; | 42 mga_vid_config.frame_size = ARR_SIZE; |
44 mga_vid_config.format=MGA_VID_FORMAT_YUY2; | 43 mga_vid_config.format = MGA_VID_FORMAT_YUY2; |
45 | 44 |
46 mga_vid_config.colkey_on=0; | 45 mga_vid_config.colkey_on = 0; |
47 mga_vid_config.src_width = 640; | 46 mga_vid_config.src_width = 640; |
48 mga_vid_config.src_height= 480; | 47 mga_vid_config.src_height = 480; |
49 mga_vid_config.dest_width = 320; | 48 mga_vid_config.dest_width = 320; |
50 mga_vid_config.dest_height= 200; | 49 mga_vid_config.dest_height = 200; |
51 mga_vid_config.x_org= 0; | 50 mga_vid_config.x_org = 0; |
52 mga_vid_config.y_org= 0; | 51 mga_vid_config.y_org = 0; |
53 | |
54 mga_vid_config.version=MGA_VID_VERSION; | |
55 if (ioctl(f,MGA_VID_CONFIG,&mga_vid_config)) | |
56 { | |
57 perror("Error in mga_vid_config ioctl()"); | |
58 printf("Your mga_vid driver version is incompatible with this MPlayer version!\n"); | |
59 exit(1); | |
60 } | |
61 ioctl(f,MGA_VID_ON,0); | |
62 | 52 |
63 frame = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,f,0); | 53 mga_vid_config.version = MGA_VID_VERSION; |
64 if(!frame){ | 54 if (ioctl(f, MGA_VID_CONFIG, &mga_vid_config)) { |
65 printf("Can't mmap mga frame\n"); | 55 perror("Error in mga_vid_config ioctl()"); |
66 exit(1); | 56 printf("Your mga_vid driver version is incompatible with this MPlayer version!\n"); |
67 } | 57 exit(1); |
58 } | |
59 ioctl(f, MGA_VID_ON, 0); | |
68 | 60 |
69 //clear the buffer | 61 frame = (char*)mmap(0, mga_vid_config.frame_size*mga_vid_config.num_frames, |
70 //memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | 62 PROT_WRITE,MAP_SHARED, f, 0); |
63 if (!frame) { | |
64 printf("Can't mmap mga frame\n"); | |
65 exit(1); | |
66 } | |
71 | 67 |
72 return 0; | 68 //clear the buffer |
69 //memset(frames[0], 0x80, mga_vid_config.frame_size*mga_vid_config.num_frames); | |
73 | 70 |
71 return 0; | |
74 } | 72 } |
75 | 73 |
76 #endif | 74 #endif |
77 | 75 |
78 // Returns current time in microseconds | 76 // Returns current time in microseconds |
79 static unsigned int GetTimer(void) | 77 static unsigned int GetTimer(void) |
80 { | 78 { |
81 struct timeval tv; | 79 struct timeval tv; |
82 struct timezone tz; | 80 struct timezone tz; |
83 // float s; | 81 //float s; |
84 gettimeofday(&tv,&tz); | 82 gettimeofday(&tv, &tz); |
85 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec; | 83 //s = tv.tv_usec; s *= 0.000001; s += tv.tv_sec; |
86 return tv.tv_sec * 1000000 + tv.tv_usec; | 84 return tv.tv_sec * 1000000 + tv.tv_usec; |
87 } | |
88 | |
89 static inline unsigned long long int read_tsc( void ) | |
90 { | |
91 unsigned long long int retval; | |
92 __asm__ volatile ("rdtsc":"=A"(retval)::"memory"); | |
93 return retval; | |
94 } | 85 } |
95 | 86 |
96 unsigned char __attribute__((aligned(4096)))arr1[ARR_SIZE],arr2[ARR_SIZE]; | 87 static inline unsigned long long int read_tsc(void) |
88 { | |
89 unsigned long long int retval; | |
90 __asm__ volatile ("rdtsc":"=A" (retval)::"memory"); | |
91 return retval; | |
92 } | |
97 | 93 |
98 int main( void ) | 94 unsigned char __attribute__((aligned(4096)))arr1[ARR_SIZE], arr2[ARR_SIZE]; |
95 | |
96 int main(void) | |
99 { | 97 { |
100 unsigned long long int v1,v2; | 98 unsigned long long int v1, v2; |
101 unsigned char * marr1,*marr2; | 99 unsigned char *marr1, *marr2; |
102 int i; | 100 int i; |
103 unsigned int t; | 101 unsigned int t; |
104 #ifdef CONFIG_MGA | 102 #ifdef CONFIG_MGA |
105 mga_init(); | 103 mga_init(); |
106 marr1 = &frame[3]; | 104 marr1 = &frame[3]; |
107 #else | 105 #else |
108 marr1 = &arr1[0]; | 106 marr1 = &arr1[0]; |
109 #endif | 107 #endif |
110 marr2 = &arr2[0]; | 108 marr2 = &arr2[0]; |
111 | 109 |
112 for(i=0; i<ARR_SIZE-16; i++) marr1[i] = marr2[i] = i; | 110 for (i = 0; i < ARR_SIZE - 16; i++) |
111 marr1[i] = marr2[i] = i; | |
113 | 112 |
114 t=GetTimer(); | 113 t = GetTimer(); |
115 v1 = read_tsc(); | 114 v1 = read_tsc(); |
116 for(i=0;i<100;i++) memcpy(marr1,marr2,ARR_SIZE-16); | 115 for (i = 0; i < 100; i++) |
117 v2 = read_tsc(); | 116 memcpy(marr1, marr2, ARR_SIZE - 16); |
118 t=GetTimer()-t; | 117 v2 = read_tsc(); |
119 // ARR_SIZE*100/(1024*1024)/(t/1000000) = ARR_SIZE*95.36743/t | 118 t = GetTimer() - t; |
120 printf(NAME": cpu clocks=%llu = %dus (%5.3ffps) %5.1fMB/s\n",v2-v1,t,100000000.0f/(float)t,(float)ARR_SIZE*95.36743f/(float)t); | 119 // ARR_SIZE*100 / (1024*1024) / (t/1000000) = ARR_SIZE*95.36743 / t |
121 return 0; | 120 printf(NAME ": cpu clocks=%llu = %dus (%5.3ffps) %5.1fMB/s\n", v2-v1, t, |
121 100000000.0f/(float)t, (float)ARR_SIZE*95.36743f/(float)t); | |
122 return 0; | |
122 } | 123 } |