Dateianhang 'memspeed.c'
Herunterladen 1 /*
2 gcc -O2 memspeed.c -o memspeed
3 */
4
5 #include <stdlib.h>
6 #include <stdio.h>
7
8 #define SIZEMB (32)
9 #define SIZE (1024*1024*SIZEMB)
10 #define ITER (20)
11 #define ITER2 (10)
12
13 double this_gettime(void)
14 {
15 struct timeval tv;
16 double time;
17
18 gettimeofday(&tv, 0);
19 time = tv.tv_sec;
20 time += ((double)tv.tv_usec)/1000000.0;
21
22 return time;
23 }
24
25
26 inline void prefetch(void *x)
27 {
28 asm volatile("prefetcht0 %0\n\t"
29 :: "m" (*(unsigned long *)x));
30 }
31
32
33 int main(int argc, char *argv[])
34 {
35 int iter, i, j;
36 void *aptr;
37
38 float *a, *b;
39 volatile float read;
40
41 double *da, *db;
42 double t1, t2, t3, t4;
43 volatile double dread;
44
45 double time1, time2;
46
47 aptr = malloc(SIZE*sizeof(float) + 64);
48 a = (float *) ((long int)(aptr+((long int)63))& ((long int)~0x3f));
49
50 aptr = malloc(SIZE*sizeof(double) + 64);
51 da = (double *) ((long int)(aptr+((long int)63))& ((long int)~0x3f));
52
53 printf("readbuffer alignment: %d %d\n", ((long int)a)&0x3f, ((long int)da)&0x3f);
54
55 for(j = 0; j < SIZE; j++)
56 {
57 a[j] = 0.0;
58 da[j] = 0.0;
59 }
60
61
62 for(iter = 0; iter < ITER; iter++)
63 {
64 time1 = this_gettime();
65 for(j = 0; j < (SIZE/16); j++)
66 {
67 prefetch(a+128);
68 read = a[0];
69 read = a[1];
70 read = a[2];
71 read = a[3];
72 read = a[4];
73 read = a[5];
74 read = a[6];
75 read = a[7];
76 read = a[8];
77 read = a[9];
78 read = a[10];
79 read = a[11];
80 read = a[12];
81 read = a[13];
82 read = a[14];
83 read = a[15];
84 a += 16;
85 }
86 time2 = this_gettime();
87 printf("c int: %f mb/s\n", ((double)(SIZEMB*4))/(time2-time1));
88 a -= SIZE;
89 }
90
91
92
93 for(iter = 0; iter < ITER; iter++)
94 {
95 time1 = this_gettime();
96 for(i = 0; i < ITER2; i++)
97 {
98 for(j = 0; j < (SIZE/64); j++)
99 {
100
101 asm volatile(
102 "prefetcht0 0x800(%0) \n\t"
103 "movaps 0x00(%0), %%xmm0 ;\n\t"
104 "movaps 0x10(%0), %%xmm1 ;\n\t"
105 "movaps 0x20(%0), %%xmm2 ;\n\t"
106 "movaps 0x30(%0), %%xmm3 ;\n\t"
107 "prefetcht0 0x840(%0) \n\t"
108 "movaps 0x40(%0), %%xmm4 ;\n\t"
109 "movaps 0x50(%0), %%xmm5 ;\n\t"
110 "movaps 0x60(%0), %%xmm6 ;\n\t"
111 "movaps 0x70(%0), %%xmm7 ;\n\t"
112 "prefetcht0 0x880(%0) \n\t"
113 "movaps 0x80(%0), %%xmm8 ;\n\t"
114 "movaps 0x90(%0), %%xmm9 ;\n\t"
115 "movaps 0xa0(%0), %%xmm10 ;\n\t"
116 "movaps 0xb0(%0), %%xmm11 ;\n\t"
117 "prefetcht0 0x8c0(%0) \n\t"
118 "movaps 0xc0(%0), %%xmm12 ;\n\t"
119 "movaps 0xd0(%0), %%xmm13 ;\n\t"
120 "movaps 0xe0(%0), %%xmm14 ;\n\t"
121 "movaps 0xf0(%0), %%xmm15 ;\n\t"
122 "prefetcht0 0x900(%0) \n\t"
123 "movaps 0x100(%0), %%xmm0 ;\n\t"
124 "movaps 0x110(%0), %%xmm1 ;\n\t"
125 "movaps 0x120(%0), %%xmm2 ;\n\t"
126 "movaps 0x130(%0), %%xmm3 ;\n\t"
127 "prefetcht0 0x940(%0) \n\t"
128 "movaps 0x140(%0), %%xmm4 ;\n\t"
129 "movaps 0x150(%0), %%xmm5 ;\n\t"
130 "movaps 0x160(%0), %%xmm6 ;\n\t"
131 "movaps 0x170(%0), %%xmm7 ;\n\t"
132 "prefetcht0 0x980(%0) \n\t"
133 "movaps 0x180(%0), %%xmm8 ;\n\t"
134 "movaps 0x190(%0), %%xmm9 ;\n\t"
135 "movaps 0x1a0(%0), %%xmm10 ;\n\t"
136 "movaps 0x1b0(%0), %%xmm11 ;\n\t"
137 "prefetcht0 0x9c0(%0) \n\t"
138 "movaps 0x1c0(%0), %%xmm12 ;\n\t"
139 "movaps 0x1d0(%0), %%xmm13 ;\n\t"
140 "movaps 0x1e0(%0), %%xmm14 ;\n\t"
141 "movaps 0x1f0(%0), %%xmm15 ;\n\t"
142 : : "r" ((unsigned long *)da));
143
144 da += 64;
145
146 }
147 da -= SIZE;
148 }
149
150 time2 = this_gettime();
151 printf("asm xmms: %f mb/s\n", ((double)(SIZEMB*8*ITER2))/(time2-time1));
152 }
153
154 /* printf("xmms: %f mb/s\n", ((double)(SIZEMB*8*ITER))/(time2-time1)); */
155 }
Gespeicherte Dateianhänge
Um Dateianhänge in eine Seite einzufügen sollte unbedingt eine Angabe wie attachment:dateiname benutzt werden, wie sie auch in der folgenden Liste der Dateien erscheint. Es sollte niemals die URL des Verweises ("laden") kopiert werden, da sich diese jederzeit ändern kann und damit der Verweis auf die Datei brechen würde.Sie dürfen keine Anhänge an diese Seite anhängen!