Last active
August 29, 2015 13:57
-
-
Save onqtam/9391671 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
================================== | |
CODE: | |
================================== | |
static int heavy(unsigned int a) { | |
int accum = 0; | |
for(unsigned int i = 0; i < a + 10; i++) | |
accum += i * i + i * 4 - i / 2; | |
return accum; | |
} | |
int optimized(unsigned int a) { | |
if(a > 3) return 3; | |
return heavy(a); | |
} | |
int main(int argc, char** argv) { | |
return optimized(argc); | |
} | |
================================== | |
AND ASSEMBLY: | |
================================== | |
.file "a.cpp" | |
.text | |
.p2align 4,,15 | |
.globl _Z9optimizedj | |
.def _Z9optimizedj; .scl 2; .type 32; .endef | |
.seh_proc _Z9optimizedj | |
_Z9optimizedj: | |
.LFB1: | |
.seh_endprologue | |
movl $3, %eax | |
cmpl $3, %ecx | |
jbe .L9 | |
rep ret | |
.p2align 4,,10 | |
.L9: | |
addl $10, %ecx | |
cmpl $10, %ecx | |
jbe .L5 | |
cmpl $11, %ecx | |
.p2align 4,,2 | |
jbe .L6 | |
cmpl $13, %ecx | |
sbbl %eax, %eax | |
andb $70, %al | |
addl $926, %eax | |
ret | |
.p2align 4,,10 | |
.L5: | |
movl $445, %eax | |
ret | |
.p2align 4,,10 | |
.L6: | |
movl $580, %eax | |
ret | |
.seh_endproc | |
.def __main; .scl 2; .type 32; .endef | |
.section .text.startup,"x" | |
.p2align 4,,15 | |
.globl main | |
.def main; .scl 2; .type 32; .endef | |
.seh_proc main | |
main: | |
.LFB2: | |
pushq %rbx | |
.seh_pushreg %rbx | |
subq $32, %rsp | |
.seh_stackalloc 32 | |
.seh_endprologue | |
movl %ecx, %ebx | |
call __main | |
cmpl $3, %ebx | |
movl $3, %eax | |
jbe .L17 | |
.L11: | |
addq $32, %rsp | |
popq %rbx | |
ret | |
.L17: | |
addl $10, %ebx | |
cmpl $10, %ebx | |
jbe .L14 | |
cmpl $11, %ebx | |
jbe .L15 | |
cmpl $13, %ebx | |
sbbl %eax, %eax | |
andb $70, %al | |
addl $926, %eax | |
jmp .L11 | |
.L14: | |
movl $445, %eax | |
jmp .L11 | |
.L15: | |
movl $580, %eax | |
jmp .L11 | |
.seh_endproc | |
.ident "GCC: (rev5, Built by MinGW-W64 project) 4.8.1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment