arrfab / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone
Blob Blame History Raw
From 6be435ec4f615266351487da396333f3ff026c03 Mon Sep 17 00:00:00 2001
From: Stefan Liebler <stli@linux.vnet.ibm.com>
Date: Thu, 8 Oct 2015 13:02:41 +0200
Subject: [PATCH 25/30] S390: Optimize strcspn and wcscspn.

upstream-commit-id: b4c21601b147efc3c2b0e679e4ffc554b3987f0b
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00099.html

This patch provides optimized versions of strcspn and wcscspn with the z13
vector instructions.

ChangeLog:

	* sysdeps/s390/multiarch/strcspn-c.c: New File.
	* sysdeps/s390/multiarch/strcspn-vx.S: Likewise.
	* sysdeps/s390/multiarch/strcspn.c: Likewise.
	* sysdeps/s390/multiarch/wcscspn-c.c: Likewise.
	* sysdeps/s390/multiarch/wcscspn-vx.S: Likewise.
	* sysdeps/s390/multiarch/wcscspn.c: Likewise.
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add strcspn and
	wcscspn functions.
	* sysdeps/s390/multiarch/ifunc-impl-list.c
	(__libc_ifunc_impl_list): Add ifunc test for strcspn, wcscspn.
	* wcsmbs/wcscspn.c: Use WCSCSPN if defined.
	* string/test-strcspn.c: Add wcscspn support.
	* wcsmbs/test-wcscspn.c: New File.
	* wcsmbs/Makefile (strop-tests): Add wcscspn.
	* benchtests/bench-strcspn.c: Add wcscspn support.
	* benchtests/bench-wcscspn.c: New File.
	* benchtests/Makefile (wcsmbs-bench): Add wcscspn.
---
 benchtests/Makefile                      |   2 +-
 benchtests/bench-strcspn.c               |  45 +++--
 benchtests/bench-wcscspn.c               |  20 +++
 string/strcspn.c                         |   8 +-
 string/test-strcspn.c                    |  45 +++--
 sysdeps/s390/multiarch/Makefile          |   6 +-
 sysdeps/s390/multiarch/ifunc-impl-list.c |   3 +
 sysdeps/s390/multiarch/strcspn-c.c       |  28 +++
 sysdeps/s390/multiarch/strcspn-vx.S      | 281 +++++++++++++++++++++++++++++
 sysdeps/s390/multiarch/strcspn.c         |  27 +++
 sysdeps/s390/multiarch/wcscspn-c.c       |  26 +++
 sysdeps/s390/multiarch/wcscspn-vx.S      | 293 +++++++++++++++++++++++++++++++
 sysdeps/s390/multiarch/wcscspn.c         |  27 +++
 wcsmbs/Makefile                          |   3 +-
 wcsmbs/test-wcscspn-ifunc.c              |  20 +++
 wcsmbs/test-wcscspn.c                    |  20 +++
 wcsmbs/wcscspn.c                         |   3 +
 17 files changed, 826 insertions(+), 31 deletions(-)
 create mode 100644 benchtests/bench-wcscspn.c
 create mode 100644 sysdeps/s390/multiarch/strcspn-c.c
 create mode 100644 sysdeps/s390/multiarch/strcspn-vx.S
 create mode 100644 sysdeps/s390/multiarch/strcspn.c
 create mode 100644 sysdeps/s390/multiarch/wcscspn-c.c
 create mode 100644 sysdeps/s390/multiarch/wcscspn-vx.S
 create mode 100644 sysdeps/s390/multiarch/wcscspn.c
 create mode 100644 wcsmbs/test-wcscspn-ifunc.c
 create mode 100644 wcsmbs/test-wcscspn.c

diff --git a/benchtests/Makefile b/benchtests/Makefile
index 015b5d6..4e811a9 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -39,7 +39,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
 wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
-		wcsncmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk
+		wcsncmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn
 string-bench-all := $(string-bench) ${wcsmbs-bench}
 
 stdlib-bench := strtod
diff --git a/benchtests/bench-strcspn.c b/benchtests/bench-strcspn.c
index 22b3b84..25de640 100644
--- a/benchtests/bench-strcspn.c
+++ b/benchtests/bench-strcspn.c
@@ -19,22 +19,41 @@
 #define STRPBRK_RESULT(s, pos) (pos)
 #define RES_TYPE size_t
 #define TEST_MAIN
-#define TEST_NAME "strcspn"
+#ifndef WIDE
+# define TEST_NAME "strcspn"
+#else
+# define TEST_NAME "wcscspn"
+#endif /* WIDE */
 #include "bench-string.h"
 
-typedef size_t (*proto_t) (const char *, const char *);
-size_t simple_strcspn (const char *, const char *);
-size_t stupid_strcspn (const char *, const char *);
+#ifndef WIDE
+# define STRCSPN strcspn
+# define CHAR char
+# define SIMPLE_STRCSPN simple_strcspn
+# define STUPID_STRCSPN stupid_strcspn
+# define STRLEN strlen
+#else
+# include <wchar.h>
+# define STRCSPN wcscspn
+# define CHAR wchar_t
+# define SIMPLE_STRCSPN simple_wcscspn
+# define STUPID_STRCSPN stupid_wcscspn
+# define STRLEN wcslen
+#endif /* WIDE */
 
-IMPL (stupid_strcspn, 0)
-IMPL (simple_strcspn, 0)
-IMPL (strcspn, 1)
+typedef size_t (*proto_t) (const CHAR *, const CHAR *);
+size_t SIMPLE_STRCSPN (const CHAR *, const CHAR *);
+size_t STUPID_STRCSPN (const CHAR *, const CHAR *);
+
+IMPL (STUPID_STRCSPN, 0)
+IMPL (SIMPLE_STRCSPN, 0)
+IMPL (STRCSPN, 1)
 
 size_t
-simple_strcspn (const char *s, const char *rej)
+SIMPLE_STRCSPN (const CHAR *s, const CHAR *rej)
 {
-  const char *r, *str = s;
-  char c;
+  const CHAR *r, *str = s;
+  CHAR c;
 
   while ((c = *s++) != '\0')
     for (r = rej; *r != '\0'; ++r)
@@ -44,9 +63,9 @@ simple_strcspn (const char *s, const char *rej)
 }
 
 size_t
-stupid_strcspn (const char *s, const char *rej)
+STUPID_STRCSPN (const CHAR *s, const CHAR *rej)
 {
-  size_t ns = strlen (s), nrej = strlen (rej);
+  size_t ns = STRLEN (s), nrej = STRLEN (rej);
   size_t i, j;
 
   for (i = 0; i < ns; ++i)
@@ -56,4 +75,6 @@ stupid_strcspn (const char *s, const char *rej)
   return i;
 }
 
+#undef CHAR
+#undef STRLEN
 #include "bench-strpbrk.c"
diff --git a/benchtests/bench-wcscspn.c b/benchtests/bench-wcscspn.c
new file mode 100644
index 0000000..3991951
--- /dev/null
+++ b/benchtests/bench-wcscspn.c
@@ -0,0 +1,20 @@
+/* Measure wcscspn 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-strcspn.c"
diff --git a/string/strcspn.c b/string/strcspn.c
index 6290429..0c750a8 100644
--- a/string/strcspn.c
+++ b/string/strcspn.c
@@ -30,12 +30,14 @@
 
 #undef strcspn
 
+#ifndef STRCSPN
+# define STRCSPN strcspn
+#endif
+
 /* Return the length of the maximum initial segment of S
    which contains no characters from REJECT.  */
 size_t
-strcspn (s, reject)
-     const char *s;
-     const char *reject;
+STRCSPN (const char *s, const char *reject)
 {
   size_t count = 0;
 
diff --git a/string/test-strcspn.c b/string/test-strcspn.c
index e2863c7..3443425 100644
--- a/string/test-strcspn.c
+++ b/string/test-strcspn.c
@@ -20,22 +20,41 @@
 #define STRPBRK_RESULT(s, pos) (pos)
 #define RES_TYPE size_t
 #define TEST_MAIN
-#define TEST_NAME "strcspn"
+#ifndef WIDE
+# define TEST_NAME "strcspn"
+#else
+# define TEST_NAME "wcscspn"
+#endif /* WIDE */
 #include "test-string.h"
 
-typedef size_t (*proto_t) (const char *, const char *);
-size_t simple_strcspn (const char *, const char *);
-size_t stupid_strcspn (const char *, const char *);
+#ifndef WIDE
+# define STRCSPN strcspn
+# define CHAR char
+# define SIMPLE_STRCSPN simple_strcspn
+# define STUPID_STRCSPN stupid_strcspn
+# define STRLEN strlen
+#else
+# include <wchar.h>
+# define STRCSPN wcscspn
+# define CHAR wchar_t
+# define SIMPLE_STRCSPN simple_wcscspn
+# define STUPID_STRCSPN stupid_wcscspn
+# define STRLEN wcslen
+#endif /* WIDE */
 
-IMPL (stupid_strcspn, 0)
-IMPL (simple_strcspn, 0)
-IMPL (strcspn, 1)
+typedef size_t (*proto_t) (const CHAR *, const CHAR *);
+size_t SIMPLE_STRCSPN (const CHAR *, const CHAR *);
+size_t STUPID_STRCSPN (const CHAR *, const CHAR *);
+
+IMPL (STUPID_STRCSPN, 0)
+IMPL (SIMPLE_STRCSPN, 0)
+IMPL (STRCSPN, 1)
 
 size_t
-simple_strcspn (const char *s, const char *rej)
+SIMPLE_STRCSPN (const CHAR *s, const CHAR *rej)
 {
-  const char *r, *str = s;
-  char c;
+  const CHAR *r, *str = s;
+  CHAR c;
 
   while ((c = *s++) != '\0')
     for (r = rej; *r != '\0'; ++r)
@@ -45,9 +64,9 @@ simple_strcspn (const char *s, const char *rej)
 }
 
 size_t
-stupid_strcspn (const char *s, const char *rej)
+STUPID_STRCSPN (const CHAR *s, const CHAR *rej)
 {
-  size_t ns = strlen (s), nrej = strlen (rej);
+  size_t ns = STRLEN (s), nrej = STRLEN (rej);
   size_t i, j;
 
   for (i = 0; i < ns; ++i)
@@ -57,4 +76,6 @@ stupid_strcspn (const char *s, const char *rej)
   return i;
 }
 
+#undef CHAR
+#undef STRLEN
 #include "test-strpbrk.c"
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
index 5765a8c..2c1fce0 100644
--- a/sysdeps/s390/multiarch/Makefile
+++ b/sysdeps/s390/multiarch/Makefile
@@ -13,7 +13,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
 		   strchrnul strchrnul-vx strchrnul-c \
 		   strrchr strrchr-vx strrchr-c \
 		   strspn strspn-vx strspn-c \
-		   strpbrk strpbrk-vx strpbrk-c
+		   strpbrk strpbrk-vx strpbrk-c \
+		   strcspn strcspn-vx strcspn-c
 endif
 
 ifeq ($(subdir),wcsmbs)
@@ -31,5 +32,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
 		   wcschrnul wcschrnul-vx wcschrnul-c \
 		   wcsrchr wcsrchr-vx wcsrchr-c \
 		   wcsspn wcsspn-vx wcsspn-c \
-		   wcspbrk wcspbrk-vx wcspbrk-c
+		   wcspbrk wcspbrk-vx wcspbrk-c \
+		   wcscspn wcscspn-vx wcscspn-c
 endif
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
index b39a5c5..7f62e49 100644
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
@@ -124,6 +124,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
   IFUNC_VX_IMPL (strpbrk);
   IFUNC_VX_IMPL (wcspbrk);
 
+  IFUNC_VX_IMPL (strcspn);
+  IFUNC_VX_IMPL (wcscspn);
+
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
 
   return i;
diff --git a/sysdeps/s390/multiarch/strcspn-c.c b/sysdeps/s390/multiarch/strcspn-c.c
new file mode 100644
index 0000000..af04b4e
--- /dev/null
+++ b/sysdeps/s390/multiarch/strcspn-c.c
@@ -0,0 +1,28 @@
+/* Default strcspn 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 && !defined NOT_IN_libc
+# define STRCSPN  __strcspn_c
+# ifdef SHARED
+#  undef libc_hidden_builtin_def
+#  define libc_hidden_builtin_def(name)				\
+     __hidden_ver1 (__strcspn_c, __GI_strcspn, __strcspn_c);
+# endif /* SHARED */
+
+# include <string/strcspn.c>
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
diff --git a/sysdeps/s390/multiarch/strcspn-vx.S b/sysdeps/s390/multiarch/strcspn-vx.S
new file mode 100644
index 0000000..c7113c4
--- /dev/null
+++ b/sysdeps/s390/multiarch/strcspn-vx.S
@@ -0,0 +1,281 @@
+/* Vector optimized 32/64 bit S/390 version of strcspn.
+   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 && !defined NOT_IN_libc
+
+# include "sysdep.h"
+# include "asm-syntax.h"
+
+	.text
+
+/* size_t strcspn (const char *s, const char * reject)
+   The strcspn() function calculates the length of the initial segment
+   of s which consists entirely of characters not in reject.
+
+   This method checks the length of reject string. If it fits entirely
+   in one vector register, a fast algorithm is used, which does not need
+   to check multiple parts of accept-string. Otherwise a slower full
+   check of accept-string is used.
+
+   register overview:
+   r3:  pointer to start of reject-string
+   r2:  pointer to start of search-string
+   r0:  loaded byte count of vlbb search-string
+   r4:  found byte index
+   r1:  current return len
+   v16: search-string
+   v17: reject-string
+   v18: temp-vreg
+
+   ONLY FOR SLOW:
+   v19: first reject-string
+   v20: zero for preparing acc-vector
+   v21: global mask; 1 indicates a match between
+	search-string-vreg and any reject-character
+   v22: current mask; 1 indicates a match between
+	search-string-vreg and any reject-character in current acc-vreg
+   v24: one for result-checking of former string-part
+   v30, v31: for re-/storing registers r6, r8, r9
+   r5:  current len of reject-string
+   r6:  zero-index in search-string or 16 if no zero
+	or min(zero-index, loaded byte count)
+   r8:  >0, if former reject-string-part contains a zero,
+			otherwise =0;
+   r9:  loaded byte count of vlbb reject-string
+*/
+ENTRY(__strcspn_vx)
+	.machine "z13"
+	.machinemode "zarch_nohighgprs"
+
+	/*
+	  Check if reject-string fits in one vreg:
+	  ----------------------------------------
+	*/
+	vlbb	%v17,0(%r3),6	/* Load reject.  */
+	lghi	%r1,0		/* Zero out current len.  */
+	lcbb	%r0,0(%r3),6
+	jo	.Lcheck_onbb	/* Special case if reject
+				   lays on block-boundary.  */
+.Lcheck_notonbb:
+	vistrbs	%v17,%v17	/* Fill with zeros after first zero.  */
+	je	.Lfast		/* Zero found -> reject fits in one vreg.  */
+	j	.Lslow		/* No zero -> reject exceeds one vreg.  */
+
+
+.Lcheck_onbb:
+	/* Reject lays on block-boundary.  */
+	vfenezb	%v18,%v17,%v17	/* Search zero in loaded reject bytes.  */
+	vlgvb	%r4,%v18,7	/* Get index of zero or 16 if not found.  */
+	clrjl	%r4,%r0,.Lcheck_notonbb /* Zero index < loaded bytes count ->
+					    Reject fits in one vreg;
+					    Fill with zeros and proceed
+					    with FAST.  */
+	vl	%v17,0(%r3)	/* Load reject, which exceeds loaded bytes.  */
+	j	.Lcheck_notonbb /* Check if reject fits in one vreg.  */
+
+
+	/*
+	  Search s for reject in one vreg
+	  -------------------------------
+	*/
+.Lfast:
+	/* Complete reject-string in v17 and remaining bytes are zero.  */
+
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
+	lcbb	%r0,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
+
+	vfaezbs	%v18,%v16,%v17,0 /* Find first element in v16
+				    unequal to any in v17
+				    or first zero element.  */
+
+	vlgvb	%r4,%v18,7	/* Load byte index of found element.  */
+	clrjl	%r4,%r0,.Lfast_loop_found2 /* If found index is within loaded
+					       bytes, return with found element
+					       index (=equal count).  */
+
+	/* Align s to 16 byte.  */
+	risbgn	%r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
+	lghi	%r1,16		/* current_len = 16.  */
+	slr	%r1,%r4		/* Compute bytes to 16bytes boundary.  */
+
+	/* Process s in 16byte aligned loop.  */
+.Lfast_loop:
+	vl	%v16,0(%r1,%r2)	/* Load search-string.  */
+	vfaezbs	%v18,%v16,%v17,0 /* Find first element in v16 equal to any
+				    in v17 or first zero element.  */
+	jno	.Lfast_loop_found
+
+	vl	%v16,16(%r1,%r2)
+	vfaezbs	%v18,%v16,%v17,0
+	jno	.Lfast_loop_found16
+
+	vl	%v16,32(%r1,%r2)
+	vfaezbs	%v18,%v16,%v17,0
+	jno	.Lfast_loop_found32
+
+	vl	%v16,48(%r1,%r2)
+	vfaezbs	%v18,%v16,%v17,0
+	jno	.Lfast_loop_found48
+
+	aghi	%r1,64
+	j	.Lfast_loop	/* Loop if no element was unequal to reject
+				   and not zero.  */
+
+	/* Found equal or zero element.  */
+.Lfast_loop_found48:
+	aghi	%r1,16
+.Lfast_loop_found32:
+	aghi	%r1,16
+.Lfast_loop_found16:
+	aghi	%r1,16
+.Lfast_loop_found:
+	vlgvb	%r4,%v18,7	/* Load byte index of found element or zero.  */
+.Lfast_loop_found2:
+	algrk	%r2,%r1,%r4	/* Add found index to current len.  */
+	br	%r14
+
+
+
+	/*
+	  Search s for reject in multiple vregs
+	  -------------------------------------
+	*/
+.Lslow:
+	/* Save registers.  */
+	vlvgg	%v30,%r6,0
+	vlvgp	%v31,%r8,%r9
+
+	/* Reject in v17 without zero.  */
+	vlr	%v19,%v17	/* Save first acc-part for a fast reload.  */
+	vzero	%v20		/* Zero for preparing acc-vector.  */
+	vone	%v24		/* One for checking result of former
+				   string-part.  */
+
+	/* Align s to 16 byte.  */
+	risbg	%r4,%r2,60,128+63,0 /* Test if s is aligned and
+				       %r4 = bits 60-63 'and' 15.   */
+	je	.Lslow_loop_str /* If s is aligned, loop aligned.  */
+	lghi	%r0,15
+	slr	%r0,%r4		/* Compute highest index to load (15-x).  */
+	vll	%v16,%r0,0(%r2) /* Load up to 16 byte boundary (vll needs
+				   highest index, remaining bytes are 0).  */
+	ahi	%r0,1		/* Work with loaded byte count.  */
+	vzero	%v21		/* Zero out global mask.  */
+	lghi	%r5,0		/* Set current len of reject-string to zero.  */
+	vfenezb	%v18,%v16,%v16	/* Find zero in current string-part.  */
+	lghi	%r8,0		/* There is no zero in first reject-part.  */
+	vlgvb	%r6,%v18,7	/* Load byte index of zero or 16 if no zero.  */
+	clije	%r6,0,.Lslow_end /* If first element is zero -> return 0.  */
+	clr	%r0,%r6		/* cc==1 if loaded byte count < zero-index.  */
+	locrl	%r6,%r0		/* Load on cc==1; zero-index = lbc.  */
+	j	.Lslow_loop_acc
+
+
+	/* Process s in 16byte aligned loop.  */
+.Lslow_next_str:
+	/* Check results of former processed str-part.  */
+	vfeeb	%v18,%v21,%v24	/* Find first equal match in global mask
+				   (ones in element).  */
+	vlgvb	%r4,%v18,7	/* Get index of first one (=equal) or 16.  */
+	/* Equal-index < min(zero-index, loaded byte count)
+	   -> Return pointer to equal element.  */
+	clrjl	%r4,%r6,.Lslow_index_found
+	/* Zero-index < loaded byte count
+	   -> Former str-part was last str-part
+	   -> Return null */
+	clrjl	%r6,%r0,.Lslow_end_not_found
+
+	/* All elements are zero (=no match) -> Proceed with next str-part.  */
+	vlr	%v17,%v19	/* Load first part of reject (no zero).  */
+	algfr	%r1,%r0		/* Add loaded byte count to current len.  */
+
+.Lslow_loop_str:
+	vl	%v16,0(%r1,%r2)	/* Load search-string.  */
+	lghi	%r0,16		/* Loaded byte count is 16.  */
+	vzero	%v21		/* Zero out global mask.  */
+	lghi	%r5,0		/* Set current len of reject to zero.  */
+	vfenezb	%v18,%v16,%v16	/* Find zero in current string-part.  */
+	lghi	%r8,0		/* There is no zero in first reject-part.  */
+	vlgvb	%r6,%v18,7	/* Load byte index of zero or 16 if no zero.  */
+	clije	%r6,0,.Lslow_end /* If first element is zero (end of string)
+				     -> Return current length.  */
+
+.Lslow_loop_acc:
+	vfaeb	%v22,%v16,%v17,4 /* Create matching-mask (1 in mask ->
+				    Character matches any rejected character in
+				    this reject-string-part) IN=0, RT=1.  */
+	vlgvb	%r4,%v22,0	/* Get result of first element.  */
+	/* First element is equal to any rejected characters?
+	   (all other parts of reject cannot lead to a match before this one)
+	   -> Return current len, which is pointing to this element.  */
+	clijh	%r4,0,.Lslow_end
+	vo	%v21,%v21,%v22	/* Global-mask = global-|matching-mask.  */
+	/* Proceed with next acc until end of acc is reached.  */
+
+
+.Lslow_next_acc:
+	clijh	%r8,0,.Lslow_next_str /* There was a zero in last reject-part
+					  -> Add found index to current len
+					     and end.  */
+	vlbb	%v17,16(%r5,%r3),6 /* Load next reject part.  */
+	aghi	%r5,16		/* Increment current len of reject-string.  */
+	lcbb	%r9,0(%r5,%r3),6 /* Get loaded byte count of reject-string.  */
+	jo	.Lslow_next_acc_onbb /* Jump away if reject-string is
+					 on block-boundary.  */
+.Lslow_next_acc_notonbb:
+	vistrbs	%v17,%v17	/* Fill with zeros after first zero.  */
+	jo	.Lslow_loop_acc /* No zero found -> no preparation needed.  */
+
+.Lslow_next_acc_prepare_zero:
+	/* Zero in reject-part: fill zeros with first-reject-character.  */
+	vlgvb	%r8,%v17,0	/* Load first element of reject-part.  */
+	clije	%r8,0,.Lslow_next_str /* Process next str-part if first
+					  character in this part of reject
+					  is a zero.  */
+	/* r8>0 -> zero found in this acc-part.  */
+	vrepb	%v18,%v17,0	/* Replicate first char accross all chars.  */
+	vceqb	%v22,%v20,%v17	/* Create a mask (v22) of null chars
+				   by comparing with 0 (v20).  */
+	vsel	%v17,%v18,%v17,%v22 /* Replace null chars with first char.  */
+	j	.Lslow_loop_acc /* Reject-string part is prepared.  */
+
+.Lslow_next_acc_onbb:
+	vfenezb	%v18,%v17,%v17	/* Find zero in loaded bytes of reject part.  */
+	vlgvb	%r8,%v18,7	/* Load byte index of zero.  */
+	clrjl	%r8,%r9,.Lslow_next_acc_notonbb /* Found a zero in loaded bytes
+						    -> Prepare vreg.  */
+	vl	%v17,0(%r5,%r3)	/* Load over boundary ...  */
+	lghi	%r8,0		/* r8=0 -> no zero in this part of acc,
+				   check for zero is in jump-target.  */
+	j	.Lslow_next_acc_notonbb /* ... and search for zero in
+					    fully loaded vreg again.  */
+
+.Lslow_end_not_found:
+	algfr	%r1,%r6		/* Add zero-index to current len.  */
+	j	.Lslow_end
+.Lslow_index_found:
+	algfr	%r1,%r4		/* Add found index of char to current len.  */
+.Lslow_end:
+	lgr	%r2,%r1
+	/* Restore registers.  */
+	vlgvg	%r6,%v30,0
+	vlgvg	%r8,%v31,0
+	vlgvg	%r9,%v31,1
+	br	%r14
+END(__strcspn_vx)
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
diff --git a/sysdeps/s390/multiarch/strcspn.c b/sysdeps/s390/multiarch/strcspn.c
new file mode 100644
index 0000000..32b46c4
--- /dev/null
+++ b/sysdeps/s390/multiarch/strcspn.c
@@ -0,0 +1,27 @@
+/* Multiple versions of strcspn.
+   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 && !defined NOT_IN_libc
+# include <string.h>
+# include <ifunc-resolve.h>
+
+s390_vx_libc_ifunc2 (__strcspn, strcspn)
+
+#else
+# include <string/strcspn.c>
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
diff --git a/sysdeps/s390/multiarch/wcscspn-c.c b/sysdeps/s390/multiarch/wcscspn-c.c
new file mode 100644
index 0000000..95e76ae
--- /dev/null
+++ b/sysdeps/s390/multiarch/wcscspn-c.c
@@ -0,0 +1,26 @@
+/* Default wcscscpn 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 && !defined NOT_IN_libc
+# define WCSCSPN  __wcscspn_c
+
+# include <wchar.h>
+extern __typeof (wcscspn) __wcscspn_c;
+
+# include <wcsmbs/wcscspn.c>
+#endif
diff --git a/sysdeps/s390/multiarch/wcscspn-vx.S b/sysdeps/s390/multiarch/wcscspn-vx.S
new file mode 100644
index 0000000..aa581ce
--- /dev/null
+++ b/sysdeps/s390/multiarch/wcscspn-vx.S
@@ -0,0 +1,293 @@
+/* Vector optimized 32/64 bit S/390 version of wcscspn.
+   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 && !defined NOT_IN_libc
+
+# include "sysdep.h"
+# include "asm-syntax.h"
+
+	.text
+
+/* size_t wcscspn (const wchar_t *s, const wchar_t * reject)
+   The wcscspn() function calculates the length of the initial segment
+   of s which consists entirely of characters not in reject.
+
+   This method checks the length of reject string. If it fits entirely
+   in one vector register, a fast algorithm is used, which does not need
+   to check multiple parts of accept-string. Otherwise a slower full
+   check of accept-string is used.
+
+   register overview:
+   r3:  pointer to start of reject-string
+   r2:  pointer to start of search-string
+   r0:  loaded byte count of vlbb search-string
+   r4:  found byte index
+   r1:  current return len
+   v16: search-string
+   v17: reject-string
+   v18: temp-vreg
+
+   ONLY FOR SLOW:
+   v19: first reject-string
+   v20: zero for preparing acc-vector
+   v21: global mask; 1 indicates a match between
+	search-string-vreg and any reject-character
+   v22: current mask; 1 indicates a match between
+	search-string-vreg and any reject-character in current acc-vreg
+   v30, v31: for re-/storing registers r6, r8, r9
+   r5:  current len of reject-string
+   r6:  zero-index in search-string or 16 if no zero
+	or min(zero-index, loaded byte count)
+   r8:  >0, if former reject-string-part contains a zero,
+			otherwise =0;
+   r9:  loaded byte count of vlbb reject-string
+*/
+ENTRY(__wcscspn_vx)
+	.machine "z13"
+	.machinemode "zarch_nohighgprs"
+
+	tmll	%r2,3		/* Test if s is 4-byte aligned?  */
+	jne	.Lfallback	/* And use common-code variant if not.  */
+
+	/*
+	  Check if reject-string fits in one vreg:
+	  ----------------------------------------
+	*/
+	vlbb	%v17,0(%r3),0	/* Load reject.  */
+	lcbb	%r0,0(%r3),0
+	jo	.Lcheck_onbb	/* Special case if reject
+				   lays on block-boundary.  */
+
+.Lcheck_notonbb:
+	lghi	%r1,0		/* Zero out current len.  */
+	vistrfs	%v17,%v17	/* Fill with zeros after first zero.  */
+	je	.Lfast		/* Zero found -> reject fits in one vreg.  */
+	j	.Lslow		/* No zero -> reject exceeds one vreg.  */
+
+
+.Lcheck_onbb:
+	/* Reject lays on block-boundary.  */
+	nill	%r0,65532	/* Recognize only fully loaded characters.  */
+	je	.Lcheck_onbb2	/* Reload vr, if we loaded no full wchar_t.  */
+	vfenezf	%v18,%v17,%v17	/* Search zero in loaded reject bytes.  */
+	vlgvb	%r4,%v18,7	/* Get index of zero or 16 if not found.  */
+	clrjl	%r4,%r0,.Lcheck_notonbb /* Zero index < loaded bytes count ->
+					    Reject fits in one vreg;
+					    Fill with zeros and proceed
+					    with FAST.  */
+.Lcheck_onbb2:
+	vl	%v17,0(%r3)	/* Load reject, which exceeds loaded bytes.  */
+	j	.Lcheck_notonbb /* Check if reject fits in one vreg.  */
+
+
+	/*
+	  Search s for reject in one vreg
+	  -------------------------------
+	*/
+.Lfast:
+	/* Complete reject-string in v17 and remaining bytes are zero.  */
+
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
+	lcbb	%r0,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
+
+	vfaezfs	%v18,%v16,%v17,0 /* Find first element in v16
+				    unequal to any in v17
+				    or first zero element.  */
+	vlgvb	%r4,%v18,7	/* Load byte index of found element.  */
+	clrjl	%r4,%r0,.Lfast_loop_found2 /* If found index is within loaded
+					       bytes, return with found element
+					       index (=equal count).  */
+
+	/* Align s to 16 byte.  */
+	risbgn	%r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
+	lghi	%r1,16		/* current_len = 16.  */
+	slr	%r1,%r4		/* Compute bytes to 16bytes boundary.  */
+
+	/* Process s in 16byte aligned loop.  */
+.Lfast_loop:
+	vl	%v16,0(%r1,%r2)	/* Load search-string.  */
+	vfaezfs	%v18,%v16,%v17,0 /* Find first element in v16 equal to any
+				    in v17 or first zero element.  */
+	jno	.Lfast_loop_found
+
+	vl	%v16,16(%r1,%r2)
+	vfaezfs	%v18,%v16,%v17,0
+	jno	.Lfast_loop_found16
+
+	vl	%v16,32(%r1,%r2)
+	vfaezfs	%v18,%v16,%v17,0
+	jno	.Lfast_loop_found32
+
+	vl	%v16,48(%r1,%r2)
+	vfaezfs	%v18,%v16,%v17,0
+	jno	.Lfast_loop_found48
+
+	aghi	%r1,64
+	j	.Lfast_loop	/* Loop if no element was unequal to reject
+				   and not zero.  */
+
+	/* Found equal or zero element.  */
+.Lfast_loop_found48:
+	aghi	%r1,16
+.Lfast_loop_found32:
+	aghi	%r1,16
+.Lfast_loop_found16:
+	aghi	%r1,16
+.Lfast_loop_found:
+	vlgvb	%r4,%v18,7	/* Load byte index of found element or zero.  */
+.Lfast_loop_found2:
+	algrk	%r2,%r1,%r4	/* Add found index to current len.  */
+	srlg	%r2,%r2,2	/* Convert byte-count to character-count.  */
+	br	%r14
+
+
+
+	/*
+	  Search s for reject in multiple vregs
+	  -------------------------------------
+	*/
+.Lslow:
+	/* Save registers.  */
+	vlvgg	%v30,%r6,0
+	vlvgp	%v31,%r8,%r9
+
+	/* Reject in v17 without zero.  */
+	vlr	%v19,%v17	/* Save first acc-part for a fast reload.  */
+	vzero	%v20		/* Zero for preparing acc-vector.  */
+	vone	%v24		/* One for checking result of former
+				   string-part.  */
+
+	/* Align s to 16 byte.  */
+	risbg	%r4,%r2,60,128+63,0 /* Test if s is aligned and
+				       %r4 = bits 60-63 'and' 15.   */
+	je	.Lslow_loop_str /* If s is aligned, loop aligned.  */
+	lghi	%r0,15
+	slr	%r0,%r4		/* Compute highest index to load (15-x).  */
+	vll	%v16,%r0,0(%r2) /* Load up to 16byte boundary (vll needs
+				   highest index, remaining bytes are 0).  */
+	ahi	%r0,1		/* Work with loaded byte count.  */
+	vzero	%v21		/* Zero out global mask.  */
+	lghi	%r5,0		/* Set current len of reject-string to zero.  */
+	vfenezf	%v18,%v16,%v16	/* Find zero in current string-part.  */
+	lghi	%r8,0		/* There is no zero in first reject-part.  */
+	vlgvb	%r6,%v18,7	/* Load byte index of zero or 16 if no zero.  */
+	clije	%r6,0,.Lslow_end /* If first element is zero -> return 0.  */
+	clr	%r0,%r6		/* cc==1 if loaded byte count < zero-index.  */
+	locrl	%r6,%r0		/* Load on cc==1; zero-index = lbc.  */
+	j	.Lslow_loop_acc
+
+
+	/* Process s in 16byte aligned loop.  */
+.Lslow_next_str:
+	/* Check results of former processed str-part.  */
+	vfeef	%v18,%v21,%v24	/* Find first equal match in global mask
+				   (ones in element).  */
+	vlgvb	%r4,%v18,7	/* Get index of first one (=equal) or 16.  */
+	/* Equal-index < min(zero-index, loaded byte count)
+	   -> Return pointer to equal element.  */
+	clrjl	%r4,%r6,.Lslow_index_found
+	/* Zero-index < loaded byte count
+	   -> Former str-part was last str-part
+	   -> Return null  */
+	clrjl	%r6,%r0,.Lslow_end_not_found
+
+	/* All elements are zero (=no match) -> proceed with next str-part.  */
+	vlr	%v17,%v19	/* Load first part of reject (no zero).  */
+	algfr	%r1,%r0		/* Add loaded byte count to current len.  */
+
+.Lslow_loop_str:
+	vl	%v16,0(%r1,%r2)	/* Load search-string.  */
+	lghi	%r0,16		/* Loaded byte count is 16.  */
+	vzero	%v21		/* Zero out global mask.  */
+	lghi	%r5,0		/* Set current len of reject to zero.  */
+	vfenezf	%v18,%v16,%v16	/* Find zero in current string-part.  */
+	lghi	%r8,0		/* There is no zero in first reject-part.  */
+	vlgvb	%r6,%v18,7	/* Load byte index of zero or 16 if no zero.  */
+	clije	%r6,0,.Lslow_end /* If first element is zero (end of string)
+				     -> Return current length.  */
+
+.Lslow_loop_acc:
+	vfaef	%v22,%v16,%v17,4 /* Create matching-mask (1 in mask ->
+				    Character matches any rejected character in
+				    this reject-string-part) IN=0, RT=1.  */
+	vlgvf	%r4,%v22,0	/* Get result of first element.  */
+	/* First element is equal to any rejected characters?
+	   (All other parts of reject cannot lead to a match before this one)
+	   -> Return current len, which is pointing to this element.  */
+	clijh	%r4,0,.Lslow_end
+	vo	%v21,%v21,%v22	/* Global-mask = global-|matching-mask.  */
+	/* Proceed with next acc until end of acc is reached.  */
+
+
+.Lslow_next_acc:
+	clijh	%r8,0,.Lslow_next_str /* There was a zero in last reject-part
+					  -> Add found index to current len
+					     and end.  */
+	vlbb	%v17,16(%r5,%r3),6 /* Load next reject part.  */
+	aghi	%r5,16		/* Increment current len of reject-string.  */
+	lcbb	%r9,0(%r5,%r3),6 /* Get loaded byte count of reject-string.  */
+	jo	.Lslow_next_acc_onbb /* Jump away if reject-string is
+					 on block-boundary.  */
+.Lslow_next_acc_notonbb:
+	vistrfs	%v17,%v17	/* Fill with zeros after first zero.  */
+	jo	.Lslow_loop_acc /* No zero found -> no preparation needed.  */
+
+.Lslow_next_acc_prepare_zero:
+	/* Zero in reject-part: fill zeros with first-reject-character.  */
+	vlgvf	%r8,%v17,0	/* Load first element of reject-part.  */
+	clije	%r8,0,.Lslow_next_str /* Process next str-part if first
+					  character in this part of reject
+					  is a zero.  */
+	/* r8>0 -> zero found in this acc-part.  */
+	vrepf	%v18,%v17,0	/* Replicate first char accross all chars.  */
+	vceqf	%v22,%v20,%v17	/* Create a mask (v22) of null chars
+				   by comparing with 0 (v20).  */
+	vsel	%v17,%v18,%v17,%v22 /* Replace null chars with first char.  */
+	j	.Lslow_loop_acc /* Reject-string part is prepared.  */
+
+.Lslow_next_acc_onbb:
+	nill	%r9,65532	/* Recognize only fully loaded characters.  */
+	je	.Lslow_next_acc_onbb2 /* Reload vr, if no full wchar_t
+					  loaded.  */
+	vfenezf	%v18,%v17,%v17	/* Find zero in loaded bytes of reject part.  */
+	vlgvb	%r8,%v18,7	/* Load byte index of zero.  */
+	clrjl	%r8,%r9,.Lslow_next_acc_notonbb /* Found a zero in loaded bytes
+						    -> Prepare vreg.  */
+.Lslow_next_acc_onbb2:
+	vl	%v17,0(%r5,%r3)	/* Load over boundary ...  */
+	lghi	%r8,0		/* r8=0 -> no zero in this part of acc,
+				   check for zero is in jump-target.  */
+	j	.Lslow_next_acc_notonbb /* ... and search for zero in
+					    fully loaded vreg again.  */
+
+.Lslow_end_not_found:
+	algfr	%r1,%r6		/* Add zero-index to current len.  */
+	j	.Lslow_end
+.Lslow_index_found:
+	algfr	%r1,%r4		/* Add found index of char to current len.  */
+.Lslow_end:
+	srlg	%r2,%r1,2	/* Convert byte-count to character-count.  */
+	/* Restore registers.  */
+	vlgvg	%r6,%v30,0
+	vlgvg	%r8,%v31,0
+	vlgvg	%r9,%v31,1
+	br	%r14
+.Lfallback:
+	jg	__wcscspn_c
+END(__wcscspn_vx)
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
diff --git a/sysdeps/s390/multiarch/wcscspn.c b/sysdeps/s390/multiarch/wcscspn.c
new file mode 100644
index 0000000..3cb4516
--- /dev/null
+++ b/sysdeps/s390/multiarch/wcscspn.c
@@ -0,0 +1,27 @@
+/* Multiple versions of wcscspn.
+   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 && !defined NOT_IN_libc
+# include <wchar.h>
+# include <ifunc-resolve.h>
+
+s390_vx_libc_ifunc2 (__wcscspn, wcscspn)
+
+#else
+# include <wcsmbs/wcscspn.c>
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
index 7ecff8b..9730b00 100644
--- a/wcsmbs/Makefile
+++ b/wcsmbs/Makefile
@@ -42,7 +42,8 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
 	    mbrtoc16 c16rtomb
 
 strop-tests :=  wcscmp wcsncmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
-		wcpcpy wcsncpy wcpncpy wcscat wcsncat wcschrnul wcsspn wcspbrk
+		wcpcpy wcsncpy wcpncpy wcscat wcsncat wcschrnul wcsspn wcspbrk \
+		wcscspn
 tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
 	 tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \
 	 tst-c16c32-1 wcsatcliff $(addprefix test-,$(strop-tests))
diff --git a/wcsmbs/test-wcscspn-ifunc.c b/wcsmbs/test-wcscspn-ifunc.c
new file mode 100644
index 0000000..e5dcdaf
--- /dev/null
+++ b/wcsmbs/test-wcscspn-ifunc.c
@@ -0,0 +1,20 @@
+/* Test and measure IFUNC implementations of wcscspn function.
+   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 TEST_IFUNC 1
+#include "test-wcscspn.c"
diff --git a/wcsmbs/test-wcscspn.c b/wcsmbs/test-wcscspn.c
new file mode 100644
index 0000000..d09cd3d
--- /dev/null
+++ b/wcsmbs/test-wcscspn.c
@@ -0,0 +1,20 @@
+/* Test wcscspn 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 "../string/test-strcspn.c"
diff --git a/wcsmbs/wcscspn.c b/wcsmbs/wcscspn.c
index 5d38d07..9e84226 100644
--- a/wcsmbs/wcscspn.c
+++ b/wcsmbs/wcscspn.c
@@ -18,6 +18,9 @@
 
 #include <wchar.h>
 
+#ifdef WCSCSPN
+# define wcscspn WCSCSPN
+#endif
 
 /* Return the length of the maximum initial segment
    of WCS which contains only wide-characters not in REJECT.  */
-- 
2.3.0