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