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