Skip to content

Commit

Permalink
powerpc: Optimized st{r,p}cpy for POWER8/PPC64
Browse files Browse the repository at this point in the history
This patch adds an optimized POWER8 strcpy using unaligned accesses.
For strings up to 16 bytes the implementation first calculate the
string size, like strlen, and issues a memcpy.  For larger strings,
source is first aligned to 16 bytes and then tested over a loop that
reads 16 bytes am combine the cmpb results for speedup.  Special case is
added for page cross reads.

It shows 30%-60% improvement over the optimized POWER7 one that uses
only aligned accesses.
  • Loading branch information
Adhemerval Zanella committed Jan 13, 2015
1 parent 0f9e585 commit 96d6fd6
Show file tree
Hide file tree
Showing 9 changed files with 398 additions and 3 deletions.
19 changes: 19 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
2015-01-13 Adhemerval Zanella <azanella@linux.vnet.ibm.com>

* sysdeps/powerpc/powerpc64/multiarch/Makefile [sysdep_routines]: Add
strcpy-power8 and stpcpy-power8 objects.
* sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
(__libc_ifunc_impl_list): Add __strcpy_power8 and __stpcpy_power8
implementations.
* sysdeps/powerpc/powerpc64/multiarch/stpcpy-power8.S: New file:
multiarch stpcpy implementation for POWER8.
* sysdeps/powerpc/powerpc64/multiarch/strcpy-power8.S: New file;
multiarch strcpy implementation for POWER8.
* sysdeps/powerpc/powerpc64/multiarch/strcpy.c (strcpy): Add
__strcpy_power8 function.
* sysdeps/powerpc/powerpc64/power8/stpcpy.S: New file: optimized
stpcpy for POWER8.
* sysdeps/powerpc/powerpc64/power8/strcpy.S: New file: optimized
strcpy for POWER8.
* NEWS: Update.

2015-01-13 Leonhard Holz <leonhard.holz@web.de>

[BZ #16009]
Expand Down
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Version 2.21
17744, 17745, 17746, 17747, 17748, 17775, 17777, 17780, 17781, 17782,
17791, 17793, 17796, 17797, 17803, 17806, 17834

* Optimized strcpy and stpcpy implementations for powerpc64/powerpc64le.

* Added support for TSX lock elision of pthread mutexes on powerpc32, powerpc64
and powerpc64le. This may improve lock scaling of existing programs on
HTM capable systems. The lock elision code is only enabled with
Expand Down
3 changes: 2 additions & 1 deletion sysdeps/powerpc/powerpc64/multiarch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ sysdep_routines += memcpy-power7 memcpy-a2 memcpy-power6 memcpy-cell \
wcschr-power6 wcschr-ppc64 wcsrchr-power7 wcsrchr-power6 \
wcsrchr-ppc64 wcscpy-power7 wcscpy-power6 wcscpy-ppc64 \
wordcopy-power7 wordcopy-power6 wordcopy-ppc64 \
strcpy-power7 strcpy-ppc64 stpcpy-power7 stpcpy-ppc64 \
strcpy-power8 strcpy-power7 strcpy-ppc64 stpcpy-power8 \
stpcpy-power7 stpcpy-ppc64 \
strrchr-power7 strrchr-ppc64 strncat-power7 strncat-ppc64 \
strncpy-power7 strncpy-ppc64 \
stpncpy-power7 stpncpy-ppc64 strcmp-power7 strcmp-ppc64 \
Expand Down
4 changes: 4 additions & 0 deletions sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,

/* Support sysdeps/powerpc/powerpc64/multiarch/strcpy.c. */
IFUNC_IMPL (i, name, strcpy,
IFUNC_IMPL_ADD (array, i, strcpy, hwcap2 & PPC_FEATURE2_ARCH_2_07,
__strcpy_power8)
IFUNC_IMPL_ADD (array, i, strcpy, hwcap & PPC_FEATURE_HAS_VSX,
__strcpy_power7)
IFUNC_IMPL_ADD (array, i, strcpy, 1,
__strcpy_ppc))

/* Support sysdeps/powerpc/powerpc64/multiarch/stpcpy.c. */
IFUNC_IMPL (i, name, stpcpy,
IFUNC_IMPL_ADD (array, i, stpcpy, hwcap2 & PPC_FEATURE2_ARCH_2_07,
__stpcpy_power8)
IFUNC_IMPL_ADD (array, i, stpcpy, hwcap & PPC_FEATURE_HAS_VSX,
__stpcpy_power7)
IFUNC_IMPL_ADD (array, i, stpcpy, 1,
Expand Down
40 changes: 40 additions & 0 deletions sysdeps/powerpc/powerpc64/multiarch/stpcpy-power8.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Optimized stpcpy implementation for POWER8/PPC64.
Copyright (C) 2015 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, see
<http://www.gnu.org/licenses/>. */

#include <sysdep.h>

#undef EALIGN
#define EALIGN(name, alignt, words) \
.section ".text"; \
ENTRY_2(__stpcpy_power8) \
.align ALIGNARG(alignt); \
EALIGN_W_##words; \
BODY_LABEL(__stpcpy_power8): \
cfi_startproc; \
LOCALENTRY(__stpcpy_power8)

#undef END
#define END(name) \
cfi_endproc; \
TRACEBACK(__stpcpy_power8) \
END_2(__stpcpy_power8)

#undef libc_hidden_builtin_def
#define libc_hidden_builtin_def(name)

#include <sysdeps/powerpc/powerpc64/power8/stpcpy.S>
40 changes: 40 additions & 0 deletions sysdeps/powerpc/powerpc64/multiarch/strcpy-power8.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Optimized strcpy implementation for POWER8/PPC64.
Copyright (C) 2015 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, see
<http://www.gnu.org/licenses/>. */

#include <sysdep.h>

#undef EALIGN
#define EALIGN(name, alignt, words) \
.section ".text"; \
ENTRY_2(__strcpy_power8) \
.align ALIGNARG(alignt); \
EALIGN_W_##words; \
BODY_LABEL(__strcpy_power8): \
cfi_startproc; \
LOCALENTRY(__strcpy_power8)

#undef END
#define END(name) \
cfi_endproc; \
TRACEBACK(__strcpy_power8) \
END_2(__strcpy_power8)

#undef libc_hidden_builtin_def
#define libc_hidden_builtin_def(name)

#include <sysdeps/powerpc/powerpc64/power8/strcpy.S>
7 changes: 5 additions & 2 deletions sysdeps/powerpc/powerpc64/multiarch/strcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@

extern __typeof (strcpy) __strcpy_ppc attribute_hidden;
extern __typeof (strcpy) __strcpy_power7 attribute_hidden;
extern __typeof (strcpy) __strcpy_power8 attribute_hidden;

libc_ifunc (strcpy,
(hwcap & PPC_FEATURE_HAS_VSX)
? __strcpy_power7
(hwcap2 & PPC_FEATURE2_ARCH_2_07)
? __strcpy_power8 :
(hwcap & PPC_FEATURE_HAS_VSX)
? __strcpy_power7
: __strcpy_ppc);
#endif
24 changes: 24 additions & 0 deletions sysdeps/powerpc/powerpc64/power8/stpcpy.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Optimized stpcpy implementation for PowerPC64/POWER8.
Copyright (C) 2015 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, see
<http://www.gnu.org/licenses/>. */

#define USE_AS_STPCPY
#include <sysdeps/powerpc/powerpc64/power8/strcpy.S>

weak_alias (__stpcpy, stpcpy)
libc_hidden_def (__stpcpy)
libc_hidden_builtin_def (stpcpy)
Loading

0 comments on commit 96d6fd6

Please sign in to comment.