Skip to content

Commit

Permalink
S390: Optimize stpncpy and wcpncpy.
Browse files Browse the repository at this point in the history
This patch provides optimized versions of stpncpy and wcpncpy with the z13
vector instructions.

ChangeLog:

	* sysdeps/s390/multiarch/stpncpy-c.c: New File.
	* sysdeps/s390/multiarch/stpncpy-vx.S: Likewise.
	* sysdeps/s390/multiarch/stpncpy.c: Likewise.
	* sysdeps/s390/multiarch/wcpncpy-c.c: Likewise.
	* sysdeps/s390/multiarch/wcpncpy-vx.S: Likewise.
	* sysdeps/s390/multiarch/wcpncpy.c: Likewise.
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add stpncpy and
	wcpncpy functions.
	* sysdeps/s390/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Add ifunc test for stpncpy, wcpncpy.
	* wcsmbs/wcpncpy.c: Use WCPNCPY if defined.
	* string/test-stpncpy.c: Add wcpncpy support.
	* wcsmbs/test-wcpncpy.c: New File.
	* wcsmbs/Makefile (strop-tests): Add wcpncpy.
	* benchtests/bench-stpncpy.c: Add wcpncpy support.
	* benchtests/bench-wcpncpy.c: New File.
	* benchtests/Makefile (wcsmbs-bench): Add wcpncpy.
  • Loading branch information
Stefan Liebler authored and Andreas Krebbel committed Aug 26, 2015
1 parent d183b96 commit b3a0c17
Show file tree
Hide file tree
Showing 16 changed files with 665 additions and 26 deletions.
20 changes: 20 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
2015-08-26 Stefan Liebler <stli@linux.vnet.ibm.com>

* sysdeps/s390/multiarch/stpncpy-c.c: New File.
* sysdeps/s390/multiarch/stpncpy-vx.S: Likewise.
* sysdeps/s390/multiarch/stpncpy.c: Likewise.
* sysdeps/s390/multiarch/wcpncpy-c.c: Likewise.
* sysdeps/s390/multiarch/wcpncpy-vx.S: Likewise.
* sysdeps/s390/multiarch/wcpncpy.c: Likewise.
* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add stpncpy and
wcpncpy functions.
* sysdeps/s390/multiarch/ifunc-impl-list.c
(__libc_ifunc_impl_list): Add ifunc test for stpncpy, wcpncpy.
* wcsmbs/wcpncpy.c: Use WCPNCPY if defined.
* string/test-stpncpy.c: Add wcpncpy support.
* wcsmbs/test-wcpncpy.c: New File.
* wcsmbs/Makefile (strop-tests): Add wcpncpy.
* benchtests/bench-stpncpy.c: Add wcpncpy support.
* benchtests/bench-wcpncpy.c: New File.
* benchtests/Makefile (wcsmbs-bench): Add wcpncpy.

2015-08-26 Stefan Liebler <stli@linux.vnet.ibm.com>

* sysdeps/s390/multiarch/strncpy-vx.S: New File.
Expand Down
2 changes: 1 addition & 1 deletion benchtests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \
strcoll
wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy
wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy
string-bench-all := $(string-bench) ${wcsmbs-bench}

# We have to generate locales
Expand Down
41 changes: 30 additions & 11 deletions benchtests/bench-stpncpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,36 @@

#define STRNCPY_RESULT(dst, len, n) ((dst) + ((len) > (n) ? (n) : (len)))
#define TEST_MAIN
#define TEST_NAME "stpncpy"
#ifndef WIDE
# define TEST_NAME "stpncpy"
#else
# define TEST_NAME "wcpncpy"
#endif /* WIDE */
#include "bench-string.h"
#ifndef WIDE
# define CHAR char
# define SIMPLE_STPNCPY simple_stpncpy
# define STUPID_STPNCPY stupid_stpncpy
# define STPNCPY stpncpy
# define STRNLEN strnlen
#else
# include <wchar.h>
# define CHAR wchar_t
# define SIMPLE_STPNCPY simple_wcpncpy
# define STUPID_STPNCPY stupid_wcpncpy
# define STPNCPY wcpncpy
# define STRNLEN wcsnlen
#endif /* WIDE */

char *simple_stpncpy (char *, const char *, size_t);
char *stupid_stpncpy (char *, const char *, size_t);
CHAR *SIMPLE_STPNCPY (CHAR *, const CHAR *, size_t);
CHAR *STUPID_STPNCPY (CHAR *, const CHAR *, size_t);

IMPL (stupid_stpncpy, 0)
IMPL (simple_stpncpy, 0)
IMPL (stpncpy, 1)
IMPL (STUPID_STPNCPY, 0)
IMPL (SIMPLE_STPNCPY, 0)
IMPL (STPNCPY, 1)

char *
simple_stpncpy (char *dst, const char *src, size_t n)
CHAR *
SIMPLE_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
{
while (n--)
if ((*dst++ = *src++) == '\0')
Expand All @@ -43,10 +61,10 @@ simple_stpncpy (char *dst, const char *src, size_t n)
return dst;
}

char *
stupid_stpncpy (char *dst, const char *src, size_t n)
CHAR *
STUPID_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
{
size_t nc = strnlen (src, n);
size_t nc = STRNLEN (src, n);
size_t i;

for (i = 0; i < nc; ++i)
Expand All @@ -56,4 +74,5 @@ stupid_stpncpy (char *dst, const char *src, size_t n)
return dst + nc;
}

#undef CHAR
#include "bench-strncpy.c"
20 changes: 20 additions & 0 deletions benchtests/bench-wcpncpy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Measure wcpncpy functions.
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 WIDE 1
#include "bench-stpncpy.c"
41 changes: 30 additions & 11 deletions string/test-stpncpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,36 @@

#define STRNCPY_RESULT(dst, len, n) ((dst) + ((len) > (n) ? (n) : (len)))
#define TEST_MAIN
#define TEST_NAME "stpncpy"
#ifndef WIDE
# define TEST_NAME "stpncpy"
#else
# define TEST_NAME "wcpncpy"
#endif /* WIDE */
#include "test-string.h"
#ifndef WIDE
# define CHAR char
# define SIMPLE_STPNCPY simple_stpncpy
# define STUPID_STPNCPY stupid_stpncpy
# define STPNCPY stpncpy
# define STRNLEN strnlen
#else
# include <wchar.h>
# define CHAR wchar_t
# define SIMPLE_STPNCPY simple_wcpncpy
# define STUPID_STPNCPY stupid_wcpncpy
# define STPNCPY wcpncpy
# define STRNLEN wcsnlen
#endif /* WIDE */

char *simple_stpncpy (char *, const char *, size_t);
char *stupid_stpncpy (char *, const char *, size_t);
CHAR *SIMPLE_STPNCPY (CHAR *, const CHAR *, size_t);
CHAR *STUPID_STPNCPY (CHAR *, const CHAR *, size_t);

IMPL (stupid_stpncpy, 0)
IMPL (simple_stpncpy, 0)
IMPL (stpncpy, 1)
IMPL (STUPID_STPNCPY, 0)
IMPL (SIMPLE_STPNCPY, 0)
IMPL (STPNCPY, 1)

char *
simple_stpncpy (char *dst, const char *src, size_t n)
CHAR *
SIMPLE_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
{
while (n--)
if ((*dst++ = *src++) == '\0')
Expand All @@ -44,10 +62,10 @@ simple_stpncpy (char *dst, const char *src, size_t n)
return dst;
}

char *
stupid_stpncpy (char *dst, const char *src, size_t n)
CHAR *
STUPID_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
{
size_t nc = strnlen (src, n);
size_t nc = STRNLEN (src, n);
size_t i;

for (i = 0; i < nc; ++i)
Expand All @@ -57,4 +75,5 @@ stupid_stpncpy (char *dst, const char *src, size_t n)
return dst + nc;
}

#undef CHAR
#include "test-strncpy.c"
6 changes: 4 additions & 2 deletions sysdeps/s390/multiarch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ sysdep_routines += strlen strlen-vx strlen-c \
strnlen strnlen-vx strnlen-c \
strcpy strcpy-vx \
stpcpy stpcpy-vx stpcpy-c \
strncpy strncpy-vx
strncpy strncpy-vx \
stpncpy stpncpy-vx stpncpy-c
endif

ifeq ($(subdir),wcsmbs)
sysdep_routines += wcslen wcslen-vx wcslen-c \
wcsnlen wcsnlen-vx wcsnlen-c \
wcscpy wcscpy-vx wcscpy-c \
wcpcpy wcpcpy-vx wcpcpy-c \
wcsncpy wcsncpy-vx wcsncpy-c
wcsncpy wcsncpy-vx wcsncpy-c \
wcpncpy wcpncpy-vx wcpncpy-c
endif
3 changes: 3 additions & 0 deletions sysdeps/s390/multiarch/ifunc-impl-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
IFUNC_VX_IMPL (strncpy);
IFUNC_VX_IMPL (wcsncpy);

IFUNC_VX_IMPL (stpncpy);
IFUNC_VX_IMPL (wcpncpy);

#endif /* HAVE_S390_VX_ASM_SUPPORT */

return i;
Expand Down
28 changes: 28 additions & 0 deletions sysdeps/s390/multiarch/stpncpy-c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Default stpncpy implementation for S/390.
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/>. */

#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
# define STPNCPY __stpncpy_c
# ifdef SHARED
# undef libc_hidden_def
# define libc_hidden_def(name) \
__hidden_ver1 (__stpncpy_c, __GI___stpncpy, __stpncpy_c);
# endif /* SHARED */

# include <string/stpncpy.c>
#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
Loading

0 comments on commit b3a0c17

Please sign in to comment.