-
Notifications
You must be signed in to change notification settings - Fork 2
/
time_mov.c
47 lines (42 loc) · 962 Bytes
/
time_mov.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
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "tdiff.h"
void time_movb() {
__asm__(
".rept 1000\n\t"
"movb $'0', %%cl\n\t"
/*"xorl %%ecx, %%ecx\n\t"*/
"addl %%ecx, %%eax\n\t"
".endr\n\t"
:::"cl", "rax"
);
}
void time_movl() {
__asm__(
".rept 1000\n\t"
"movl $'0', %%ecx\n\t"
/*"xorl %%ecx, %%ecx\n\t"*/
"addl %%ecx, %%eax\n\t"
".endr\n\t"
:::"ecx", "eax"
);
}
int main(void) {
struct timespec clock1, clock2;
unsigned int count;
puts("time_movb:");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 1000000; ++count)
time_movb();
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("time_movl:");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 1000000; ++count)
time_movl();
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
return EXIT_SUCCESS;
}