forked from sysprog21/prefetcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
69 lines (56 loc) · 1.61 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
#include <assert.h>
#include <xmmintrin.h>
#define TEST_W 4096
#define TEST_H 4096
/* provide the implementations of naive_transpose,
* sse_transpose, sse_prefetch_transpose
*/
#include "impl.c"
void (*transpose)(int *src, int *dst, int w, int h);
static long diff_in_us(struct timespec t1, struct timespec t2)
{
struct timespec diff;
if (t2.tv_nsec-t1.tv_nsec < 0) {
diff.tv_sec = t2.tv_sec - t1.tv_sec - 1;
diff.tv_nsec = t2.tv_nsec - t1.tv_nsec + 1000000000;
} else {
diff.tv_sec = t2.tv_sec - t1.tv_sec;
diff.tv_nsec = t2.tv_nsec - t1.tv_nsec;
}
return (diff.tv_sec * 1000000.0 + diff.tv_nsec / 1000.0);
}
int main()
{
#ifdef NAIVE
transpose=&naive_transpose;
#endif
#ifdef SSE
transpose=&sse_transpose;
#endif
#ifdef SSE_PREFETCH
transpose=&sse_prefetch_transpose;
#endif
struct timespec start, end;
int *src = (int *) malloc(sizeof(int) * TEST_W * TEST_H);
int *out0 = (int *) malloc(sizeof(int) * TEST_W * TEST_H);
int *out1 = (int *) malloc(sizeof(int) * TEST_W * TEST_H);
int *out2 = (int *) malloc(sizeof(int) * TEST_W * TEST_H);
srand(time(NULL));
for (int y = 0; y < TEST_H; y++)
for (int x = 0; x < TEST_W; x++)
*(src + y * TEST_W + x) = rand();
clock_gettime(CLOCK_REALTIME, &start);
transpose(src, out0, TEST_W, TEST_H);
clock_gettime(CLOCK_REALTIME, &end);
printf("time: \t %ld us\n", diff_in_us(start, end));
free(src);
free(out0);
free(out1);
free(out2);
return 0;
}