Skip to content

Commit

Permalink
Optimize x86-64 sem_wait for uncontested semaphore.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Drepper committed Jul 17, 2009
1 parent c3c2f3c commit 0adae46
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
3 changes: 3 additions & 0 deletions nptl/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
2009-07-17 Ulrich Drepper <drepper@redhat.com>

* sysdeps/unix/sysv/linux/x86_64/sem_wait.S (sem_wait): Optimize
handling of uncontested semaphore.

* sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
(__condvar_cleanup): Rewrite to use cfi directives instead of
hand-coded unwind tables.
Expand Down
51 changes: 27 additions & 24 deletions nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,36 @@ sem_wait:
cfi_personality(DW_EH_PE_udata4, __gcc_personality_v0)
cfi_lsda(DW_EH_PE_udata4, .LexceptSTART)
#endif
pushq %r12
cfi_adjust_cfa_offset(8)
cfi_rel_offset(%r12, 0)
pushq %r13
cfi_adjust_cfa_offset(8)
cfi_rel_offset(%r13, 0)
movq %rdi, %r13

#if VALUE == 0
movl (%r13), %eax
movl (%rdi), %eax
#else
movl VALUE(%r13), %eax
movl VALUE(%rdi), %eax
#endif
2: testl %eax, %eax
je 1f

leal -1(%rax), %edx
LOCK
#if VALUE == 0
cmpxchgl %edx, (%r13)
cmpxchgl %edx, (%rdi)
#else
cmpxchgl %edx, VALUE(%r13)
cmpxchgl %edx, VALUE(%rdi)
#endif
jne 2b

7: xorl %eax, %eax

9: popq %r13
cfi_adjust_cfa_offset(-8)
cfi_restore(%r13)
popq %r12
cfi_adjust_cfa_offset(-8)
cfi_restore(%r12)

xorl %eax, %eax
retq

cfi_adjust_cfa_offset(2 * 8)
cfi_rel_offset(%r12, 8)
1: pushq %r12
cfi_adjust_cfa_offset(8)
cfi_rel_offset(%r12, 0)
pushq %r13
cfi_adjust_cfa_offset(8)
cfi_rel_offset(%r13, 0)
1: LOCK
movq %rdi, %r13

LOCK
addq $1, NWAITERS(%r13)

.LcleanupSTART:
Expand Down Expand Up @@ -128,8 +118,21 @@ sem_wait:

LOCK
subq $1, NWAITERS(%r13)
jmp 7b

xorl %eax, %eax

9: popq %r13
cfi_adjust_cfa_offset(-8)
cfi_restore(%r13)
popq %r12
cfi_adjust_cfa_offset(-8)
cfi_restore(%r12)

retq

cfi_adjust_cfa_offset(2 * 8)
cfi_rel_offset(%r12, 8)
cfi_rel_offset(%r13, 0)
4: negq %r12
#if USE___THREAD
movq errno@gottpoff(%rip), %rdx
Expand Down

0 comments on commit 0adae46

Please sign in to comment.