diff --git a/lab/prof/Makefile b/lab/prof/Makefile index 1c6da0f..b1d3283 100644 --- a/lab/prof/Makefile +++ b/lab/prof/Makefile @@ -1,6 +1,4 @@ -main: main.c - gcc -m64 -O3 -Wall main.c -o main +main: main.c int.s + gcc -Wall main.c int.s -o main -main.s: main.c - gcc -m64 -O3 -Wall -fomit-frame-pointer -fno-PIC -S main.c diff --git a/lab/prof/int.s b/lab/prof/int.s new file mode 100644 index 0000000..66240f1 --- /dev/null +++ b/lab/prof/int.s @@ -0,0 +1,34 @@ + +.globl _interrupt_mem +_interrupt_mem: + movl 4(%esp), %eax +L_loop1: + subl $1, 0(%eax); + jz L_int1 + jmp L_loop1 +L_int1: + ret + +.globl _interrupt_reg +_interrupt_reg: + movl 4(%esp), %eax +L_loop2: + subl $1, %eax; + jz L_int2 + subl $1, %eax; + jz L_int2 + subl $1, %eax; + jz L_int2 + subl $1, %eax; + jz L_int2 + subl $1, %eax; + jz L_int2 + subl $1, %eax; + jz L_int2 + subl $1, %eax; + jz L_int2 + jmp L_loop2 +L_int2: + ret + + diff --git a/lab/prof/main b/lab/prof/main index 5c6055e..e4a9855 100755 Binary files a/lab/prof/main and b/lab/prof/main differ diff --git a/lab/prof/main.c b/lab/prof/main.c index c052de3..6332f80 100644 --- a/lab/prof/main.c +++ b/lab/prof/main.c @@ -1,14 +1,31 @@ + #include - -long long foo(long long int x){ - return x+1; -} - #include -int main(int argc, char** argv){ - fprintf(stderr, "sizeof(long long int)=%ld\n", - sizeof(long long int)); - long long int x = 57; - x = foo(x); +#include + +typedef struct pcb{ + int counter; +} pcb; + +extern void interrupt_mem(pcb*); +extern void interrupt_reg(int); + +void usage(char* name){ + fprintf(stderr, "Usage: %s [mem|reg]\n", name); exit(-1); } + +int main(int argc, char** argv){ + int most_positive_number = 0x7FFFFFFF; + if(argc != 2) usage(argv[0]); + if(strcmp(argv[1], "reg") == 0){ + interrupt_reg(most_positive_number); + } else if(strcmp(argv[1], "mem") == 0){ + pcb x; + x.counter = most_positive_number; + interrupt_mem(&x); + } else { + usage(argv[0]); + } + return 0; +} diff --git a/lab/prof/main.s b/lab/prof/main.s deleted file mode 100644 index abed3c4..0000000 --- a/lab/prof/main.s +++ /dev/null @@ -1,77 +0,0 @@ - .text -.globl _foo -_foo: -LFB3: - leaq 1(%rdi), %rax - ret -LFE3: - .cstring -LC0: - .ascii "sizeof(long long int)=%ld\12\0" - .text -.globl _main -_main: -LFB20: - subq $8, %rsp -LCFI0: - movl $8, %edx - leaq LC0(%rip), %rsi - movq ___stderrp@GOTPCREL(%rip), %rax - movq (%rax), %rdi - xorl %eax, %eax - call _fprintf - movl $-1, %edi - call _exit -LFE20: - .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support -EH_frame1: - .set L$set$0,LECIE1-LSCIE1 - .long L$set$0 -LSCIE1: - .long 0x0 - .byte 0x1 - .ascii "zR\0" - .byte 0x1 - .byte 0x78 - .byte 0x10 - .byte 0x1 - .byte 0x10 - .byte 0xc - .byte 0x7 - .byte 0x8 - .byte 0x90 - .byte 0x1 - .align 3 -LECIE1: - .globl _foo.eh -_foo.eh: -LSFDE1: - .set L$set$1,LEFDE1-LASFDE1 - .long L$set$1 -LASFDE1: - .long LASFDE1-EH_frame1 - .quad LFB3-. - .set L$set$2,LFE3-LFB3 - .quad L$set$2 - .byte 0x0 - .align 3 -LEFDE1: - .globl _main.eh -_main.eh: -LSFDE3: - .set L$set$3,LEFDE3-LASFDE3 - .long L$set$3 -LASFDE3: - .long LASFDE3-EH_frame1 - .quad LFB20-. - .set L$set$4,LFE20-LFB20 - .quad L$set$4 - .byte 0x0 - .byte 0x4 - .set L$set$5,LCFI0-LFB20 - .long L$set$5 - .byte 0xe - .byte 0x10 - .align 3 -LEFDE3: - .subsections_via_symbols diff --git a/lab/prof/plot.gcx b/lab/prof/plot.gcx new file mode 100644 index 0000000..894c3c4 Binary files /dev/null and b/lab/prof/plot.gcx differ diff --git a/lab/prof/times.txt b/lab/prof/times.txt new file mode 100644 index 0000000..a06df50 --- /dev/null +++ b/lab/prof/times.txt @@ -0,0 +1,9 @@ +1 2.157 +2 1.618 +3 1.440 +4 1.350 +5 1.296 +6 1.260 +7 1.232 + +