mirror of
git://sourceware.org/git/glibc.git
synced 2025-01-18 12:16:13 +08:00
* sysdeps/x86_64/strlen.S: Optimize by using SSE2 instructions.
This commit is contained in:
parent
c0bac8b05a
commit
a152f366dc
@ -1,3 +1,7 @@
|
|||||||
|
2009-04-05 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* sysdeps/x86_64/strlen.S: Optimize by using SSE2 instructions.
|
||||||
|
|
||||||
2009-04-03 Ulrich Drepper <drepper@redhat.com>
|
2009-04-03 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
* configure.in: We need to test for the compiler earlier.
|
* configure.in: We need to test for the compiler earlier.
|
||||||
|
5
NEWS
5
NEWS
@ -1,4 +1,4 @@
|
|||||||
GNU C Library NEWS -- history of user-visible changes. 2009-4-3
|
GNU C Library NEWS -- history of user-visible changes. 2009-4-5
|
||||||
Copyright (C) 1992-2008, 2009 Free Software Foundation, Inc.
|
Copyright (C) 1992-2008, 2009 Free Software Foundation, Inc.
|
||||||
See the end for copying conditions.
|
See the end for copying conditions.
|
||||||
|
|
||||||
@ -37,6 +37,9 @@ Version 2.10
|
|||||||
|
|
||||||
* New locale: nan_TW@latin
|
* New locale: nan_TW@latin
|
||||||
|
|
||||||
|
* Faster strlen on x86-64.
|
||||||
|
Implemented by Ulrich Drepper.
|
||||||
|
|
||||||
|
|
||||||
Version 2.9
|
Version 2.9
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* strlen(str) -- determine the length of the string STR.
|
/* strlen(str) -- determine the length of the string STR.
|
||||||
Copyright (C) 2002, 2003 Free Software Foundation, Inc.
|
Copyright (C) 2009 Free Software Foundation, Inc.
|
||||||
Based on i486 version contributed by Ulrich Drepper <drepper@redhat.com>.
|
Contributed by Ulrich Drepper <drepper@redhat.com>.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -19,121 +19,35 @@
|
|||||||
02111-1307 USA. */
|
02111-1307 USA. */
|
||||||
|
|
||||||
#include <sysdep.h>
|
#include <sysdep.h>
|
||||||
#include "asm-syntax.h"
|
|
||||||
#include "bp-sym.h"
|
|
||||||
#include "bp-asm.h"
|
|
||||||
|
|
||||||
|
|
||||||
.text
|
ENTRY(strlen)
|
||||||
ENTRY (strlen)
|
movq %rdi, %rcx
|
||||||
movq %rdi, %rcx /* Duplicate source pointer. */
|
movq %rdi, %r8
|
||||||
andl $7, %ecx /* mask alignment bits */
|
andq $~15, %rdi
|
||||||
movq %rdi, %rax /* duplicate destination. */
|
pxor %xmm1, %xmm1
|
||||||
jz 1f /* aligned => start loop */
|
orl $0xffffffff, %esi
|
||||||
|
movdqa (%rdi), %xmm0
|
||||||
|
subq %rdi, %rcx
|
||||||
|
leaq 16(%rdi), %rdi
|
||||||
|
pcmpeqb %xmm1, %xmm0
|
||||||
|
shl %cl, %esi
|
||||||
|
pmovmskb %xmm0, %edx
|
||||||
|
xorl %eax, %eax
|
||||||
|
negq %r8
|
||||||
|
andl %esi, %edx
|
||||||
|
jnz 1f
|
||||||
|
|
||||||
neg %ecx /* We need to align to 8 bytes. */
|
2: movdqa (%rdi), %xmm0
|
||||||
addl $8,%ecx
|
leaq 16(%rdi), %rdi
|
||||||
/* Search the first bytes directly. */
|
pcmpeqb %xmm1, %xmm0
|
||||||
0: cmpb $0x0,(%rax) /* is byte NUL? */
|
pmovmskb %xmm0, %edx
|
||||||
je 2f /* yes => return */
|
testl %edx, %edx
|
||||||
incq %rax /* increment pointer */
|
jz 2b
|
||||||
decl %ecx
|
|
||||||
jnz 0b
|
|
||||||
|
|
||||||
1: movq $0xfefefefefefefeff,%r8 /* Save magic. */
|
1: leaq -16(%rdi,%r8), %rdi
|
||||||
|
bsfl %edx, %eax
|
||||||
.p2align 4 /* Align loop. */
|
addq %rdi, %rax
|
||||||
4: /* Main Loop is unrolled 4 times. */
|
|
||||||
/* First unroll. */
|
|
||||||
movq (%rax), %rcx /* get double word (= 8 bytes) in question */
|
|
||||||
addq $8,%rax /* adjust pointer for next word */
|
|
||||||
movq %r8, %rdx /* magic value */
|
|
||||||
addq %rcx, %rdx /* add the magic value to the word. We get
|
|
||||||
carry bits reported for each byte which
|
|
||||||
is *not* 0 */
|
|
||||||
jnc 3f /* highest byte is NUL => return pointer */
|
|
||||||
xorq %rcx, %rdx /* (word+magic)^word */
|
|
||||||
orq %r8, %rdx /* set all non-carry bits */
|
|
||||||
incq %rdx /* add 1: if one carry bit was *not* set
|
|
||||||
the addition will not result in 0. */
|
|
||||||
jnz 3f /* found NUL => return pointer */
|
|
||||||
|
|
||||||
/* Second unroll. */
|
|
||||||
movq (%rax), %rcx /* get double word (= 8 bytes) in question */
|
|
||||||
addq $8,%rax /* adjust pointer for next word */
|
|
||||||
movq %r8, %rdx /* magic value */
|
|
||||||
addq %rcx, %rdx /* add the magic value to the word. We get
|
|
||||||
carry bits reported for each byte which
|
|
||||||
is *not* 0 */
|
|
||||||
jnc 3f /* highest byte is NUL => return pointer */
|
|
||||||
xorq %rcx, %rdx /* (word+magic)^word */
|
|
||||||
orq %r8, %rdx /* set all non-carry bits */
|
|
||||||
incq %rdx /* add 1: if one carry bit was *not* set
|
|
||||||
the addition will not result in 0. */
|
|
||||||
jnz 3f /* found NUL => return pointer */
|
|
||||||
|
|
||||||
/* Third unroll. */
|
|
||||||
movq (%rax), %rcx /* get double word (= 8 bytes) in question */
|
|
||||||
addq $8,%rax /* adjust pointer for next word */
|
|
||||||
movq %r8, %rdx /* magic value */
|
|
||||||
addq %rcx, %rdx /* add the magic value to the word. We get
|
|
||||||
carry bits reported for each byte which
|
|
||||||
is *not* 0 */
|
|
||||||
jnc 3f /* highest byte is NUL => return pointer */
|
|
||||||
xorq %rcx, %rdx /* (word+magic)^word */
|
|
||||||
orq %r8, %rdx /* set all non-carry bits */
|
|
||||||
incq %rdx /* add 1: if one carry bit was *not* set
|
|
||||||
the addition will not result in 0. */
|
|
||||||
jnz 3f /* found NUL => return pointer */
|
|
||||||
|
|
||||||
/* Fourth unroll. */
|
|
||||||
movq (%rax), %rcx /* get double word (= 8 bytes) in question */
|
|
||||||
addq $8,%rax /* adjust pointer for next word */
|
|
||||||
movq %r8, %rdx /* magic value */
|
|
||||||
addq %rcx, %rdx /* add the magic value to the word. We get
|
|
||||||
carry bits reported for each byte which
|
|
||||||
is *not* 0 */
|
|
||||||
jnc 3f /* highest byte is NUL => return pointer */
|
|
||||||
xorq %rcx, %rdx /* (word+magic)^word */
|
|
||||||
orq %r8, %rdx /* set all non-carry bits */
|
|
||||||
incq %rdx /* add 1: if one carry bit was *not* set
|
|
||||||
the addition will not result in 0. */
|
|
||||||
jz 4b /* no NUL found => continue loop */
|
|
||||||
|
|
||||||
.p2align 4 /* Align, it's a jump target. */
|
|
||||||
3: subq $8,%rax /* correct pointer increment. */
|
|
||||||
|
|
||||||
testb %cl, %cl /* is first byte NUL? */
|
|
||||||
jz 2f /* yes => return */
|
|
||||||
incq %rax /* increment pointer */
|
|
||||||
|
|
||||||
testb %ch, %ch /* is second byte NUL? */
|
|
||||||
jz 2f /* yes => return */
|
|
||||||
incq %rax /* increment pointer */
|
|
||||||
|
|
||||||
testl $0x00ff0000, %ecx /* is third byte NUL? */
|
|
||||||
jz 2f /* yes => return pointer */
|
|
||||||
incq %rax /* increment pointer */
|
|
||||||
|
|
||||||
testl $0xff000000, %ecx /* is fourth byte NUL? */
|
|
||||||
jz 2f /* yes => return pointer */
|
|
||||||
incq %rax /* increment pointer */
|
|
||||||
|
|
||||||
shrq $32, %rcx /* look at other half. */
|
|
||||||
|
|
||||||
testb %cl, %cl /* is first byte NUL? */
|
|
||||||
jz 2f /* yes => return */
|
|
||||||
incq %rax /* increment pointer */
|
|
||||||
|
|
||||||
testb %ch, %ch /* is second byte NUL? */
|
|
||||||
jz 2f /* yes => return */
|
|
||||||
incq %rax /* increment pointer */
|
|
||||||
|
|
||||||
testl $0xff0000, %ecx /* is third byte NUL? */
|
|
||||||
jz 2f /* yes => return pointer */
|
|
||||||
incq %rax /* increment pointer */
|
|
||||||
2:
|
|
||||||
subq %rdi, %rax /* compute difference to string start */
|
|
||||||
ret
|
ret
|
||||||
END (strlen)
|
END(strlen)
|
||||||
libc_hidden_builtin_def (strlen)
|
libc_hidden_builtin_def (strlen)
|
||||||
|
Loading…
Reference in New Issue
Block a user