Skip to content

Instantly share code, notes, and snippets.

@kitsuyui
Last active August 29, 2015 14:14
Show Gist options
  • Save kitsuyui/67be108ecc24d5b33da2 to your computer and use it in GitHub Desktop.
Save kitsuyui/67be108ecc24d5b33da2 to your computer and use it in GitHub Desktop.
基本の話: 「変数や関数を節約すればパフォーマンスが上がる」わけではない ref: http://qiita.com/kitsuyui/items/1275ba79c423f2d85530
#include <stdio.h>
int main(void)
{
printf("%d\n", 24);
return 0;
}
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
_main: ## @main
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp2:
.cfi_def_cfa_offset 16
Ltmp3:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp4:
.cfi_def_cfa_register %rbp
subq $16, %rsp
leaq L_.str(%rip), %rdi
movl $24, %esi
movl $0, -4(%rbp)
movb $0, %al
callq _printf
movl $0, %esi
movl %eax, -8(%rbp) ## 4-byte Spill
movl %esi, %eax
addq $16, %rsp
popq %rbp
retq
.cfi_endproc
.section __TEXT,__cstring,cstring_literals
L_.str: ## @.str
.asciz "%d\n"
.subsections_via_symbols
#include <stdio.h>
int main(void)
{
int i = 1;
int j = 2;
int k = 3;
int l = 4;
int m = i * j * k * l;
printf("%d\n", m);
return 0;
}
#include <stdio.h>
static int x2(int x)
{
return x * 2;
}
static int x3(int x)
{
return x * 3;
}
static int x4(int x)
{
return x2(x2(x));
}
int main(void)
{
int x = x4(x3(x2(1)));
printf("%d\n", x);
return 0;
}
$ cc --version
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
$ cc -c -O3 a.c b.c c.c
$ cmp a.o b.o
$ cmp b.o c.o
$ cmp c.o a.o
$ cc -O3 -S a.c
$ cc -c -O3 -S a.c
$ cmp a.o a.o
$ cmp a.o d.o
a.o d.o differ: char 1153, line 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment