Blame SOURCES/glibc-rh1380680-3.patch

147e83
From c3fd92047b3cc1b66b9b241be0765fe1e72678a1 Mon Sep 17 00:00:00 2001
147e83
From: Stefan Liebler <stli@linux.vnet.ibm.com>
147e83
Date: Mon, 7 Nov 2016 15:29:26 +0100
147e83
Subject: [PATCH 03/17] S390: Optimize 8bit-generic iconv modules.
147e83
147e83
Upstream commit 4690dab084f854bf0013b5eaabcf90c2d5b692ff
147e83
147e83
This patch introduces a s390 specific 8bit-generic.c file which provides an
147e83
optimized version for z13 with translate-/vector-instructions, which will be
147e83
chosen at runtime via ifunc.
147e83
If the build-environment lacks vector support, then iconvdata/8bit-generic.c
147e83
is used wihtout any change. Otherwise iconvdata/8bit-generic.c is used to create
147e83
conversion loop routines without vector instructions as fallback, if vector
147e83
instructions aren't available at runtime.
147e83
147e83
The vector routines can only be used with charsets where the maximum UCS4 value
147e83
fits in 1 byte size. Then the hardware translate-instruction is used
147e83
to translate between up to 256 generic characters and "1 byte UCS4"
147e83
characters at once. The vector instructions are used to convert between
147e83
the "1 byte UCS4" and UCS4.
147e83
147e83
The gen-8bit.sh script in sysdeps/s390/multiarch generates the conversion
147e83
table to_ucs1. Therefore in sysdeps/s390/multiarch/Makefile is added an
147e83
override define generate-8bit-table, which is originally defined in
147e83
iconvdata/Makefile. This version calls the gen-8bit.sh in iconvdata folder
147e83
and the s390 one.
147e83
147e83
ChangeLog:
147e83
147e83
	* sysdeps/s390/multiarch/8bit-generic.c: New File.
147e83
	* sysdeps/s390/multiarch/gen-8bit.sh: New File.
147e83
	* sysdeps/s390/multiarch/Makefile (generate-8bit-table):
147e83
	New override define.
147e83
	* sysdeps/s390/multiarch/iconv/skeleton.c: Likewise.
147e83
---
147e83
 sysdeps/s390/multiarch/8bit-generic.c   | 415 ++++++++++++++++++++++++++++++++
147e83
 sysdeps/s390/multiarch/Makefile         |  10 +
147e83
 sysdeps/s390/multiarch/gen-8bit.sh      |   6 +
147e83
 sysdeps/s390/multiarch/iconv/skeleton.c |  21 ++
147e83
 4 files changed, 452 insertions(+)
147e83
 create mode 100644 sysdeps/s390/multiarch/8bit-generic.c
147e83
 create mode 100644 sysdeps/s390/multiarch/gen-8bit.sh
147e83
 create mode 100644 sysdeps/s390/multiarch/iconv/skeleton.c
147e83
147e83
diff --git a/sysdeps/s390/multiarch/8bit-generic.c b/sysdeps/s390/multiarch/8bit-generic.c
147e83
new file mode 100644
147e83
index 0000000..93565e1
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/8bit-generic.c
147e83
@@ -0,0 +1,415 @@
147e83
+/* Generic conversion to and from 8bit charsets - S390 version.
147e83
+   Copyright (C) 2016 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#if defined HAVE_S390_VX_ASM_SUPPORT
147e83
+
147e83
+# if defined HAVE_S390_VX_GCC_SUPPORT
147e83
+#  define ASM_CLOBBER_VR(NR) , NR
147e83
+# else
147e83
+#  define ASM_CLOBBER_VR(NR)
147e83
+# endif
147e83
+
147e83
+/* Generate the conversion loop routines without vector instructions as
147e83
+   fallback, if vector instructions aren't available at runtime.  */
147e83
+# define IGNORE_ICONV_SKELETON
147e83
+# define from_generic __from_generic_c
147e83
+# define to_generic __to_generic_c
147e83
+# include "iconvdata/8bit-generic.c"
147e83
+# undef IGNORE_ICONV_SKELETON
147e83
+# undef from_generic
147e83
+# undef to_generic
147e83
+
147e83
+/* Generate the converion routines with vector instructions. The vector
147e83
+   routines can only be used with charsets where the maximum UCS4 value
147e83
+   fits in 1 byte size. Then the hardware translate-instruction is used
147e83
+   to translate between multiple generic characters and "1 byte UCS4"
147e83
+   characters at once. The vector instructions are used to convert between
147e83
+   the "1 byte UCS4" and UCS4.  */
147e83
+# include <unistd.h>
147e83
+# include <dl-procinfo.h>
147e83
+
147e83
+# undef FROM_LOOP
147e83
+# undef TO_LOOP
147e83
+# define FROM_LOOP		__from_generic_vx
147e83
+# define TO_LOOP		__to_generic_vx
147e83
+
147e83
+# define MIN_NEEDED_FROM	1
147e83
+# define MIN_NEEDED_TO		4
147e83
+# define ONE_DIRECTION		0
147e83
+
147e83
+/* First define the conversion function from the 8bit charset to UCS4.  */
147e83
+# define MIN_NEEDED_INPUT	MIN_NEEDED_FROM
147e83
+# define MIN_NEEDED_OUTPUT	MIN_NEEDED_TO
147e83
+# define LOOPFCT		FROM_LOOP
147e83
+# define BODY_FROM_ORIG \
147e83
+  {									      \
147e83
+    uint32_t ch = to_ucs4[*inptr];					      \
147e83
+									      \
147e83
+    if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && *inptr != '\0')     \
147e83
+      {									      \
147e83
+	/* This is an illegal character.  */				      \
147e83
+	STANDARD_FROM_LOOP_ERR_HANDLER (1);				      \
147e83
+      }									      \
147e83
+									      \
147e83
+    put32 (outptr, ch);							      \
147e83
+    outptr += 4;							      \
147e83
+    ++inptr;								      \
147e83
+  }
147e83
+
147e83
+# define BODY								\
147e83
+  {									\
147e83
+    if (__builtin_expect (inend - inptr < 16, 1)			\
147e83
+	|| outend - outptr < 64)					\
147e83
+      /* Convert remaining bytes with c code.  */			\
147e83
+      BODY_FROM_ORIG							\
147e83
+    else								\
147e83
+       {								\
147e83
+	 /* Convert 16 ... 256 bytes at once with tr-instruction.  */	\
147e83
+	 size_t index;							\
147e83
+	 char buf[256];							\
147e83
+	 size_t loop_count = (inend - inptr) / 16;			\
147e83
+	 if (loop_count > (outend - outptr) / 64)			\
147e83
+	   loop_count = (outend - outptr) / 64;				\
147e83
+	 if (loop_count > 16)						\
147e83
+	   loop_count = 16;						\
147e83
+	 __asm__ volatile (".machine push\n\t"				\
147e83
+			   ".machine \"z13\"\n\t"			\
147e83
+			   ".machinemode \"zarch_nohighgprs\"\n\t"	\
147e83
+			   "    sllk %[R_I],%[R_LI],4\n\t"		\
147e83
+			   "    ahi %[R_I],-1\n\t"			\
147e83
+			   /* Execute mvc and tr with correct len.  */	\
147e83
+			   "    exrl %[R_I],21f\n\t"			\
147e83
+			   "    exrl %[R_I],22f\n\t"			\
147e83
+			   /* Post-processing.  */			\
147e83
+			   "    lghi %[R_I],0\n\t"			\
147e83
+			   "    vzero %%v0\n\t"				\
147e83
+			   "0:  \n\t"					\
147e83
+			   /* Find invalid character - value is zero.  */ \
147e83
+			   "    vl %%v16,0(%[R_I],%[R_BUF])\n\t"	\
147e83
+			   "    vceqbs %%v23,%%v0,%%v16\n\t"		\
147e83
+			   "    jle 10f\n\t"				\
147e83
+			   "1:  \n\t"					\
147e83
+			   /* Enlarge to UCS4.  */			\
147e83
+			   "    vuplhb %%v17,%%v16\n\t"			\
147e83
+			   "    vupllb %%v18,%%v16\n\t"			\
147e83
+			   "    vuplhh %%v19,%%v17\n\t"			\
147e83
+			   "    vupllh %%v20,%%v17\n\t"			\
147e83
+			   "    vuplhh %%v21,%%v18\n\t"			\
147e83
+			   "    vupllh %%v22,%%v18\n\t"			\
147e83
+			   /* Store 64bytes to buf_out.  */		\
147e83
+			   "    vstm %%v19,%%v22,0(%[R_OUT])\n\t"	\
147e83
+			   "    aghi %[R_I],16\n\t"			\
147e83
+			   "    la %[R_OUT],64(%[R_OUT])\n\t"		\
147e83
+			   "    brct %[R_LI],0b\n\t"			\
147e83
+			   "    la %[R_IN],0(%[R_I],%[R_IN])\n\t"	\
147e83
+			   "    j 20f\n\t"				\
147e83
+			   "21: mvc 0(1,%[R_BUF]),0(%[R_IN])\n\t"	\
147e83
+			   "22: tr 0(1,%[R_BUF]),0(%[R_TBL])\n\t"	\
147e83
+			   /* Possibly invalid character found.  */	\
147e83
+			   "10: \n\t"					\
147e83
+			   /* Test if input was zero, too.  */		\
147e83
+			   "    vl %%v24,0(%[R_I],%[R_IN])\n\t"		\
147e83
+			   "    vceqb %%v24,%%v0,%%v24\n\t"		\
147e83
+			   /* Zeros in buf (v23) and inptr (v24) are marked \
147e83
+			      with one bits. After xor, invalid characters \
147e83
+			      are marked as one bits. Proceed, if no	\
147e83
+			      invalid characters are found.  */		\
147e83
+			   "    vx %%v24,%%v23,%%v24\n\t"		\
147e83
+			   "    vfenebs %%v24,%%v24,%%v0\n\t"		\
147e83
+			   "    jo 1b\n\t"				\
147e83
+			   /* Found an invalid translation.		\
147e83
+			      Store the preceding chars.  */		\
147e83
+			   "    la %[R_IN],0(%[R_I],%[R_IN])\n\t"	\
147e83
+			   "    vlgvb %[R_I],%%v24,7\n\t"		\
147e83
+			   "    la %[R_IN],0(%[R_I],%[R_IN])\n\t"	\
147e83
+			   "    sll %[R_I],2\n\t"			\
147e83
+			   "    ahi %[R_I],-1\n\t"			\
147e83
+			   "    jl 20f\n\t"				\
147e83
+			   "    lgr %[R_LI],%[R_I]\n\t"			\
147e83
+			   "    vuplhb %%v17,%%v16\n\t"			\
147e83
+			   "    vuplhh %%v19,%%v17\n\t"			\
147e83
+			   "    vstl %%v19,%[R_I],0(%[R_OUT])\n\t"	\
147e83
+			   "    ahi %[R_I],-16\n\t"			\
147e83
+			   "    jl 11f\n\t"				\
147e83
+			   "    vupllh %%v20,%%v17\n\t"			\
147e83
+			   "    vstl %%v20,%[R_I],16(%[R_OUT])\n\t"	\
147e83
+			   "    ahi %[R_I],-16\n\t"			\
147e83
+			   "    jl 11f\n\t"				\
147e83
+			   "    vupllb %%v18,%%v16\n\t"			\
147e83
+			   "    vuplhh %%v21,%%v18\n\t"			\
147e83
+			   "    vstl %%v21,%[R_I],32(%[R_OUT])\n\t"	\
147e83
+			   "    ahi %[R_I],-16\n\t"			\
147e83
+			   "    jl 11f\n\t"				\
147e83
+			   "    vupllh %%v22,%%v18\n\t"			\
147e83
+			   "    vstl %%v22,%[R_I],48(%[R_OUT])\n\t"	\
147e83
+			   "11: \n\t"					\
147e83
+			   "    la %[R_OUT],1(%[R_LI],%[R_OUT])\n\t"	\
147e83
+			   "20: \n\t"					\
147e83
+			   ".machine pop"				\
147e83
+			   : /* outputs */ [R_IN] "+a" (inptr)		\
147e83
+			     , [R_OUT] "+a" (outptr), [R_I] "=&a" (index) \
147e83
+			     , [R_LI] "+a" (loop_count)			\
147e83
+			   : /* inputs */ [R_BUF] "a" (buf)		\
147e83
+			     , [R_TBL] "a" (to_ucs1)			\
147e83
+			   : /* clobber list*/ "memory", "cc"		\
147e83
+			     ASM_CLOBBER_VR ("v0")  ASM_CLOBBER_VR ("v16") \
147e83
+			     ASM_CLOBBER_VR ("v17") ASM_CLOBBER_VR ("v18") \
147e83
+			     ASM_CLOBBER_VR ("v19") ASM_CLOBBER_VR ("v20") \
147e83
+			     ASM_CLOBBER_VR ("v21") ASM_CLOBBER_VR ("v22") \
147e83
+			     ASM_CLOBBER_VR ("v23") ASM_CLOBBER_VR ("v24") \
147e83
+			   );						\
147e83
+	 /* Error occured?  */						\
147e83
+	 if (loop_count != 0)						\
147e83
+	   {								\
147e83
+	     /* Found an invalid character!  */				\
147e83
+	    STANDARD_FROM_LOOP_ERR_HANDLER (1);				\
147e83
+	  }								\
147e83
+      }									\
147e83
+    }
147e83
+
147e83
+# define LOOP_NEED_FLAGS
147e83
+# include <iconv/loop.c>
147e83
+
147e83
+/* Next, define the other direction - from UCS4 to 8bit charset.  */
147e83
+# define MIN_NEEDED_INPUT	MIN_NEEDED_TO
147e83
+# define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
147e83
+# define LOOPFCT		TO_LOOP
147e83
+# define BODY_TO_ORIG \
147e83
+  {									      \
147e83
+    uint32_t ch = get32 (inptr);					      \
147e83
+									      \
147e83
+    if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), 0)\
147e83
+	|| (__builtin_expect (from_ucs4[ch], '\1') == '\0' && ch != 0))	      \
147e83
+      {									      \
147e83
+	UNICODE_TAG_HANDLER (ch, 4);					      \
147e83
+									      \
147e83
+	/* This is an illegal character.  */				      \
147e83
+	STANDARD_TO_LOOP_ERR_HANDLER (4);				      \
147e83
+      }									      \
147e83
+									      \
147e83
+    *outptr++ = from_ucs4[ch];						      \
147e83
+    inptr += 4;								      \
147e83
+  }
147e83
+# define BODY								\
147e83
+  {									\
147e83
+    if (__builtin_expect (inend - inptr < 64, 1)			\
147e83
+	|| outend - outptr < 16)					\
147e83
+      /* Convert remaining bytes with c code.  */			\
147e83
+      BODY_TO_ORIG							\
147e83
+    else								\
147e83
+      {									\
147e83
+	/* Convert 64 ... 1024 bytes at once with tr-instruction.  */	\
147e83
+	size_t index, tmp;						\
147e83
+	char buf[256];							\
147e83
+	size_t loop_count = (inend - inptr) / 64;			\
147e83
+	uint32_t max = sizeof (from_ucs4) / sizeof (from_ucs4[0]);	\
147e83
+	if (loop_count > (outend - outptr) / 16)			\
147e83
+	  loop_count = (outend - outptr) / 16;				\
147e83
+	if (loop_count > 16)						\
147e83
+	  loop_count = 16;						\
147e83
+	size_t remaining_loop_count = loop_count;			\
147e83
+	/* Step 1: Check for ch>=max, ch == 0 and shorten to bytes.	\
147e83
+	   (ch == 0 is no error, but is handled differently)  */	\
147e83
+	__asm__ volatile (".machine push\n\t"				\
147e83
+			  ".machine \"z13\"\n\t"			\
147e83
+			  ".machinemode \"zarch_nohighgprs\"\n\t"	\
147e83
+			  /* Setup to check for ch >= max.  */		\
147e83
+			  "    vzero %%v21\n\t"				\
147e83
+			  "    vleih %%v21,-24576,0\n\t" /* element 0:   >  */ \
147e83
+			  "    vleih %%v21,-8192,2\n\t"  /* element 1: =<>  */ \
147e83
+			  "    vlvgf %%v20,%[R_MAX],0\n\t" /* element 0: val  */ \
147e83
+			  /* Process in 64byte - 16 characters blocks.  */ \
147e83
+			  "    lghi %[R_I],0\n\t"			\
147e83
+			  "    lghi %[R_TMP],0\n\t"			\
147e83
+			  "0:  \n\t"					\
147e83
+			  "    vlm %%v16,%%v19,0(%[R_IN])\n\t"		\
147e83
+			  /* Test for ch >= max and ch == 0.  */	\
147e83
+			  "    vstrczfs %%v22,%%v16,%%v20,%%v21\n\t"	\
147e83
+			  "    jno 10f\n\t"				\
147e83
+			  "    vstrczfs %%v22,%%v17,%%v20,%%v21\n\t"	\
147e83
+			  "    jno 11f\n\t"				\
147e83
+			  "    vstrczfs %%v22,%%v18,%%v20,%%v21\n\t"	\
147e83
+			  "    jno 12f\n\t"				\
147e83
+			  "    vstrczfs %%v22,%%v19,%%v20,%%v21\n\t"	\
147e83
+			  "    jno 13f\n\t"				\
147e83
+			  /* Shorten to byte values.  */		\
147e83
+			  "    vpkf %%v16,%%v16,%%v17\n\t"		\
147e83
+			  "    vpkf %%v18,%%v18,%%v19\n\t"		\
147e83
+			  "    vpkh %%v16,%%v16,%%v18\n\t"		\
147e83
+			  /* Store 16bytes to buf.  */			\
147e83
+			  "    vst %%v16,0(%[R_I],%[R_BUF])\n\t"	\
147e83
+			  /* Loop until all blocks are processed.  */	\
147e83
+			  "    la %[R_IN],64(%[R_IN])\n\t"		\
147e83
+			  "    aghi %[R_I],16\n\t"			\
147e83
+			  "    brct %[R_LI],0b\n\t"			\
147e83
+			  "    j 20f\n\t"				\
147e83
+			  /* Found error ch >= max or ch == 0. */	\
147e83
+			  "13: aghi %[R_TMP],4\n\t"			\
147e83
+			  "12: aghi %[R_TMP],4\n\t"			\
147e83
+			  "11: aghi %[R_TMP],4\n\t"			\
147e83
+			  "10: vlgvb %[R_I],%%v22,7\n\t"		\
147e83
+			  "    srlg %[R_I],%[R_I],2\n\t"		\
147e83
+			  "    agr %[R_I],%[R_TMP]\n\t"			\
147e83
+			  "20: \n\t"					\
147e83
+			  ".machine pop"				\
147e83
+			  : /* outputs */ [R_IN] "+a" (inptr)		\
147e83
+			    , [R_I] "=&a" (index)			\
147e83
+			    , [R_TMP] "=d" (tmp)			\
147e83
+			    , [R_LI] "+d" (remaining_loop_count)	\
147e83
+			  : /* inputs */ [R_BUF] "a" (buf)		\
147e83
+			    , [R_MAX] "d" (max)				\
147e83
+			  : /* clobber list*/ "memory", "cc"		\
147e83
+			    ASM_CLOBBER_VR ("v16") ASM_CLOBBER_VR ("v17") \
147e83
+			    ASM_CLOBBER_VR ("v18") ASM_CLOBBER_VR ("v19") \
147e83
+			    ASM_CLOBBER_VR ("v20") ASM_CLOBBER_VR ("v21") \
147e83
+			    ASM_CLOBBER_VR ("v22")			\
147e83
+			  );						\
147e83
+	/* Error occured in step 1? An error (ch >= max || ch == 0)	\
147e83
+	   occured, if remaining_loop_count > 0. The error occured	\
147e83
+	   at character-index (index) after already processed blocks.  */ \
147e83
+	loop_count -= remaining_loop_count;				\
147e83
+	if (loop_count > 0)						\
147e83
+	  {								\
147e83
+	    /* Step 2: Translate already processed blocks in buf and	\
147e83
+	       check for errors (from_ucs4[ch] == 0).  */		\
147e83
+	    __asm__ volatile (".machine push\n\t"			\
147e83
+			      ".machine \"z13\"\n\t"			\
147e83
+			      ".machinemode \"zarch_nohighgprs\"\n\t"	\
147e83
+			      "    sllk %[R_I],%[R_LI],4\n\t"		\
147e83
+			      "    ahi %[R_I],-1\n\t"			\
147e83
+			      /* Execute tr with correct len.  */	\
147e83
+			      "    exrl %[R_I],21f\n\t"			\
147e83
+			      /* Post-processing.  */			\
147e83
+			      "    lghi %[R_I],0\n\t"			\
147e83
+			      "0:  \n\t"				\
147e83
+			      /* Find invalid character - value == 0.  */ \
147e83
+			      "    vl %%v16,0(%[R_I],%[R_BUF])\n\t"	\
147e83
+			      "    vfenezbs %%v17,%%v16,%%v16\n\t"	\
147e83
+			      "    je 10f\n\t"				\
147e83
+			      /* Store 16bytes to buf_out.  */		\
147e83
+			      "    vst %%v16,0(%[R_I],%[R_OUT])\n\t"	\
147e83
+			      "    aghi %[R_I],16\n\t"			\
147e83
+			      "    brct %[R_LI],0b\n\t"			\
147e83
+			      "    la %[R_OUT],0(%[R_I],%[R_OUT])\n\t"	\
147e83
+			      "    j 20f\n\t"				\
147e83
+			      "21: tr 0(1,%[R_BUF]),0(%[R_TBL])\n\t"	\
147e83
+			      /* Found an error: from_ucs4[ch] == 0.  */ \
147e83
+			      "10: la %[R_OUT],0(%[R_I],%[R_OUT])\n\t"	\
147e83
+			      "    vlgvb %[R_I],%%v17,7\n\t"		\
147e83
+			      "20: \n\t"				\
147e83
+			      ".machine pop"				\
147e83
+			      : /* outputs */ [R_OUT] "+a" (outptr)	\
147e83
+				, [R_I] "=&a" (tmp)			\
147e83
+				, [R_LI] "+d" (loop_count)		\
147e83
+			      : /* inputs */ [R_BUF] "a" (buf)		\
147e83
+				, [R_TBL] "a" (from_ucs4)		\
147e83
+			      : /* clobber list*/ "memory", "cc"	\
147e83
+				ASM_CLOBBER_VR ("v16")			\
147e83
+				ASM_CLOBBER_VR ("v17")			\
147e83
+			      );					\
147e83
+	    /* Error occured in processed bytes of step 2?		\
147e83
+	       Thus possible error in step 1 is obselete.*/		\
147e83
+	    if (tmp < 16)						\
147e83
+	      {								\
147e83
+		index = tmp;						\
147e83
+		inptr -= loop_count * 64;				\
147e83
+	      }								\
147e83
+	  }								\
147e83
+	/* Error occured in step 1/2?  */				\
147e83
+	if (index < 16)							\
147e83
+	  {								\
147e83
+	    /* Found an invalid character (see step 2) or zero		\
147e83
+	       (see step 1) at index! Convert the chars before index	\
147e83
+	       manually. If there is a zero at index detected by step 1, \
147e83
+	       there could be invalid characters before this zero.  */	\
147e83
+	    int i;							\
147e83
+	    uint32_t ch;						\
147e83
+	    for (i = 0; i < index; i++)					\
147e83
+	      {								\
147e83
+		ch = get32 (inptr);					\
147e83
+		if (__builtin_expect (from_ucs4[ch], '\1') == '\0')     \
147e83
+		  break;						\
147e83
+		*outptr++ = from_ucs4[ch];				\
147e83
+		inptr += 4;						\
147e83
+	      }								\
147e83
+	    if (i == index)						\
147e83
+	      {								\
147e83
+		ch = get32 (inptr);					\
147e83
+		if (ch == 0)						\
147e83
+		  {							\
147e83
+		    /* This is no error, but handled differently.  */	\
147e83
+		    *outptr++ = from_ucs4[ch];				\
147e83
+		    inptr += 4;						\
147e83
+		    continue;						\
147e83
+		  }							\
147e83
+	      }								\
147e83
+									\
147e83
+	    UNICODE_TAG_HANDLER (ch, 4);				\
147e83
+									\
147e83
+	    /* This is an illegal character.  */			\
147e83
+	    STANDARD_TO_LOOP_ERR_HANDLER (4);				\
147e83
+	  }								\
147e83
+      }									\
147e83
+  }
147e83
+
147e83
+# define LOOP_NEED_FLAGS
147e83
+# include <iconv/loop.c>
147e83
+
147e83
+
147e83
+/* Generate ifunc'ed loop function.  */
147e83
+__typeof(__from_generic_c)
147e83
+__attribute__ ((ifunc ("__from_generic_resolver")))
147e83
+__from_generic;
147e83
+
147e83
+static void *
147e83
+__from_generic_resolver (unsigned long int dl_hwcap)
147e83
+{
147e83
+  if (sizeof (from_ucs4) / sizeof (from_ucs4[0]) <= 256
147e83
+      && dl_hwcap & HWCAP_S390_VX)
147e83
+    return &__from_generic_vx;
147e83
+  else
147e83
+    return &__from_generic_c;
147e83
+}
147e83
+
147e83
+__typeof(__to_generic_c)
147e83
+__attribute__ ((ifunc ("__to_generic_resolver")))
147e83
+__to_generic;
147e83
+
147e83
+static void *
147e83
+__to_generic_resolver (unsigned long int dl_hwcap)
147e83
+{
147e83
+  if (sizeof (from_ucs4) / sizeof (from_ucs4[0]) <= 256
147e83
+      && dl_hwcap & HWCAP_S390_VX)
147e83
+    return &__to_generic_vx;
147e83
+  else
147e83
+    return &__to_generic_c;
147e83
+}
147e83
+
147e83
+strong_alias (__to_generic_c_single, __to_generic_single)
147e83
+
147e83
+# undef FROM_LOOP
147e83
+# undef TO_LOOP
147e83
+# define FROM_LOOP		__from_generic
147e83
+# define TO_LOOP		__to_generic
147e83
+# include <iconv/skeleton.c>
147e83
+
147e83
+#else
147e83
+/* Generate this module without ifunc if build environment lacks vector
147e83
+   support. Instead the common 8bit-generic.c is used.  */
147e83
+# include "iconvdata/8bit-generic.c"
147e83
+#endif /* !defined HAVE_S390_VX_ASM_SUPPORT */
147e83
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
147e83
index 0805b07..11ad2b9 100644
147e83
--- a/sysdeps/s390/multiarch/Makefile
147e83
+++ b/sysdeps/s390/multiarch/Makefile
147e83
@@ -42,3 +42,13 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
147e83
 		   wmemset wmemset-vx wmemset-c \
147e83
 		   wmemcmp wmemcmp-vx wmemcmp-c
147e83
 endif
147e83
+
147e83
+ifeq ($(subdir),iconvdata)
147e83
+override define generate-8bit-table
147e83
+$(make-target-directory)
147e83
+LC_ALL=C $(SHELL) ./gen-8bit.sh $< > $(@:stmp=T)
147e83
+LC_ALL=C $(SHELL) ../sysdeps/s390/multiarch/gen-8bit.sh $< >> $(@:stmp=T)
147e83
+$(move-if-change) $(@:stmp=T) $(@:stmp=h)
147e83
+touch $@
147e83
+endef
147e83
+endif
147e83
diff --git a/sysdeps/s390/multiarch/gen-8bit.sh b/sysdeps/s390/multiarch/gen-8bit.sh
147e83
new file mode 100644
147e83
index 0000000..6f88c4b
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/gen-8bit.sh
147e83
@@ -0,0 +1,6 @@
147e83
+#!/bin/sh
147e83
+echo "static const uint8_t to_ucs1[256] = {"
147e83
+sed -ne '/^[^[:space:]]*[[:space:]]*.x00/d;/^END/q' \
147e83
+    -e 's/^<U00\(..\)>[[:space:]]*.x\(..\).*/  [0x\2] = 0x\1,/p' \
147e83
+    "$@" | sort -u
147e83
+echo "};"
147e83
diff --git a/sysdeps/s390/multiarch/iconv/skeleton.c b/sysdeps/s390/multiarch/iconv/skeleton.c
147e83
new file mode 100644
147e83
index 0000000..3a90031
147e83
--- /dev/null
147e83
+++ b/sysdeps/s390/multiarch/iconv/skeleton.c
147e83
@@ -0,0 +1,21 @@
147e83
+/* Skeleton for a conversion module - S390 version.
147e83
+   Copyright (C) 2016 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#ifndef IGNORE_ICONV_SKELETON
147e83
+# include_next <iconv/skeleton.c>
147e83
+#endif
147e83
-- 
147e83
1.8.3.1
147e83