-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmul_div.c
76 lines (61 loc) · 1.38 KB
/
mul_div.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
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#define LOGIN "original"
long long count;
int loop;
#define LOOP_SEC (2)
static __inline int mul(int x,int y) {
//
// 以下を削除してここに乗算のロジックを入れてください。x=32bit , y=32bit, result=64bit
//
return x*y;
}
static __inline int div(int x,int y) {
//
// 以下を削除してここに除算のロジックを入れてください。x=32bit , y=32bit, result=32bit
//
return x/y;
}
void alarm_mul(int signum){
printf("MUL: %lld K instructions/sec\n", count/LOOP_SEC/1000);
loop = 0;
}
void alarm_div(int signum){
printf("DIV: %lld K instructions/sec\n", count/LOOP_SEC/1000);
loop = 0;
}
int main() {
int x,y;
printf("Start (%s program)\n", LOGIN);
// Benchmark MUL
count = 0;
loop = 1;
signal(SIGALRM, alarm_mul);
alarm(LOOP_SEC);
for (x=1; loop ; ++x) {
for (y=1; y<0xffff; ++y) {
if (mul(x,y) != x*y) {
printf("MUL: Calculation results are incorrect. results=%d, expected=%d\n", mul(x,y), x*y);
return(-1);
}
++count;
}
}
// Benchmark DIV
count = 0;
loop = 1;
signal(SIGALRM, alarm_div);
alarm(LOOP_SEC);
for (x=0x0fffffff; loop ; --x) {
for (y=1; y<0xffff; ++y) {
if (div(x,y) != x/y) {
printf("DIV: Calculation results are incorrect. results=%d, expected=%d\n", div(x,y), x/y);
return(-1);
}
++count;
}
}
return 0;
}