/
arm_profiler.c
100 lines (80 loc) · 2.32 KB
/
arm_profiler.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
// imports for time
#include <sys/times.h>
#include <unistd.h>
#include "define.h"
// c cordic implementations
#include "cordic_implementations/cordic.c"
// arm
#include "cordic_implementations/cordic_assembly.h"
// optimized arm
#include "cordic_implementations/cordic_assembly_optimized.h"
clock_t get_time() {
struct tms time_struct;
times(&time_struct);
return time_struct.tms_utime;
}
void check_32_bit() {
if( ! (!(0 & 0x80000000)
&& !(1 & 0x80000000)
&& !(100 & 0x80000000)
&& !!(-1 & 0x80000000)
&& !!(-100 & 0x80000000))) {
printf("Your platform doesn't support 32 bit integers. You must use a platform that supports 32 bit integers.\n");
exit(EXIT_FAILURE);
}
}
int main(void) {
clock_t before_time;
int ticks_per_second = sysconf(_SC_CLK_TCK);
int repetitions = 1000000;
volatile int i;
int values[repetitions];
int angles[repetitions];
for (i = 0; i < repetitions; i++) {
values[i] = rand() % 10000;
angles[i] = rand() % HALF_PI;
}
int x, y, z;
check_32_bit();
printf("\t\tCordic Profiler: Seng440\n\n");
// int_cordic
before_time = get_time();
for (i=0; i<repetitions; i++) {
x = values[i];
y = angles[repetitions-1-i];
z = angles[i];
cordic(&x, &y, &z, ROTATIONAL);
}
printf("\tcordic\n\ntime: %f\n\n", (double)(get_time() - before_time) / ticks_per_second);
// optimized cordic
before_time = get_time();
for (i=0; i<repetitions; i++) {
x = values[i];
y = angles[repetitions-1-i];
z = angles[i];
cordic_optimized(&x, &y, &z, ROTATIONAL);
}
printf("\toptimized cordic\n\ntime: %f\n\n", (double)(get_time() - before_time) / ticks_per_second);
// arm implementation
before_time = get_time();
for (i=0; i<repetitions; i++) {
x = values[i];
y = angles[repetitions-1-i];
z = angles[i];
cordic_assembly(&x, &y, &z, (int)ROTATIONAL);
}
printf("\tarm cordic\n\ntime: %f\n\n", (double)(get_time() - before_time) / ticks_per_second);
// optimized arm implementation
before_time = get_time();
for (i=0; i<repetitions; i++) {
x = values[i];
y = angles[repetitions-1-i];
z = angles[i];
cordic_assembly_optimized(&x, &y, &z, (int)ROTATIONAL);
}
printf("\toptimized arm cordic\n\ntime: %f\n\n", (double)(get_time() - before_time) / ticks_per_second);
return 0;
}