- 论坛徽章:
- 0
|
做了二个程序:
1.
- #define likely(x) __builtin_expect (!!(x), 1)
- #define unlikely(x) __builtin_expect (!!(x), 0)
- int main(int argc, char *argv[])
- {
- int i=0;
- if (likely(argc == 3))
- i ++;
- return i;
- }
复制代码 2.
- int main(int argc, char *argv[])
- {
- int i=0;
- if (argc == 3)
- i ++;
- return i;
- }
复制代码 分别用gcc -S -Wall 生成汇编指令。得到如下结果
1.
- .file "likely.c"
- .text
- .globl main
- .type main, @function
- main:
- leal 4(%esp), %ecx
- andl $-16, %esp
- pushl -4(%ecx)
- pushl %ebp
- movl %esp, %ebp
- pushl %ecx
- subl $16, %esp
- movl $0, -8(%ebp)
- cmpl $3, (%ecx)
- sete %al
- movzbl %al, %eax
- testl %eax, %eax
- je .L2
- addl $1, -8(%ebp)
- .L2:
- movl -8(%ebp), %eax
- addl $16, %esp
- popl %ecx
- popl %ebp
- leal -4(%ecx), %esp
- ret
- .size main, .-main
- .ident "GCC: (Debian 4.3.2-1.1) 4.3.2"
- .section .note.GNU-stack,"",@progbits
复制代码 2.
- .file "likely1.c"
- .text
- .globl main
- .type main, @function
- main:
- leal 4(%esp), %ecx
- andl $-16, %esp
- pushl -4(%ecx)
- pushl %ebp
- movl %esp, %ebp
- pushl %ecx
- subl $16, %esp
- movl $0, -8(%ebp)
- cmpl $3, (%ecx)
- jne .L2
- addl $1, -8(%ebp)
- .L2:
- movl -8(%ebp), %eax
- addl $16, %esp
- popl %ecx
- popl %ebp
- leal -4(%ecx), %esp
- ret
- .size main, .-main
- .ident "GCC: (Debian 4.3.2-1.1) 4.3.2"
- .section .note.GNU-stack,"",@progbits
复制代码 看不懂汇编,请大虾指点。 |
|