Skip to content

Instantly share code, notes, and snippets.

@afeinberg
Created December 20, 2011 09:12
Show Gist options
  • Save afeinberg/1500902 to your computer and use it in GitHub Desktop.
Save afeinberg/1500902 to your computer and use it in GitHub Desktop.
compile with g++ -S -O3 unroll.cc
.file "unroll.cc"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "%d\n"
.text
.p2align 4,,15
.globl _Z3bari
.type _Z3bari, @function
_Z3bari: ;; (would still get unrolled -funroll-loops)
.LFB48:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movl %edi, %ebp
pushq %rbx
.cfi_def_cfa_offset 24
.cfi_offset 3, -24
subq $8, %rsp
.cfi_def_cfa_offset 32
testl %edi, %edi
jle .L1
xorl %ebx, %ebx
.p2align 4,,10
.p2align 3
.L3:
movl %ebx, %edx
xorl %eax, %eax
movl $.LC0, %esi
movl $1, %edi
addl $1, %ebx
call __printf_chk
cmpl %ebp, %ebx
jne .L3
.L1:
addq $8, %rsp
.cfi_def_cfa_offset 24
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE48:
.size _Z3bari, .-_Z3bari
.section .text.startup,"ax",@progbits
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB49:
.cfi_startproc ;; (-O3 auto unrolls and inlines foo)
subq $8, %rsp
.cfi_def_cfa_offset 16
xorl %edx, %edx
movl $.LC0, %esi
movl $1, %edi
xorl %eax, %eax
call __printf_chk
movl $1, %edx
movl $.LC0, %esi
movl $1, %edi
xorl %eax, %eax
call __printf_chk
movl $2, %edx
movl $.LC0, %esi
movl $1, %edi
xorl %eax, %eax
call __printf_chk
movl $3, %edx
movl $.LC0, %esi
movl $1, %edi
xorl %eax, %eax
call __printf_chk
movl $4, %edx
movl $.LC0, %esi
movl $1, %edi
xorl %eax, %eax
call __printf_chk
movl $5, %edx
movl $.LC0, %esi
movl $1, %edi
xorl %eax, %eax
call __printf_chk
movl $6, %edx
movl $.LC0, %esi
movl $1, %edi
xorl %eax, %eax
call __printf_chk
movl $7, %edx
movl $.LC0, %esi
movl $1, %edi
xorl %eax, %eax
call __printf_chk
movl $8, %edi
call _Z3bari
xorl %eax, %eax
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE49:
.size main, .-main
.ident "GCC: (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1"
.section .note.GNU-stack,"",@progbits
#include <cstdio>
#include <cstdlib>
template<int N>
void foo() {
for (int i = 0; i < N; ++i) {
printf("%d\n", i);
}
}
void bar(int n) {
for (int i = 0; i < n; ++i) {
printf("%d\n", i);
}
}
int main(int argc, char **argv) {
foo<8>();
bar(8);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment