Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
__builtin_expect comparison
--- readdir.s 2012-07-03 16:24:35.568018624 +0000
+++ readdir_o.s 2012-07-03 16:24:06.528020576 +0000
@@ -12,9 +12,9 @@
movl 16(%rdi), %edx
movq %rdi, %rbx
cmpl 20(%rdi), %edx
+ jge .L7
+.L2:
movslq %edx, %rax
- jge .L8
-.L3:
leaq 32(%rbx,%rax), %rax
movzwl 16(%rax), %ecx
addl %ecx, %edx
@@ -25,26 +25,22 @@
.cfi_remember_state
.cfi_def_cfa_offset 8
ret
- .p2align 4,,10
- .p2align 3
-.L8:
+.L7:
.cfi_restore_state
leaq 32(%rdi), %rsi
movl (%rdi), %edi
movl $2048, %edx
call __getdents
testl %eax, %eax
- jle .L5
+ jle .L4
movl %eax, 20(%rbx)
xorl %edx, %edx
- xorl %eax, %eax
- jmp .L3
- .p2align 4,,10
- .p2align 3
-.L5:
+ jmp .L2
+.L4:
xorl %eax, %eax
popq %rbx
.cfi_def_cfa_offset 8
+ .p2align 4,,1
ret
.cfi_endproc
.LFE7:
.file "readdir.c"
.text
.p2align 4,,15
.globl readdir
.type readdir, @function
readdir:
.LFB7:
.cfi_startproc
pushq %rbx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
movl 16(%rdi), %edx
movq %rdi, %rbx
cmpl 20(%rdi), %edx
movslq %edx, %rax
jge .L8
.L3:
leaq 32(%rbx,%rax), %rax
movzwl 16(%rax), %ecx
addl %ecx, %edx
movl %edx, 16(%rbx)
movq 8(%rax), %rdx
movq %rdx, 8(%rbx)
popq %rbx
.cfi_remember_state
.cfi_def_cfa_offset 8
ret
.p2align 4,,10
.p2align 3
.L8:
.cfi_restore_state
leaq 32(%rdi), %rsi
movl (%rdi), %edi
movl $2048, %edx
call __getdents
testl %eax, %eax
jle .L5
movl %eax, 20(%rbx)
xorl %edx, %edx
xorl %eax, %eax
jmp .L3
.p2align 4,,10
.p2align 3
.L5:
xorl %eax, %eax
popq %rbx
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE7:
.size readdir, .-readdir
.weak readdir64
.set readdir64,readdir
.ident "GCC: (Exherbo gcc-4.7.1) 4.7.1"
.section .note.GNU-stack,"",@progbits
.file "readdir.c"
.text
.p2align 4,,15
.globl readdir
.type readdir, @function
readdir:
.LFB7:
.cfi_startproc
pushq %rbx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
movl 16(%rdi), %edx
movq %rdi, %rbx
cmpl 20(%rdi), %edx
jge .L7
.L2:
movslq %edx, %rax
leaq 32(%rbx,%rax), %rax
movzwl 16(%rax), %ecx
addl %ecx, %edx
movl %edx, 16(%rbx)
movq 8(%rax), %rdx
movq %rdx, 8(%rbx)
popq %rbx
.cfi_remember_state
.cfi_def_cfa_offset 8
ret
.L7:
.cfi_restore_state
leaq 32(%rdi), %rsi
movl (%rdi), %edi
movl $2048, %edx
call __getdents
testl %eax, %eax
jle .L4
movl %eax, 20(%rbx)
xorl %edx, %edx
jmp .L2
.L4:
xorl %eax, %eax
popq %rbx
.cfi_def_cfa_offset 8
.p2align 4,,1
ret
.cfi_endproc
.LFE7:
.size readdir, .-readdir
.weak readdir64
.set readdir64,readdir
.ident "GCC: (Exherbo gcc-4.7.1) 4.7.1"
.section .note.GNU-stack,"",@progbits
.file "src/dirent/readdir.c"
.text
.globl readdir
.align 16, 0x90
.type readdir,@function
readdir: # @readdir
.cfi_startproc
# BB#0:
pushq %rbx
.Ltmp2:
.cfi_def_cfa_offset 16
.Ltmp3:
.cfi_offset %rbx, -16
movq %rdi, %rbx
movl 16(%rbx), %eax
cmpl 20(%rbx), %eax
jl .LBB0_3
# BB#1:
movl (%rbx), %edi
leaq 32(%rbx), %rsi
movl $2048, %edx # imm = 0x800
callq __getdents
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jle .LBB0_4
# BB#2:
movl %ecx, 20(%rbx)
movl $0, 16(%rbx)
xorl %eax, %eax
.LBB0_3:
movslq %eax, %rax
movzwl 48(%rbx,%rax), %ecx
movl %eax, %edx
addl %ecx, %edx
movl %edx, 16(%rbx)
movq 40(%rbx,%rax), %rcx
movq %rcx, 8(%rbx)
leaq 32(%rbx,%rax), %rax
.LBB0_4:
popq %rbx
ret
.Ltmp4:
.size readdir, .Ltmp4-readdir
.cfi_endproc
.weak readdir64
readdir64 = readdir
.section ".note.GNU-stack","",@progbits
.file "src/dirent/readdir.c"
.text
.globl readdir
.align 16, 0x90
.type readdir,@function
readdir: # @readdir
.cfi_startproc
# BB#0:
pushq %rbx
.Ltmp2:
.cfi_def_cfa_offset 16
.Ltmp3:
.cfi_offset %rbx, -16
movq %rdi, %rbx
movl 16(%rbx), %eax
cmpl 20(%rbx), %eax
jge .LBB0_1
.align 16, 0x90
.LBB0_3:
movslq %eax, %rax
movzwl 48(%rbx,%rax), %ecx
movl %eax, %edx
addl %ecx, %edx
movl %edx, 16(%rbx)
movq 40(%rbx,%rax), %rcx
movq %rcx, 8(%rbx)
leaq 32(%rbx,%rax), %rax
.align 16, 0x90
.LBB0_4:
popq %rbx
ret
.LBB0_1:
movl (%rbx), %edi
leaq 32(%rbx), %rsi
movl $2048, %edx # imm = 0x800
callq __getdents
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jle .LBB0_4
# BB#2:
movl %ecx, 20(%rbx)
movl $0, 16(%rbx)
xorl %eax, %eax
jmp .LBB0_3
.Ltmp4:
.size readdir, .Ltmp4-readdir
.cfi_endproc
.weak readdir64
readdir64 = readdir
.section ".note.GNU-stack","",@progbits
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include <limits.h>
#include "__dirent.h"
#include "syscall.h"
#include "libc.h"
#include "compiler.h"
int __getdents(int, struct dirent *, size_t);
struct dirent *readdir(DIR *dir)
{
struct dirent *de;
if (dir->buf_pos >= dir->buf_end) {
int len = __getdents(dir->fd, (void *)dir->buf, sizeof dir->buf);
if (len <= 0) return 0;
dir->buf_end = len;
dir->buf_pos = 0;
}
de = (void *)(dir->buf + dir->buf_pos);
dir->buf_pos += de->d_reclen;
dir->tell = de->d_off;
return de;
}
LFS64(readdir);
--- readdir.s 2012-07-03 15:25:01.324857380 +0000
+++ readdir_o.s 2012-07-03 15:25:28.108185315 +0000
@@ -14,20 +14,8 @@
movq %rdi, %rbx
movl 16(%rbx), %eax
cmpl 20(%rbx), %eax
- jl .LBB0_3
-# BB#1:
- movl (%rbx), %edi
- leaq 32(%rbx), %rsi
- movl $2048, %edx # imm = 0x800
- callq __getdents
- movl %eax, %ecx
- xorl %eax, %eax
- testl %ecx, %ecx
- jle .LBB0_4
-# BB#2:
- movl %ecx, 20(%rbx)
- movl $0, 16(%rbx)
- xorl %eax, %eax
+ jge .LBB0_1
+ .align 16, 0x90
.LBB0_3:
movslq %eax, %rax
movzwl 48(%rbx,%rax), %ecx
@@ -37,9 +25,24 @@
movq 40(%rbx,%rax), %rcx
movq %rcx, 8(%rbx)
leaq 32(%rbx,%rax), %rax
+ .align 16, 0x90
.LBB0_4:
popq %rbx
ret
+.LBB0_1:
+ movl (%rbx), %edi
+ leaq 32(%rbx), %rsi
+ movl $2048, %edx # imm = 0x800
+ callq __getdents
+ movl %eax, %ecx
+ xorl %eax, %eax
+ testl %ecx, %ecx
+ jle .LBB0_4
+# BB#2:
+ movl %ecx, 20(%rbx)
+ movl $0, 16(%rbx)
+ xorl %eax, %eax
+ jmp .LBB0_3
.Ltmp4:
.size readdir, .Ltmp4-readdir
.cfi_endproc
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include <limits.h>
#include "__dirent.h"
#include "syscall.h"
#include "libc.h"
#include "compiler.h"
int __getdents(int, struct dirent *, size_t);
struct dirent *readdir(DIR *dir)
{
struct dirent *de;
if (unlikely(dir->buf_pos >= dir->buf_end)) {
int len = __getdents(dir->fd, (void *)dir->buf, sizeof dir->buf);
if (len <= 0) return 0;
dir->buf_end = len;
dir->buf_pos = 0;
}
de = (void *)(dir->buf + dir->buf_pos);
dir->buf_pos += de->d_reclen;
dir->tell = de->d_off;
return de;
}
LFS64(readdir);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.