Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define likely(x) __builtin_expect(!!(x), 1)
- #define unlikely(x) __builtin_expect(!!(x), 0)
- void ext(void);
- void foo(int x) {
- if (x > 10) ext();
- }
- void foo_1(int x) {
- if (likely(x > 10)) ext();
- }
- void foo_0(int x) {
- if (unlikely(x > 10)) ext();
- }
- // -----------------------------------------------------------------------------
- // gcc (GCC) 5.3.1 20151207 (Red Hat 5.3.1-2)
- // gcc -O3 -mtune=haswell -c -o tailcall.o
- //
- // tailcall.o: file format elf64-x86-64
- //
- //
- // Disassembly of section .text:
- //
- // 0000000000000000 <foo>:
- // 0: 83 ff 0a cmp $0xa,%edi
- // 3: 7f 0b jg 10 <L00>
- // 5: c3 retq
- // 6: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
- // d: 00 00 00
- // 10:L00 e9 00 00 00 00 jmpq 15 <L01>
- // 15:L01 66 66 2e 0f 1f 84 00 data16 nopw %cs:0x0(%rax,%rax,1)
- // 1c: 00 00 00 00
- //
- // 0000000000000020 <foo_1>:
- // 20: 83 ff 0a cmp $0xa,%edi
- // 23: 7e 0b jle 30 <L01>
- // 25: e9 00 00 00 00 jmpq 2a <L00>
- // 2a:L00 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
- // 30:L01 c3 retq
- // 31: 66 66 66 66 66 66 2e data16 data16 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
- // 38: 0f 1f 84 00 00 00 00
- // 3f: 00
- //
- // 0000000000000040 <foo_0>:
- // 40: 83 ff 0a cmp $0xa,%edi
- // 43: 7f 0b jg 50 <L00>
- // 45: c3 retq
- // 46: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
- // 4d: 00 00 00
- // 50:L00 e9 00 00 00 00 jmpq 55 <foo_0+0x15>
- // -----------------------------------------------------------------------------
- // clang version 3.5.0 (tags/RELEASE_350/final)
- // clang -O3 -mtune=haswell -c -o tailcall.o
- //
- // tailcall.o: file format elf64-x86-64
- //
- //
- // Disassembly of section .text:
- //
- // 0000000000000000 <foo>:
- // 0: 83 ff 0b cmp $0xb,%edi
- // 3: 7c 05 jl a <L00>
- // 5: e9 00 00 00 00 jmpq a <L00>
- // a:L00 c3 retq
- // b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
- //
- // 0000000000000010 <foo_1>:
- // 10: 83 ff 0b cmp $0xb,%edi
- // 13: 7c 05 jl 1a <L00>
- // 15: e9 00 00 00 00 jmpq 1a <L00>
- // 1a:L00 c3 retq
- // 1b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
- //
- // 0000000000000020 <foo_0>:
- // 20: 83 ff 0b cmp $0xb,%edi
- // 23: 7d 01 jge 26 <L00>
- // 25: c3 retq
- // 26:L00 e9 00 00 00 00 jmpq 2b <foo_0+0xb>
- // -----------------------------------------------------------------------------
- // gcc (GCC) 5.3.1 20151207 (Red Hat 5.3.1-2)
- // gcc -O3 -mtune=haswell -S -o tailcall.s
- // .file "tailcall.c"
- // .section .text.unlikely,"ax",@progbits
- // .LCOLDB0:
- // .text
- // .LHOTB0:
- // .p2align 4,,15
- // .globl foo
- // .type foo, @function
- // foo:
- // .LFB0:
- // .cfi_startproc
- // cmpl $10, %edi
- // jg .L4
- // ret
- // .p2align 4,,10
- // .p2align 3
- // .L4:
- // jmp ext
- // .cfi_endproc
- // .LFE0:
- // .size foo, .-foo
- // .section .text.unlikely
- // .LCOLDE0:
- // .text
- // .LHOTE0:
- // .section .text.unlikely
- // .LCOLDB1:
- // .text
- // .LHOTB1:
- // .p2align 4,,15
- // .globl foo_1
- // .type foo_1, @function
- // foo_1:
- // .LFB1:
- // .cfi_startproc
- // cmpl $10, %edi
- // jle .L5
- // jmp ext
- // .p2align 4,,10
- // .p2align 3
- // .L5:
- // ret
- // .cfi_endproc
- // .LFE1:
- // .size foo_1, .-foo_1
- // .section .text.unlikely
- // .LCOLDE1:
- // .text
- // .LHOTE1:
- // .section .text.unlikely
- // .LCOLDB2:
- // .text
- // .LHOTB2:
- // .p2align 4,,15
- // .globl foo_0
- // .type foo_0, @function
- // foo_0:
- // .LFB2:
- // .cfi_startproc
- // cmpl $10, %edi
- // jg .L9
- // ret
- // .p2align 4,,10
- // .p2align 3
- // .L9:
- // jmp ext
- // .cfi_endproc
- // .LFE2:
- // .size foo_0, .-foo_0
- // .section .text.unlikely
- // .LCOLDE2:
- // .text
- // .LHOTE2:
- // .ident "GCC: (GNU) 5.3.1 20151207 (Red Hat 5.3.1-2)"
- // .section .note.GNU-stack,"",@progbits
- // -----------------------------------------------------------------------------
- // clang version 3.5.0 (tags/RELEASE_350/final)
- // clang -O3 -mtune=haswell -S -o tailcall.s
- // .text
- // .file "tailcall.c"
- // .globl foo
- // .align 16, 0x90
- // .type foo,@function
- // foo: # @foo
- // .cfi_startproc
- // # BB#0:
- // cmpl $11, %edi
- // jl .LBB0_1
- // # BB#2:
- // jmp ext # TAILCALL
- // .LBB0_1:
- // retq
- // .Ltmp0:
- // .size foo, .Ltmp0-foo
- // .cfi_endproc
- //
- // .globl foo_1
- // .align 16, 0x90
- // .type foo_1,@function
- // foo_1: # @foo_1
- // .cfi_startproc
- // # BB#0:
- // cmpl $11, %edi
- // jl .LBB1_1
- // # BB#2:
- // jmp ext # TAILCALL
- // .LBB1_1:
- // retq
- // .Ltmp1:
- // .size foo_1, .Ltmp1-foo_1
- // .cfi_endproc
- //
- // .globl foo_0
- // .align 16, 0x90
- // .type foo_0,@function
- // foo_0: # @foo_0
- // .cfi_startproc
- // # BB#0:
- // cmpl $11, %edi
- // jge .LBB2_2
- // # BB#1:
- // retq
- // .LBB2_2:
- // jmp ext # TAILCALL
- // .Ltmp2:
- // .size foo_0, .Ltmp2-foo_0
- // .cfi_endproc
- //
- //
- // .ident "clang version 3.5.0 (tags/RELEASE_350/final)"
- // .section ".note.GNU-stack","",@progbits
Advertisement
Add Comment
Please, Sign In to add comment