summaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/posix/preadv.c108
-rw-r--r--sysdeps/posix/preadv64.c9
-rw-r--r--sysdeps/posix/pwritev.c108
-rw-r--r--sysdeps/posix/pwritev64.c9
-rw-r--r--sysdeps/posix/readv.c40
-rw-r--r--sysdeps/posix/writev.c42
-rw-r--r--sysdeps/unix/sysv/linux/bits/socket.h12
-rw-r--r--sysdeps/unix/sysv/linux/kernel-features.h14
-rw-r--r--sysdeps/unix/sysv/linux/preadv.c88
-rw-r--r--sysdeps/unix/sysv/linux/preadv64.c6
-rw-r--r--sysdeps/unix/sysv/linux/pwritev.c88
-rw-r--r--sysdeps/unix/sysv/linux/pwritev64.c6
-rw-r--r--sysdeps/unix/sysv/linux/readv.c46
-rw-r--r--sysdeps/unix/sysv/linux/sys/eventfd.h2
-rw-r--r--sysdeps/unix/sysv/linux/wordsize-64/preadv64.c1
-rw-r--r--sysdeps/unix/sysv/linux/wordsize-64/pwritev64.c1
-rw-r--r--sysdeps/unix/sysv/linux/writev.c45
-rw-r--r--sysdeps/x86_64/strchr.S313
-rw-r--r--sysdeps/x86_64/strlen.S146
19 files changed, 608 insertions, 476 deletions
diff --git a/sysdeps/posix/preadv.c b/sysdeps/posix/preadv.c
new file mode 100644
index 0000000000..e697604c19
--- /dev/null
+++ b/sysdeps/posix/preadv.c
@@ -0,0 +1,108 @@
+/* Copyright (C) 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <sys/param.h>
+#if __WORDSIZE == 64 && !defined PREADV
+/* Hide the preadv64 declaration. */
+# define preadv64 __redirect_preadv64
+#endif
+#include <sys/uio.h>
+#include <bits/wordsize.h>
+
+#ifndef PREADV
+# define PREADV preadv
+# define PREAD __pread
+# define OFF_T off_t
+#endif
+
+
+static void
+ifree (char **ptrp)
+{
+ free (*ptrp);
+}
+
+
+/* Read data from file descriptor FD at the given position OFFSET
+ without change the file pointer, and put the result in the buffers
+ described by VECTOR, which is a vector of COUNT 'struct iovec's.
+ The buffers are filled in the order specified. Operates just like
+ 'read' (see <unistd.h>) except that data are put in VECTOR instead
+ of a contiguous buffer. */
+ssize_t
+PREADV (int fd, const struct iovec *vector, int count, OFF_T offset)
+{
+ /* Find the total number of bytes to be read. */
+ size_t bytes = 0;
+ for (int i = 0; i < count; ++i)
+ {
+ /* Check for ssize_t overflow. */
+ if (SSIZE_MAX - bytes < vector[i].iov_len)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ bytes += vector[i].iov_len;
+ }
+
+ /* Allocate a temporary buffer to hold the data. We should normally
+ use alloca since it's faster and does not require synchronization
+ with other threads. But we cannot if the amount of memory
+ required is too large. */
+ char *buffer;
+ char *malloced_buffer __attribute__ ((__cleanup__ (ifree))) = NULL;
+ if (__libc_use_alloca (bytes))
+ buffer = (char *) __alloca (bytes);
+ else
+ {
+ malloced_buffer = buffer = (char *) malloc (bytes);
+ if (buffer == NULL)
+ return -1;
+ }
+
+ /* Read the data. */
+ ssize_t bytes_read = PREAD (fd, buffer, bytes, offset);
+ if (bytes_read <= 0)
+ return -1;
+
+ /* Copy the data from BUFFER into the memory specified by VECTOR. */
+ bytes = bytes_read;
+ for (int i = 0; i < count; ++i)
+ {
+ size_t copy = MIN (vector[i].iov_len, bytes);
+
+ (void) memcpy ((void *) vector[i].iov_base, (void *) buffer, copy);
+
+ buffer += copy;
+ bytes -= copy;
+ if (bytes == 0)
+ break;
+ }
+
+ return bytes_read;
+}
+#if __WORDSIZE == 64 && defined preadv64
+# undef preadv64
+strong_alias (preadv, preadv64)
+#endif
diff --git a/sysdeps/posix/preadv64.c b/sysdeps/posix/preadv64.c
new file mode 100644
index 0000000000..198622353a
--- /dev/null
+++ b/sysdeps/posix/preadv64.c
@@ -0,0 +1,9 @@
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 32
+# define PREADV preadv64
+# define PREAD __pread64
+# define OFF_T off64_t
+
+# include "preadv.c"
+#endif
diff --git a/sysdeps/posix/pwritev.c b/sysdeps/posix/pwritev.c
new file mode 100644
index 0000000000..0b6627dc9d
--- /dev/null
+++ b/sysdeps/posix/pwritev.c
@@ -0,0 +1,108 @@
+/* Copyright (C) 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <sys/param.h>
+#if __WORDSIZE == 64 && !defined PWRITEV
+/* Hide the pwritev64 declaration. */
+# define pwritev64 __redirect_pwritev64
+#endif
+#include <sys/uio.h>
+#include <bits/wordsize.h>
+
+#ifndef PWRITEV
+# define PWRITEV pwritev
+# define PWRITE __pwrite
+# define OFF_T off_t
+#endif
+
+
+static void
+ifree (char **ptrp)
+{
+ free (*ptrp);
+}
+
+
+/* Read data from file descriptor FD at the given position OFFSET
+ without change the file pointer, and put the result in the buffers
+ described by VECTOR, which is a vector of COUNT 'struct iovec's.
+ The buffers are filled in the order specified. Operates just like
+ 'read' (see <unistd.h>) except that data are put in VECTOR instead
+ of a contiguous buffer. */
+ssize_t
+PWRITEV (int fd, const struct iovec *vector, int count, OFF_T offset)
+{
+ /* Find the total number of bytes to be read. */
+ size_t bytes = 0;
+ for (int i = 0; i < count; ++i)
+ {
+ /* Check for ssize_t overflow. */
+ if (SSIZE_MAX - bytes < vector[i].iov_len)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ bytes += vector[i].iov_len;
+ }
+
+ /* Allocate a temporary buffer to hold the data. We should normally
+ use alloca since it's faster and does not require synchronization
+ with other threads. But we cannot if the amount of memory
+ required is too large. */
+ char *buffer;
+ char *malloced_buffer __attribute__ ((__cleanup__ (ifree))) = NULL;
+ if (__libc_use_alloca (bytes))
+ buffer = (char *) __alloca (bytes);
+ else
+ {
+ malloced_buffer = buffer = (char *) malloc (bytes);
+ if (buffer == NULL)
+ return -1;
+ }
+
+ /* Read the data. */
+ ssize_t bytes_read = PWRITE (fd, buffer, bytes, offset);
+ if (bytes_read <= 0)
+ return -1;
+
+ /* Copy the data from BUFFER into the memory specified by VECTOR. */
+ bytes = bytes_read;
+ for (int i = 0; i < count; ++i)
+ {
+ size_t copy = MIN (vector[i].iov_len, bytes);
+
+ (void) memcpy ((void *) vector[i].iov_base, (void *) buffer, copy);
+
+ buffer += copy;
+ bytes -= copy;
+ if (bytes == 0)
+ break;
+ }
+
+ return bytes_read;
+}
+#if __WORDSIZE == 64 && defined pwritev64
+# undef pwritev64
+strong_alias (pwritev, pwritev64)
+#endif
diff --git a/sysdeps/posix/pwritev64.c b/sysdeps/posix/pwritev64.c
new file mode 100644
index 0000000000..4948d2efee
--- /dev/null
+++ b/sysdeps/posix/pwritev64.c
@@ -0,0 +1,9 @@
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 32
+# define PWRITEV pwritev64
+# define PWRITE __pwrite64
+# define OFF_T off64_t
+
+# include "pwritev.c"
+#endif
diff --git a/sysdeps/posix/readv.c b/sysdeps/posix/readv.c
index f0e78e6662..50bcc91315 100644
--- a/sysdeps/posix/readv.c
+++ b/sysdeps/posix/readv.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1996, 1997, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1992,1996,1997,2002,2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -25,24 +25,24 @@
#include <sys/uio.h>
#include <errno.h>
+
+static void
+ifree (char **ptrp)
+{
+ free (*ptrp);
+}
+
/* Read data from file descriptor FD, and put the result in the
- buffers described by VECTOR, which is a vector of COUNT `struct iovec's.
+ buffers described by VECTOR, which is a vector of COUNT 'struct iovec's.
The buffers are filled in the order specified.
- Operates just like `read' (see <unistd.h>) except that data are
+ Operates just like 'read' (see <unistd.h>) except that data are
put in VECTOR instead of a contiguous buffer. */
ssize_t
__libc_readv (int fd, const struct iovec *vector, int count)
{
- char *buffer;
- char *buffer_start;
- size_t bytes;
- ssize_t bytes_read;
- int i;
- bool use_malloc = false;
-
/* Find the total number of bytes to be read. */
- bytes = 0;
- for (i = 0; i < count; ++i)
+ size_t bytes = 0;
+ for (int i = 0; i < count; ++i)
{
/* Check for ssize_t overflow. */
if (SSIZE_MAX - bytes < vector[i].iov_len)
@@ -57,28 +57,25 @@ __libc_readv (int fd, const struct iovec *vector, int count)
use alloca since it's faster and does not require synchronization
with other threads. But we cannot if the amount of memory
required is too large. */
+ char *buffer;
+ char *malloced_buffer __attribute__ ((__cleanup__ (ifree))) = NULL;
if (__libc_use_alloca (bytes))
buffer = (char *) __alloca (bytes);
else
{
- buffer = (char *) malloc (bytes);
+ malloced_buffer = buffer = (char *) malloc (bytes);
if (buffer == NULL)
- /* XXX I don't know whether it is acceptable to try reading
- the data in chunks. Probably not so we just fail here. */
return -1;
-
- use_malloc = true;
}
/* Read the data. */
- bytes_read = __read (fd, buffer, bytes);
+ ssize_t bytes_read = __read (fd, buffer, bytes);
if (bytes_read <= 0)
return -1;
/* Copy the data from BUFFER into the memory specified by VECTOR. */
bytes = bytes_read;
- buffer_start = buffer;
- for (i = 0; i < count; ++i)
+ for (int i = 0; i < count; ++i)
{
size_t copy = MIN (vector[i].iov_len, bytes);
@@ -90,9 +87,6 @@ __libc_readv (int fd, const struct iovec *vector, int count)
break;
}
- if (use_malloc)
- free (buffer_start);
-
return bytes_read;
}
#ifndef __libc_readv
diff --git a/sysdeps/posix/writev.c b/sysdeps/posix/writev.c
index a347cc2eac..203cf9cebd 100644
--- a/sysdeps/posix/writev.c
+++ b/sysdeps/posix/writev.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1996, 1997, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1992,1996,1997,2002,2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -25,24 +25,25 @@
#include <sys/uio.h>
#include <errno.h>
+
+static void
+ifree (char **ptrp)
+{
+ free (*ptrp);
+}
+
+
/* Write data pointed by the buffers described by VECTOR, which
- is a vector of COUNT `struct iovec's, to file descriptor FD.
+ is a vector of COUNT 'struct iovec's, to file descriptor FD.
The data is written in the order specified.
- Operates just like `write' (see <unistd.h>) except that the data
+ Operates just like 'write' (see <unistd.h>) except that the data
are taken from VECTOR instead of a contiguous buffer. */
ssize_t
__libc_writev (int fd, const struct iovec *vector, int count)
{
- char *buffer;
- register char *bp;
- size_t bytes, to_copy;
- ssize_t bytes_written;
- int i;
- bool use_malloc = false;
-
/* Find the total number of bytes to be written. */
- bytes = 0;
- for (i = 0; i < count; ++i)
+ size_t bytes = 0;
+ for (int i = 0; i < count; ++i)
{
/* Check for ssize_t overflow. */
if (SSIZE_MAX - bytes < vector[i].iov_len)
@@ -57,23 +58,23 @@ __libc_writev (int fd, const struct iovec *vector, int count)
use alloca since it's faster and does not require synchronization
with other threads. But we cannot if the amount of memory
required is too large. */
+ char *buffer;
+ char *malloced_buffer __attribute__ ((__cleanup__ (ifree))) = NULL;
if (__libc_use_alloca (bytes))
buffer = (char *) __alloca (bytes);
else
{
- buffer = (char *) malloc (bytes);
+ malloced_buffer = buffer = (char *) malloc (bytes);
if (buffer == NULL)
/* XXX I don't know whether it is acceptable to try writing
the data in chunks. Probably not so we just fail here. */
return -1;
-
- use_malloc = true;
}
/* Copy the data into BUFFER. */
- to_copy = bytes;
- bp = buffer;
- for (i = 0; i < count; ++i)
+ size_t to_copy = bytes;
+ char *bp = buffer;
+ for (int i = 0; i < count; ++i)
{
size_t copy = MIN (vector[i].iov_len, to_copy);
@@ -84,10 +85,7 @@ __libc_writev (int fd, const struct iovec *vector, int count)
break;
}
- bytes_written = __write (fd, buffer, bytes);
-
- if (use_malloc)
- free (buffer);
+ ssize_t bytes_written = __write (fd, buffer, bytes);
return bytes_written;
}
diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h
index 72c7335ae5..88062e59ad 100644
--- a/sysdeps/unix/sysv/linux/bits/socket.h
+++ b/sysdeps/unix/sysv/linux/bits/socket.h
@@ -95,15 +95,20 @@ enum __socket_type
#define PF_ASH 18 /* Ash. */
#define PF_ECONET 19 /* Acorn Econet. */
#define PF_ATMSVC 20 /* ATM SVCs. */
+#define PF_RDS 21 /* RDS sockets. */
#define PF_SNA 22 /* Linux SNA Project */
#define PF_IRDA 23 /* IRDA sockets. */
#define PF_PPPOX 24 /* PPPoX sockets. */
#define PF_WANPIPE 25 /* Wanpipe API sockets. */
+#define PF_LLC 26 /* Linux LLC. */
+#define PF_CAN 29 /* Controller Area Network. */
+#define PF_TIPC 30 /* TIPC sockets. */
#define PF_BLUETOOTH 31 /* Bluetooth sockets. */
#define PF_IUCV 32 /* IUCV sockets. */
#define PF_RXRPC 33 /* RxRPC sockets. */
#define PF_ISDN 34 /* mISDN sockets. */
-#define PF_MAX 35 /* For now.. */
+#define PF_PHONET 35 /* Phonet sockets. */
+#define PF_MAX 36 /* For now.. */
/* Address families. */
#define AF_UNSPEC PF_UNSPEC
@@ -130,14 +135,19 @@ enum __socket_type
#define AF_ASH PF_ASH
#define AF_ECONET PF_ECONET
#define AF_ATMSVC PF_ATMSVC
+#define AF_RDS PF_RDS
#define AF_SNA PF_SNA
#define AF_IRDA PF_IRDA
#define AF_PPPOX PF_PPPOX
#define AF_WANPIPE PF_WANPIPE
+#define AF_LLC PF_LLC
+#define AF_CAN PF_CAN
+#define AF_TIPC PF_TIPC
#define AF_BLUETOOTH PF_BLUETOOTH
#define AF_IUCV PF_IUCV
#define AF_RXRPC PF_RXRPC
#define AF_ISDN PF_ISDN
+#define AF_PHONET PF_PHONET
#define AF_MAX PF_MAX
/* Socket level values. Others are defined in the appropriate headers.
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 29afe27711..a640765b5c 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -462,6 +462,13 @@
# define __ASSUME_SET_ROBUST_LIST 1
#endif
+/* Pessimistically assume that 2.6.18 introduced real handling of
+ large numbers of requests to readv and writev and that we don't
+ need a fallback. It likely worked for much longer. */
+#if __LINUX_KERNEL_VERSION >= 0x020612
+# define __ASSUME_COMPLETE_READV_WRITEV 1
+#endif
+
/* Support for PI futexes was added in 2.6.18. */
#if __LINUX_KERNEL_VERSION >= 0x020612
# define __ASSUME_FUTEX_LOCK_PI 1
@@ -522,3 +529,10 @@
#if __LINUX_KERNEL_VERSION >= 0x02061d
# define __ASSUME_FUTEX_CLOCK_REALTIME 1
#endif
+
+/* Support for preadv and pwritev was added in 2.6.30. */
+#if __LINUX_KERNEL_VERSION >= 0x02061e \
+ && (defined __i386__ || defined __x86_64__)
+# define __ASSUME_PREADV 1
+# define __ASSUME_PWRITEV 1
+#endif
diff --git a/sysdeps/unix/sysv/linux/preadv.c b/sysdeps/unix/sysv/linux/preadv.c
new file mode 100644
index 0000000000..e2f8238596
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/preadv.c
@@ -0,0 +1,88 @@
+/* Copyright (C) 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/param.h>
+#if __WORDSIZE == 64
+/* Hide the preadv64 declaration. */
+# define preadv64 __redirect_preadv64
+#endif
+#include <sys/uio.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <kernel-features.h>
+
+#ifndef PREADV
+# define PREADV preadv
+# define PREADV_REPLACEMENT __atomic_preadv_replacement
+# define PREAD __pread
+# define OFF_T off_t
+#endif
+
+static ssize_t PREADV_REPLACEMENT (int, __const struct iovec *,
+ int, OFF_T) internal_function;
+
+
+ssize_t
+PREADV (fd, vector, count, offset)
+ int fd;
+ const struct iovec *vector;
+ int count;
+ OFF_T offset;
+{
+#ifdef __NR_preadv
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ result = INLINE_SYSCALL (preadv, 5, fd, vector, count, offset >> 32,
+ offset & 0xffffffff);
+ else
+ {
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ result = INLINE_SYSCALL (preadv, 5, fd, vector, count, offset >> 32,
+ offset & 0xffffffff);
+
+ LIBC_CANCEL_RESET (oldtype);
+ }
+# ifdef __ASSUME_PREADV
+ return result;
+# endif
+#endif
+
+#ifndef __ASSUME_PREADV
+# ifdef __NR_preadv
+ if (result >= 0 || errno != ENOSYS)
+ return result;
+# endif
+
+ return PREADV_REPLACEMENT (fd, vector, count, offset);
+#endif
+}
+#if __WORDSIZE == 64
+# undef preadv64
+strong_alias (preadv, preadv64)
+#endif
+
+#ifndef __ASSUME_PREADV
+# undef PREADV
+# define PREADV static internal_function PREADV_REPLACEMENT
+# include <sysdeps/posix/preadv.c>
+#endif
diff --git a/sysdeps/unix/sysv/linux/preadv64.c b/sysdeps/unix/sysv/linux/preadv64.c
new file mode 100644
index 0000000000..739df00257
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/preadv64.c
@@ -0,0 +1,6 @@
+#define PREADV preadv64
+#define PREADV_REPLACEMENT __atomic_preadv64_replacement
+#define PREAD __pread64
+#define OFF_T off64_t
+
+#include "preadv.c"
diff --git a/sysdeps/unix/sysv/linux/pwritev.c b/sysdeps/unix/sysv/linux/pwritev.c
new file mode 100644
index 0000000000..df430ffe46
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/pwritev.c
@@ -0,0 +1,88 @@
+/* Copyright (C) 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stddef.h>
+#include <sys/param.h>
+#if __WORDSIZE == 64 && !defined PWRITEV
+/* Hide the pwritev64 declaration. */
+# define pwritev64 __redirect_pwritev64
+#endif
+#include <sys/uio.h>
+
+#include <sysdep-cancel.h>
+#include <sys/syscall.h>
+#include <kernel-features.h>
+
+#ifndef PWRITEV
+# define PWRITEV pwritev
+# define PWRITEV_REPLACEMENT __atomic_pwritev_replacement
+# define PWRITE __pwrite
+# define OFF_T off_t
+#endif
+
+static ssize_t PWRITEV_REPLACEMENT (int, __const struct iovec *,
+ int, OFF_T) internal_function;
+
+
+ssize_t
+PWRITEV (fd, vector, count, offset)
+ int fd;
+ const struct iovec *vector;
+ int count;
+ OFF_T offset;
+{
+#ifdef __NR_pwritev
+ ssize_t result;
+
+ if (SINGLE_THREAD_P)
+ result = INLINE_SYSCALL (pwritev, 5, fd, vector, count, offset >> 32,
+ offset & 0xffffffff);
+ else
+ {
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ result = INLINE_SYSCALL (pwritev, 5, fd, vector, count, offset >> 32,
+ offset & 0xffffffff);
+
+ LIBC_CANCEL_RESET (oldtype);
+ }
+# ifdef __ASSUME_PWRITEV
+ return result;
+# endif
+#endif
+
+#ifndef __ASSUME_PWRITEV
+# ifdef __NR_pwritev
+ if (result >= 0 || errno != ENOSYS)
+ return result;
+# endif
+
+ return PWRITEV_REPLACEMENT (fd, vector, count, offset);
+#endif
+}
+#if __WORDSIZE == 64 && defined pwritev64
+# undef pwritev64
+strong_alias (pwritev, pwritev64)
+#endif
+
+#ifndef __ASSUME_PWRITEV
+# undef PWRITEV
+# define PWRITEV static internal_function PWRITEV_REPLACEMENT
+# include <sysdeps/posix/pwritev.c>
+#endif
diff --git a/sysdeps/unix/sysv/linux/pwritev64.c b/sysdeps/unix/sysv/linux/pwritev64.c
new file mode 100644
index 0000000000..1e8168f103
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/pwritev64.c
@@ -0,0 +1,6 @@
+#define PWRITEV pwritev64
+#define PWRITEV_REPLACEMENT __atomic_pwritev64_replacement
+#define PWRITE __pwrite64
+#define OFF_T off64_t
+
+#include "pwritev.c"
diff --git a/sysdeps/unix/sysv/linux/readv.c b/sysdeps/unix/sysv/linux/readv.c
index 250c00a075..bff4a3ff74 100644
--- a/sysdeps/unix/sysv/linux/readv.c
+++ b/sysdeps/unix/sysv/linux/readv.c
@@ -1,5 +1,5 @@
/* readv supports all Linux kernels >= 2.0.
- Copyright (C) 1997,1998,2000,2002,2003 Free Software Foundation, Inc.
+ Copyright (C) 1997,1998,2000,2002,2003,2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -25,6 +25,7 @@
#include <sysdep-cancel.h>
#include <sys/syscall.h>
#include <bp-checks.h>
+#include <kernel-features.h>
static ssize_t __atomic_readv_replacement (int, __const struct iovec *,
int) internal_function;
@@ -36,41 +37,38 @@ static ssize_t __atomic_readv_replacement (int, __const struct iovec *,
#endif
-/* We should deal with kernel which have a smaller UIO_FASTIOV as well
- as a very big count. */
-static ssize_t
-do_readv (int fd, const struct iovec *vector, int count)
-{
- ssize_t bytes_read;
-
- bytes_read = INLINE_SYSCALL (readv, 3, fd, CHECK_N (vector, count), count);
-
- if (bytes_read >= 0 || errno != EINVAL || count <= UIO_FASTIOV)
- return bytes_read;
-
- return __atomic_readv_replacement (fd, vector, count);
-}
-
-
ssize_t
__libc_readv (fd, vector, count)
int fd;
const struct iovec *vector;
int count;
{
- if (SINGLE_THREAD_P)
- return do_readv (fd, vector, count);
+ ssize_t result;
- int oldtype = LIBC_CANCEL_ASYNC ();
+ if (SINGLE_THREAD_P)
+ result = INLINE_SYSCALL (readv, 3, fd, CHECK_N (vector, count), count);
+ else
+ {
+ int oldtype = LIBC_CANCEL_ASYNC ();
- int result = do_readv (fd, vector, count);
+ result = INLINE_SYSCALL (readv, 3, fd, CHECK_N (vector, count), count);
- LIBC_CANCEL_RESET (oldtype);
+ LIBC_CANCEL_RESET (oldtype);
+ }
+#ifdef __ASSUME_COMPLETE_READV_WRITEV
return result;
+#else
+ if (result >= 0 || errno != EINVAL || count <= UIO_FASTIOV)
+ return result;
+
+ return __atomic_readv_replacement (fd, vector, count);
+#endif
}
strong_alias (__libc_readv, __readv)
weak_alias (__libc_readv, readv)
-#define __libc_readv static internal_function __atomic_readv_replacement
-#include <sysdeps/posix/readv.c>
+#ifndef __ASSUME_COMPLETE_READV_WRITEV
+# define __libc_readv static internal_function __atomic_readv_replacement
+# include <sysdeps/posix/readv.c>
+#endif
diff --git a/sysdeps/unix/sysv/linux/sys/eventfd.h b/sysdeps/unix/sysv/linux/sys/eventfd.h
index 7c6cf7196d..d942df4bf9 100644
--- a/sysdeps/unix/sysv/linux/sys/eventfd.h
+++ b/sysdeps/unix/sysv/linux/sys/eventfd.h
@@ -28,6 +28,8 @@ typedef uint64_t eventfd_t;
/* Flags for signalfd. */
enum
{
+ EFD_SEMAPHORE = 1,
+#define EFD_SEMAPHORE EFD_SEMAPHORE
EFD_CLOEXEC = 02000000,
#define EFD_CLOEXEC EFD_CLOEXEC
EFD_NONBLOCK = 04000
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/preadv64.c b/sysdeps/unix/sysv/linux/wordsize-64/preadv64.c
new file mode 100644
index 0000000000..fd9320cfc7
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/wordsize-64/preadv64.c
@@ -0,0 +1 @@
+/* Empty since the preadv syscall is equivalent. */
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/pwritev64.c b/sysdeps/unix/sysv/linux/wordsize-64/pwritev64.c
new file mode 100644
index 0000000000..8b72a2928b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/wordsize-64/pwritev64.c
@@ -0,0 +1 @@
+/* Empty since the pwritev syscall is equivalent. */
diff --git a/sysdeps/unix/sysv/linux/writev.c b/sysdeps/unix/sysv/linux/writev.c
index 05978665fa..55e915d34d 100644
--- a/sysdeps/unix/sysv/linux/writev.c
+++ b/sysdeps/unix/sysv/linux/writev.c
@@ -1,5 +1,5 @@
/* writev supports all Linux kernels >= 2.0.
- Copyright (C) 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1997,1998,2000,2002,2003,2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -25,6 +25,7 @@
#include <sysdep-cancel.h>
#include <sys/syscall.h>
#include <bp-checks.h>
+#include <kernel-features.h>
static ssize_t __atomic_writev_replacement (int, const struct iovec *,
int) internal_function;
@@ -36,40 +37,38 @@ static ssize_t __atomic_writev_replacement (int, const struct iovec *,
#endif
-/* We should deal with kernel which have a smaller UIO_FASTIOV as well
- as a very big count. */
-static ssize_t
-do_writev (int fd, const struct iovec *vector, int count)
-{
- ssize_t bytes_written;
-
- bytes_written = INLINE_SYSCALL (writev, 3, fd, CHECK_N (vector, count), count);
-
- if (bytes_written >= 0 || errno != EINVAL || count <= UIO_FASTIOV)
- return bytes_written;
-
- return __atomic_writev_replacement (fd, vector, count);
-}
-
ssize_t
__libc_writev (fd, vector, count)
int fd;
const struct iovec *vector;
int count;
{
- if (SINGLE_THREAD_P)
- return do_writev (fd, vector, count);
+ ssize_t result;
- int oldtype = LIBC_CANCEL_ASYNC ();
+ if (SINGLE_THREAD_P)
+ result = INLINE_SYSCALL (writev, 3, fd, CHECK_N (vector, count), count);
+ else
+ {
+ int oldtype = LIBC_CANCEL_ASYNC ();
- ssize_t result = do_writev (fd, vector, count);
+ result = INLINE_SYSCALL (writev, 3, fd, CHECK_N (vector, count), count);
- LIBC_CANCEL_RESET (oldtype);
+ LIBC_CANCEL_RESET (oldtype);
+ }
+#ifdef __ASSUME_COMPLETE_READV_WRITEV
return result;
+#else
+ if (result >= 0 || errno != EINVAL || count <= UIO_FASTIOV)
+ return result;
+
+ return __atomic_writev_replacement (fd, vector, count);
+#endif
}
strong_alias (__libc_writev, __writev)
weak_alias (__libc_writev, writev)
-#define __libc_writev static internal_function __atomic_writev_replacement
-#include <sysdeps/posix/writev.c>
+#ifndef __ASSUME_COMPLETE_READV_WRITEV
+# define __libc_writev static internal_function __atomic_writev_replacement
+# include <sysdeps/posix/writev.c>
+#endif
diff --git a/sysdeps/x86_64/strchr.S b/sysdeps/x86_64/strchr.S
index 8934697972..8833cd0cc4 100644
--- a/sysdeps/x86_64/strchr.S
+++ b/sysdeps/x86_64/strchr.S
@@ -1,6 +1,6 @@
/* strchr (str, ch) -- Return pointer to first occurrence of CH in STR.
For AMD x86-64.
- Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -19,273 +19,52 @@
02111-1307 USA. */
#include <sysdep.h>
-#include "asm-syntax.h"
-#include "bp-sym.h"
-#include "bp-asm.h"
.text
-ENTRY (BP_SYM (strchr))
-
- /* Before we start with the main loop we process single bytes
- until the source pointer is aligned. This has two reasons:
- 1. aligned 64-bit memory access is faster
- and (more important)
- 2. we process in the main loop 64 bit in one step although
- we don't know the end of the string. But accessing at
- 8-byte alignment guarantees that we never access illegal
- memory if this would not also be done by the trivial
- implementation (this is because all processor inherent
- boundaries are multiples of 8). */
-
- movq %rdi, %rdx
- andl $7, %edx /* Mask alignment bits */
- movq %rdi, %rax /* duplicate destination. */
- jz 1f /* aligned => start loop */
- neg %edx
- addl $8, %edx /* Align to 8 bytes. */
-
- /* Search the first bytes directly. */
-0: movb (%rax), %cl /* load byte */
- cmpb %cl,%sil /* compare byte. */
- je 6f /* target found */
- testb %cl,%cl /* is byte NUL? */
- je 7f /* yes => return NULL */
- incq %rax /* increment pointer */
- decl %edx
- jnz 0b
-
-
-1:
- /* At the moment %rsi contains C. What we need for the
- algorithm is C in all bytes of the register. Avoid
- operations on 16 bit words because these require an
- prefix byte (and one more cycle). */
- /* Populate 8 bit data to full 64-bit. */
- movabs $0x0101010101010101,%r9
- movzbl %sil,%edx
- imul %rdx,%r9
-
- movq $0xfefefefefefefeff, %r8 /* Save magic. */
-
- /* We exit the loop if adding MAGIC_BITS to LONGWORD fails to
- change any of the hole bits of LONGWORD.
-
- 1) Is this safe? Will it catch all the zero bytes?
- Suppose there is a byte with all zeros. Any carry bits
- propagating from its left will fall into the hole at its
- least significant bit and stop. Since there will be no
- carry from its most significant bit, the LSB of the
- byte to the left will be unchanged, and the zero will be
- detected.
-
- 2) Is this worthwhile? Will it ignore everything except
- zero bytes? Suppose every byte of QUARDWORD has a bit set
- somewhere. There will be a carry into bit 8. If bit 8
- is set, this will carry into bit 16. If bit 8 is clear,
- one of bits 9-15 must be set, so there will be a carry
- into bit 16. Similarly, there will be a carry into bit
- 24 tec.. If one of bits 54-63 is set, there will be a carry
- into bit 64 (=carry flag), so all of the hole bits will
- be changed.
-
- 3) But wait! Aren't we looking for C, not zero?
- Good point. So what we do is XOR LONGWORD with a longword,
- each of whose bytes is C. This turns each byte that is C
- into a zero. */
-
- .p2align 4
-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 */
- xorq %r9, %rcx /* XOR with qword c|...|c => bytes of str == c
- are now 0 */
- 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 c => return pointer */
-
- /* The quadword we looked at does not contain the value we're looking
- for. Let's search now whether we have reached the end of the
- string. */
- xorq %r9, %rcx /* restore original dword without reload */
- 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 7f /* highest byte is NUL => return NULL */
- 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 7f /* found NUL => return NULL */
-
- /* 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 */
- xorq %r9, %rcx /* XOR with qword c|...|c => bytes of str == c
- are now 0 */
- 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 c => return pointer */
-
- /* The quadword we looked at does not contain the value we're looking
- for. Let's search now whether we have reached the end of the
- string. */
- xorq %r9, %rcx /* restore original dword without reload */
- 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 7f /* highest byte is NUL => return NULL */
- 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 7f /* found NUL => return NULL */
- /* 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 */
- xorq %r9, %rcx /* XOR with qword c|...|c => bytes of str == c
- are now 0 */
- 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 c => return pointer */
-
- /* The quadword we looked at does not contain the value we're looking
- for. Let's search now whether we have reached the end of the
- string. */
- xorq %r9, %rcx /* restore original dword without reload */
- 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 7f /* highest byte is NUL => return NULL */
- 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 7f /* found NUL => return NULL */
- /* 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 */
- xorq %r9, %rcx /* XOR with qword c|...|c => bytes of str == c
- are now 0 */
- 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 c => return pointer */
-
- /* The quadword we looked at does not contain the value we're looking
- for. Let's search now whether we have reached the end of the
- string. */
- xorq %r9, %rcx /* restore original dword without reload */
- 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 7f /* highest byte is NUL => return NULL */
- 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 => restart loop */
-
-
-7: /* Return NULL. */
- xorl %eax, %eax
- retq
-
-
- /* We now scan for the byte in which the character was matched.
- But we have to take care of the case that a NUL char is
- found before this in the dword. Note that we XORed %rcx
- with the byte we're looking for, therefore the tests below look
- reversed. */
-
-
- .p2align 4 /* Align, it's a jump target. */
-3: movq %r9,%rdx /* move to %rdx so that we can access bytes */
- subq $8,%rax /* correct pointer increment. */
- testb %cl, %cl /* is first byte C? */
- jz 6f /* yes => return pointer */
- cmpb %dl, %cl /* is first byte NUL? */
- je 7b /* yes => return NULL */
- incq %rax /* increment pointer */
-
- testb %ch, %ch /* is second byte C? */
- jz 6f /* yes => return pointer */
- cmpb %dl, %ch /* is second byte NUL? */
- je 7b /* yes => return NULL? */
- incq %rax /* increment pointer */
-
- shrq $16, %rcx /* make upper bytes accessible */
- testb %cl, %cl /* is third byte C? */
- jz 6f /* yes => return pointer */
- cmpb %dl, %cl /* is third byte NUL? */
- je 7b /* yes => return NULL */
- incq %rax /* increment pointer */
-
- testb %ch, %ch /* is fourth byte C? */
- jz 6f /* yes => return pointer */
- cmpb %dl, %ch /* is fourth byte NUL? */
- je 7b /* yes => return NULL? */
- incq %rax /* increment pointer */
-
- shrq $16, %rcx /* make upper bytes accessible */
- testb %cl, %cl /* is fifth byte C? */
- jz 6f /* yes => return pointer */
- cmpb %dl, %cl /* is fifth byte NUL? */
- je 7b /* yes => return NULL */
- incq %rax /* increment pointer */
-
- testb %ch, %ch /* is sixth byte C? */
- jz 6f /* yes => return pointer */
- cmpb %dl, %ch /* is sixth byte NUL? */
- je 7b /* yes => return NULL? */
- incq %rax /* increment pointer */
-
- shrq $16, %rcx /* make upper bytes accessible */
- testb %cl, %cl /* is seventh byte C? */
- jz 6f /* yes => return pointer */
- cmpb %dl, %cl /* is seventh byte NUL? */
- je 7b /* yes => return NULL */
-
- /* It must be in the eigth byte and it cannot be NUL. */
- incq %rax
-
-6:
- nop
- retq
-END (BP_SYM (strchr))
-
-weak_alias (BP_SYM (strchr), BP_SYM (index))
+ENTRY (strchr)
+ movd %esi, %xmm1
+ movq %rdi, %rcx
+ punpcklbw %xmm1, %xmm1
+ andq $~15, %rdi
+ pxor %xmm2, %xmm2
+ punpcklbw %xmm1, %xmm1
+ orl $0xffffffff, %esi
+ movdqa (%rdi), %xmm0
+ pshufd $0, %xmm1, %xmm1
+ subq %rdi, %rcx
+ movdqa %xmm0, %xmm3
+ leaq 16(%rdi), %rdi
+ pcmpeqb %xmm1, %xmm0
+ pcmpeqb %xmm2, %xmm3
+ shl %cl, %esi
+ pmovmskb %xmm0, %edx
+ pmovmskb %xmm3, %ecx
+ andl %esi, %edx
+ andl %esi, %ecx
+ orl %edx, %ecx
+ jnz 1f
+
+2: movdqa (%rdi), %xmm0
+ leaq 16(%rdi), %rdi
+ movdqa %xmm0, %xmm3
+ pcmpeqb %xmm1, %xmm0
+ pcmpeqb %xmm2, %xmm3
+ pmovmskb %xmm0, %edx
+ pmovmskb %xmm3, %ecx
+ orl %edx, %ecx
+ jz 2b
+
+1: bsfl %edx, %edx
+ jz 4f
+ bsfl %ecx, %ecx
+ leaq -16(%rdi,%rdx), %rax
+ cmpl %edx, %ecx
+ je 5f
+4: xorl %eax, %eax
+5: ret
+END (strchr)
+
+weak_alias (strchr, index)
libc_hidden_builtin_def (strchr)
+
diff --git a/sysdeps/x86_64/strlen.S b/sysdeps/x86_64/strlen.S
index fd950edaaa..b83332c90c 100644
--- a/sysdeps/x86_64/strlen.S
+++ b/sysdeps/x86_64/strlen.S
@@ -1,6 +1,6 @@
/* strlen(str) -- determine the length of the string STR.
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
- Based on i486 version contributed by Ulrich Drepper <drepper@redhat.com>.
+ Copyright (C) 2009 Free Software Foundation, Inc.
+ Contributed by Ulrich Drepper <drepper@redhat.com>.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -19,121 +19,35 @@
02111-1307 USA. */
#include <sysdep.h>
-#include "asm-syntax.h"
-#include "bp-sym.h"
-#include "bp-asm.h"
- .text
-ENTRY (strlen)
- movq %rdi, %rcx /* Duplicate source pointer. */
- andl $7, %ecx /* mask alignment bits */
- movq %rdi, %rax /* duplicate destination. */
- jz 1f /* aligned => start loop */
-
- neg %ecx /* We need to align to 8 bytes. */
- addl $8,%ecx
- /* Search the first bytes directly. */
-0: cmpb $0x0,(%rax) /* is byte NUL? */
- je 2f /* yes => return */
- incq %rax /* increment pointer */
- decl %ecx
- jnz 0b
-
-1: movq $0xfefefefefefefeff,%r8 /* Save magic. */
-
- .p2align 4 /* Align loop. */
-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 */
+ENTRY(strlen)
+ movq %rdi, %rcx
+ movq %rdi, %r8
+ andq $~15, %rdi
+ pxor %xmm1, %xmm1
+ 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
+
+2: movdqa (%rdi), %xmm0
+ leaq 16(%rdi), %rdi
+ pcmpeqb %xmm1, %xmm0
+ pmovmskb %xmm0, %edx
+ testl %edx, %edx
+ jz 2b
+
+1: leaq -16(%rdi,%r8), %rdi
+ bsfl %edx, %eax
+ addq %rdi, %rax
ret
-END (strlen)
+END(strlen)
libc_hidden_builtin_def (strlen)