2024-01-01 18:12:26 +00:00
|
|
|
/* Copyright (C) 1992-2024 Free Software Foundation, Inc.
|
1997-06-23 21:55:26 +00:00
|
|
|
This file is part of the GNU C Library.
|
1995-02-18 01:27:10 +00:00
|
|
|
|
1997-06-23 21:55:26 +00:00
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
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.
|
1995-02-18 01:27:10 +00:00
|
|
|
|
1997-06-23 21:55:26 +00:00
|
|
|
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
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1995-02-18 01:27:10 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
1995-02-18 01:27:10 +00:00
|
|
|
|
2014-11-14 13:48:39 +00:00
|
|
|
#define NO_MEMPCPY_STPCPY_REDIRECT
|
1995-02-18 01:27:10 +00:00
|
|
|
#include <string.h>
|
string: Improve generic stpcpy
It follows the strategy:
- Align the destination on word boundary using byte operations.
- If source is also word aligned, read a word per time, check for
null (using has_zero from string-fzb.h), and write the remaining
bytes.
- If source is not word aligned, loop by aligning the source, and
merging the result of two reads. Similar to aligned case,
check for null with has_zero, and write the remaining bytes if
null is found.
Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu,
and powerpc-linux-gnu by removing the arch-specific assembly
implementation and disabling multi-arch (it covers both LE and BE
for 64 and 32 bits).
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
2023-01-31 18:46:08 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <memcopy.h>
|
|
|
|
#include <string-fzb.h>
|
|
|
|
#include <string-misc.h>
|
1995-02-18 01:27:10 +00:00
|
|
|
|
1997-09-16 00:42:43 +00:00
|
|
|
#undef __stpcpy
|
|
|
|
#undef stpcpy
|
|
|
|
|
2015-07-28 20:12:25 +00:00
|
|
|
#ifndef STPCPY
|
|
|
|
# define STPCPY __stpcpy
|
1997-08-20 03:53:21 +00:00
|
|
|
#endif
|
|
|
|
|
string: Improve generic stpcpy
It follows the strategy:
- Align the destination on word boundary using byte operations.
- If source is also word aligned, read a word per time, check for
null (using has_zero from string-fzb.h), and write the remaining
bytes.
- If source is not word aligned, loop by aligning the source, and
merging the result of two reads. Similar to aligned case,
check for null with has_zero, and write the remaining bytes if
null is found.
Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu,
and powerpc-linux-gnu by removing the arch-specific assembly
implementation and disabling multi-arch (it covers both LE and BE
for 64 and 32 bits).
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
2023-01-31 18:46:08 +00:00
|
|
|
static __always_inline char *
|
|
|
|
write_byte_from_word (op_t *dest, op_t word)
|
|
|
|
{
|
|
|
|
char *d = (char *) dest;
|
|
|
|
for (size_t i = 0; i < OPSIZ; i++, ++d)
|
|
|
|
{
|
|
|
|
char c = extractbyte (word, i);
|
|
|
|
*d = c;
|
|
|
|
if (c == '\0')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline char *
|
|
|
|
stpcpy_aligned_loop (op_t *restrict dst, const op_t *restrict src)
|
|
|
|
{
|
|
|
|
op_t word;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
word = *src++;
|
|
|
|
if (has_zero (word))
|
|
|
|
break;
|
|
|
|
*dst++ = word;
|
|
|
|
}
|
|
|
|
|
|
|
|
return write_byte_from_word (dst, word);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __always_inline char *
|
|
|
|
stpcpy_unaligned_loop (op_t *restrict dst, const op_t *restrict src,
|
|
|
|
uintptr_t ofs)
|
|
|
|
{
|
|
|
|
op_t w2a = *src++;
|
|
|
|
uintptr_t sh_1 = ofs * CHAR_BIT;
|
|
|
|
uintptr_t sh_2 = OPSIZ * CHAR_BIT - sh_1;
|
|
|
|
|
|
|
|
op_t w2 = MERGE (w2a, sh_1, (op_t)-1, sh_2);
|
|
|
|
if (!has_zero (w2))
|
|
|
|
{
|
|
|
|
op_t w2b;
|
|
|
|
|
|
|
|
/* Unaligned loop. The invariant is that W2B, which is "ahead" of W1,
|
|
|
|
does not contain end-of-string. Therefore it is safe (and necessary)
|
|
|
|
to read another word from each while we do not have a difference. */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
w2b = *src++;
|
|
|
|
w2 = MERGE (w2a, sh_1, w2b, sh_2);
|
|
|
|
/* Check if there is zero on w2a. */
|
|
|
|
if (has_zero (w2))
|
|
|
|
goto out;
|
|
|
|
*dst++ = w2;
|
|
|
|
if (has_zero (w2b))
|
|
|
|
break;
|
|
|
|
w2a = w2b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Align the final partial of P2. */
|
|
|
|
w2 = MERGE (w2b, sh_1, 0, sh_2);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return write_byte_from_word (dst, w2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-02-18 01:27:10 +00:00
|
|
|
/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
|
|
|
|
char *
|
2015-07-28 20:12:25 +00:00
|
|
|
STPCPY (char *dest, const char *src)
|
1995-02-18 01:27:10 +00:00
|
|
|
{
|
string: Improve generic stpcpy
It follows the strategy:
- Align the destination on word boundary using byte operations.
- If source is also word aligned, read a word per time, check for
null (using has_zero from string-fzb.h), and write the remaining
bytes.
- If source is not word aligned, loop by aligning the source, and
merging the result of two reads. Similar to aligned case,
check for null with has_zero, and write the remaining bytes if
null is found.
Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64-linux-gnu,
and powerpc-linux-gnu by removing the arch-specific assembly
implementation and disabling multi-arch (it covers both LE and BE
for 64 and 32 bits).
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
2023-01-31 18:46:08 +00:00
|
|
|
/* Copy just a few bytes to make DEST aligned. */
|
|
|
|
size_t len = (-(uintptr_t) dest) % OPSIZ;
|
|
|
|
for (; len != 0; len--, ++dest)
|
|
|
|
{
|
|
|
|
char c = *src++;
|
|
|
|
*dest = c;
|
|
|
|
if (c == '\0')
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DEST is now aligned to op_t, SRC may or may not be. */
|
|
|
|
uintptr_t ofs = (uintptr_t) src % OPSIZ;
|
|
|
|
return ofs == 0 ? stpcpy_aligned_loop ((op_t*) dest, (const op_t *) src)
|
|
|
|
: stpcpy_unaligned_loop ((op_t*) dest,
|
|
|
|
(const op_t *) (src - ofs) , ofs);
|
1995-02-18 01:27:10 +00:00
|
|
|
}
|
1995-09-28 09:00:19 +00:00
|
|
|
weak_alias (__stpcpy, stpcpy)
|
2015-07-28 20:12:25 +00:00
|
|
|
libc_hidden_def (__stpcpy)
|
Update.
2004-05-27 Jakub Jelinek <jakub@redhat.com>
* sysdeps/i386/fpu/bits/mathinline.h (__expm1_code): Define using
__builtin_expm1l for GCC 3.5+.
(__expl): Define using __builtin_expl for GCC 3.4+.
(exp, expf, expl): Don't define for GCC 3.4+.
(tan, tanf, tanl): Don't define for GCC 3.5+.
(__atan2l): Define using __builtin_atan2l for GCC 3.4+.
(atan2, atan2f, atan2l): Don't define for GCC 3.4+ or !__FAST_MATH__.
(fmod, fmodf, fmodl): Don't define for GCC 3.5+ or !__FAST_MATH__.
(fabsf, fabsl): Only provide if __USE_MISC or __USE_ISOC99.
(sin, sinf, sinl, cos, cosf, cosl, log, logf, logl): Don't define
for GCC 3.4+.
(log10, log10f, log10l, asin, asinf, asinl, acos, acosf, acosl):
Don't define for GCC 3.5+.
(atan, atanf, atanl): Don't define for GCC 3.4+ or !__FAST_MATH__.
(log1p, log1pf, log1pl, logb, logbf, logbl, log2, log2f, log2l): Don't
define for GCC 3.5+.
(drem, dremf, dreml): Don't define for GCC 3.5+ or !__FAST_MATH__.
* sysdeps/sparc/fpu/bits/mathinline.h (sqrt, sqrtf, sqrtl): Don't
define for GCC 3.2+.
2004-05-27 Jakub Jelinek <jakub@redhat.com>
* string/bits/string2.h (__bzero): Define even for GCC 3.0+.
* sysdeps/alpha/stpcpy.S (stpcpy): Add libc_hidden_builtin_def.
* sysdeps/alpha/alphaev67/stpcpy.S (stpcpy): Likewise.
* sysdeps/powerpc/powerpc32/stpcpy.S (stpcpy): Likewise.
* sysdeps/powerpc/powerpc64/stpcpy.S (stpcpy): Likewise.
* sysdeps/sparc/sparc32/stpcpy.S (stpcpy): Likewise.
* sysdeps/sparc/sparc64/stpcpy.S (stpcpy): Likewise.
* sysdeps/i386/stpcpy.S (stpcpy): Likewise.
* sysdeps/i386/i586/stpcpy.S (stpcpy): Likewise.
* sysdeps/generic/stpcpy.c (stpcpy): Likewise.
* sysdeps/x86_64/stpcpy.S (stpcpy): Likewise.
* sysdeps/i386/i586/memcpy.S (memcpy): Remove
libc_hidden_builtin_def if MEMPCPY_P.
* sysdeps/x86_64/memcpy.S (memcpy): Likewise.
* sysdeps/i386/i686/mempcpy.S (mempcpy): Add libc_hidden_builtin_def.
* sysdeps/i386/i586/mempcpy.S (mempcpy): Likewise.
* sysdeps/generic/mempcpy.c (mempcpy): Likewise.
* sysdeps/x86_64/mempcpy.S (mempcpy): Likewise.
2004-05-28 06:56:51 +00:00
|
|
|
libc_hidden_builtin_def (stpcpy)
|