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