Last active
October 13, 2020 15:33
-
-
Save Loki-Astari/02c569f75809824f5260af7ba1551fc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>diff Loop.s Recu.s | |
3c3 | |
< .globl __Z4fibLi ## -- Begin function _Z4fibLi | |
--- | |
> .globl __Z4fibRi ## -- Begin function _Z4fibRi | |
5c5 | |
< __Z4fibLi: ## @_Z4fibLi | |
--- | |
> __Z4fibRi: ## @_Z4fibRi | |
15c15 | |
< jl LBB0_3 | |
--- | |
> jl LBB1_3 | |
21c21 | |
< LBB0_2: ## =>This Inner Loop Header: Depth=1 | |
--- | |
> LBB1_2: ## =>This Inner Loop Header: Depth=1 | |
28,29c28,29 | |
< jg LBB0_2 | |
< LBB0_3: | |
--- | |
> jg LBB1_2 | |
> LBB1_3: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#ifdef LOOP | |
int fibL(int n) | |
{ | |
int a = 1; // f(0) => 1 | |
int b = 1; // f(1) => 1 | |
for(; n >= 2 ; --n) { | |
int c = a + b; | |
a = b; | |
b = c; | |
} | |
return b; | |
} | |
#endif | |
#ifdef RECU | |
int fibR(int a, int b, int n) | |
{ | |
if (n < 2) { | |
return b; | |
} | |
return fibR(b, a+b, n - 1); | |
} | |
int fibR(int n) | |
{ | |
return fibR(1, 1, n); | |
} | |
#endif | |
#ifdef APP | |
int main() | |
{ | |
std::cout << fibR(1) << " " << fibL(1) << "\n"; | |
std::cout << fibR(5) << " " << fibL(5) << "\n"; | |
std::cout << fibR(8) << " " << fibL(8) << "\n"; | |
std::cout << fibR(13) << " " << fibL(13) << "\n"; | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note I removed the header | |
.globl __Z4fibLi ## -- Begin function _Z4fibLi | |
.p2align 4, 0x90 | |
__Z4fibLi: ## @_Z4fibLi | |
.cfi_startproc | |
## %bb.0: | |
pushq %rbp | |
.cfi_def_cfa_offset 16 | |
.cfi_offset %rbp, -16 | |
movq %rsp, %rbp | |
.cfi_def_cfa_register %rbp | |
movl $1, %eax | |
cmpl $2, %edi | |
jl LBB0_3 | |
## %bb.1: | |
incl %edi | |
movl $1, %eax | |
movl $1, %ecx | |
.p2align 4, 0x90 | |
LBB0_2: ## =>This Inner Loop Header: Depth=1 | |
movl %eax, %edx | |
movl %ecx, %eax | |
addl %edx, %eax | |
decl %edi | |
movl %edx, %ecx | |
cmpl $2, %edi | |
jg LBB0_2 | |
LBB0_3: | |
popq %rbp | |
retq | |
.cfi_endproc | |
## -- End function | |
.subsections_via_symbols |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note I removed the header | |
// and the definition of fibR(int,int,int) as it is inlined below. | |
// | |
.globl __Z4fibRi ## -- Begin function _Z4fibRi | |
.p2align 4, 0x90 | |
__Z4fibRi: ## @_Z4fibRi | |
.cfi_startproc | |
## %bb.0: | |
pushq %rbp | |
.cfi_def_cfa_offset 16 | |
.cfi_offset %rbp, -16 | |
movq %rsp, %rbp | |
.cfi_def_cfa_register %rbp | |
movl $1, %eax | |
cmpl $2, %edi | |
jl LBB1_3 | |
## %bb.1: | |
incl %edi | |
movl $1, %eax | |
movl $1, %ecx | |
.p2align 4, 0x90 | |
LBB1_2: ## =>This Inner Loop Header: Depth=1 | |
movl %eax, %edx | |
movl %ecx, %eax | |
addl %edx, %eax | |
decl %edi | |
movl %edx, %ecx | |
cmpl $2, %edi | |
jg LBB1_2 | |
LBB1_3: | |
popq %rbp | |
retq | |
.cfi_endproc | |
## -- End function | |
.subsections_via_symbols |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment