8ae002
From c806cab89b52a644b5c563b8f1c8ae59abfc2c13 Mon Sep 17 00:00:00 2001
8ae002
From: Stefan Liebler <stli@linux.vnet.ibm.com>
8ae002
Date: Mon, 7 Nov 2016 16:22:17 +0100
8ae002
Subject: [PATCH 12/17] S390: Optimize utf16-utf32 module.
8ae002
8ae002
Upstream commit 6896776c3c9c32fd22324e6de6737dd69ae73213
8ae002
8ae002
This patch reworks the s390 specific module to convert between utf16 and utf32.
8ae002
Now ifunc is used to choose either the c or etf3eh (with convert utf
8ae002
instruction) variants at runtime.
8ae002
Furthermore a new vector variant for z13 is introduced which will be build
8ae002
and chosen if vector support is available at build / runtime.
8ae002
8ae002
In case of converting utf 32 to utf16, the vector variant optimizes input of
8ae002
2byte utf16 characters. The convert utf instruction is used if an utf16
8ae002
surrogate is found.
8ae002
8ae002
For the other direction utf16 to utf32, the cu24 instruction can't be re-
8ae002
enabled, because it does not report an error, if the input-stream consists of
8ae002
a single low surrogate utf16 char (e.g. 0xdc00). This applies to the newest z13,
8ae002
too. Thus there is only the c or the new vector variant, which can handle utf16
8ae002
surrogate characters.
8ae002
8ae002
This patch also fixes some whitespace errors. Furthermore, the etf3eh variant is
8ae002
handling the "UTF-xx//IGNORE" case now. Before they ignored the ignore-case and
8ae002
always stopped at an error.
8ae002
8ae002
ChangeLog:
8ae002
8ae002
	* sysdeps/s390/s390-64/utf16-utf32-z9.c: Use ifunc to select c,
8ae002
	etf3eh or new vector loop-variant.
8ae002
---
8ae002
 sysdeps/s390/s390-64/utf16-utf32-z9.c | 471 +++++++++++++++++++++++++++-------
8ae002
 1 file changed, 379 insertions(+), 92 deletions(-)
8ae002
8ae002
diff --git a/sysdeps/s390/s390-64/utf16-utf32-z9.c b/sysdeps/s390/s390-64/utf16-utf32-z9.c
8ae002
index e6a033d..33594f1 100644
8ae002
--- a/sysdeps/s390/s390-64/utf16-utf32-z9.c
8ae002
+++ b/sysdeps/s390/s390-64/utf16-utf32-z9.c
8ae002
@@ -30,47 +30,27 @@
8ae002
 #include <dl-procinfo.h>
8ae002
 #include <gconv.h>
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
 /* UTF-32 big endian byte order mark.  */
8ae002
 #define BOM_UTF32               0x0000feffu
8ae002
 
8ae002
 /* UTF-16 big endian byte order mark.  */
8ae002
-#define BOM_UTF16	        0xfeff
8ae002
+#define BOM_UTF16               0xfeff
8ae002
 
8ae002
 #define DEFINE_INIT		0
8ae002
 #define DEFINE_FINI		0
8ae002
 #define MIN_NEEDED_FROM		2
8ae002
 #define MAX_NEEDED_FROM		4
8ae002
 #define MIN_NEEDED_TO		4
8ae002
-#define FROM_LOOP		from_utf16_loop
8ae002
-#define TO_LOOP			to_utf16_loop
8ae002
+#define FROM_LOOP		__from_utf16_loop
8ae002
+#define TO_LOOP			__to_utf16_loop
8ae002
 #define FROM_DIRECTION		(dir == from_utf16)
8ae002
 #define ONE_DIRECTION           0
8ae002
-#define PREPARE_LOOP							\
8ae002
-  enum direction dir = ((struct utf16_data *) step->__data)->dir;	\
8ae002
-  int emit_bom = ((struct utf16_data *) step->__data)->emit_bom;	\
8ae002
-									\
8ae002
-  if (emit_bom && !data->__internal_use					\
8ae002
-      && data->__invocation_counter == 0)				\
8ae002
-    {									\
8ae002
-      if (dir == to_utf16)						\
8ae002
-	{								\
8ae002
-          /* Emit the UTF-16 Byte Order Mark.  */			\
8ae002
-          if (__glibc_unlikely (outbuf + 2 > outend))			      \
8ae002
-	    return __GCONV_FULL_OUTPUT;					\
8ae002
-									\
8ae002
-	  put16u (outbuf, BOM_UTF16);					\
8ae002
-	  outbuf += 2;							\
8ae002
-	}								\
8ae002
-      else								\
8ae002
-	{								\
8ae002
-          /* Emit the UTF-32 Byte Order Mark.  */			\
8ae002
-	  if (__glibc_unlikely (outbuf + 4 > outend))			      \
8ae002
-	    return __GCONV_FULL_OUTPUT;					\
8ae002
-									\
8ae002
-	  put32u (outbuf, BOM_UTF32);					\
8ae002
-	  outbuf += 4;							\
8ae002
-	}								\
8ae002
-    }
8ae002
 
8ae002
 /* Direction of the transformation.  */
8ae002
 enum direction
8ae002
@@ -169,16 +149,16 @@ gconv_end (struct __gconv_step *data)
8ae002
     register unsigned long long outlen __asm__("11") = outend - outptr;	\
8ae002
     uint64_t cc = 0;							\
8ae002
 									\
8ae002
-    __asm__ volatile (".machine push       \n\t"			\
8ae002
-		      ".machine \"z9-109\" \n\t"			\
8ae002
-		      "0: " INSTRUCTION "  \n\t"			\
8ae002
-		      ".machine pop        \n\t"			\
8ae002
-		      "   jo     0b        \n\t"			\
8ae002
-		      "   ipm    %2        \n"				\
8ae002
-		      : "+a" (pOutput), "+a" (pInput), "+d" (cc),	\
8ae002
-		      "+d" (outlen), "+d" (inlen)			\
8ae002
-		      :							\
8ae002
-		      : "cc", "memory");				\
8ae002
+    __asm__ __volatile__ (".machine push       \n\t"			\
8ae002
+			  ".machine \"z9-109\" \n\t"			\
8ae002
+			  "0: " INSTRUCTION "  \n\t"			\
8ae002
+			  ".machine pop        \n\t"			\
8ae002
+			  "   jo     0b        \n\t"			\
8ae002
+			  "   ipm    %2        \n"			\
8ae002
+			  : "+a" (pOutput), "+a" (pInput), "+d" (cc),	\
8ae002
+			    "+d" (outlen), "+d" (inlen)			\
8ae002
+			  :						\
8ae002
+			  : "cc", "memory");				\
8ae002
 									\
8ae002
     inptr = pInput;							\
8ae002
     outptr = pOutput;							\
8ae002
@@ -187,44 +167,46 @@ gconv_end (struct __gconv_step *data)
8ae002
     if (cc == 1)							\
8ae002
       {									\
8ae002
 	result = __GCONV_FULL_OUTPUT;					\
8ae002
-	break;								\
8ae002
       }									\
8ae002
     else if (cc == 2)							\
8ae002
       {									\
8ae002
 	result = __GCONV_ILLEGAL_INPUT;					\
8ae002
-	break;								\
8ae002
       }									\
8ae002
   }
8ae002
 
8ae002
+#define PREPARE_LOOP							\
8ae002
+  enum direction dir = ((struct utf16_data *) step->__data)->dir;	\
8ae002
+  int emit_bom = ((struct utf16_data *) step->__data)->emit_bom;	\
8ae002
+									\
8ae002
+  if (emit_bom && !data->__internal_use					\
8ae002
+      && data->__invocation_counter == 0)				\
8ae002
+    {									\
8ae002
+      if (dir == to_utf16)						\
8ae002
+	{								\
8ae002
+	  /* Emit the UTF-16 Byte Order Mark.  */			\
8ae002
+	  if (__glibc_unlikely (outbuf + 2 > outend))			\
8ae002
+	    return __GCONV_FULL_OUTPUT;					\
8ae002
+									\
8ae002
+	  put16u (outbuf, BOM_UTF16);					\
8ae002
+	  outbuf += 2;							\
8ae002
+	}								\
8ae002
+      else								\
8ae002
+	{								\
8ae002
+	  /* Emit the UTF-32 Byte Order Mark.  */			\
8ae002
+	  if (__glibc_unlikely (outbuf + 4 > outend))			\
8ae002
+	    return __GCONV_FULL_OUTPUT;					\
8ae002
+									\
8ae002
+	  put32u (outbuf, BOM_UTF32);					\
8ae002
+	  outbuf += 4;							\
8ae002
+	}								\
8ae002
+    }
8ae002
+
8ae002
 /* Conversion function from UTF-16 to UTF-32 internal/BE.  */
8ae002
 
8ae002
-#define MIN_NEEDED_INPUT	MIN_NEEDED_FROM
8ae002
-#define MAX_NEEDED_INPUT	MAX_NEEDED_FROM
8ae002
-#define MIN_NEEDED_OUTPUT	MIN_NEEDED_TO
8ae002
-#define LOOPFCT			FROM_LOOP
8ae002
 /* The software routine is copied from utf-16.c (minus bytes
8ae002
    swapping).  */
8ae002
-#define BODY								\
8ae002
+#define BODY_FROM_C							\
8ae002
   {									\
8ae002
-    /* The hardware instruction currently fails to report an error for	\
8ae002
-       isolated low surrogates so we have to disable the instruction	\
8ae002
-       until this gets resolved.  */					\
8ae002
-    if (0) /* (GLRO (dl_hwcap) & HWCAP_S390_ETF3EH) */			\
8ae002
-      {									\
8ae002
-	HARDWARE_CONVERT ("cu24 %0, %1, 1");				\
8ae002
-	if (inptr != inend)						\
8ae002
-	  {								\
8ae002
-	    /* Check if the third byte is				\
8ae002
-	       a valid start of a UTF-16 surrogate.  */			\
8ae002
-	    if (inend - inptr == 3 && (inptr[3] & 0xfc) != 0xdc)	\
8ae002
-	      STANDARD_FROM_LOOP_ERR_HANDLER (3);			\
8ae002
-									\
8ae002
-	    result = __GCONV_INCOMPLETE_INPUT;				\
8ae002
-	    break;							\
8ae002
-	  }								\
8ae002
-	continue;							\
8ae002
-      }									\
8ae002
-									\
8ae002
     uint16_t u1 = get16 (inptr);					\
8ae002
 									\
8ae002
     if (__builtin_expect (u1 < 0xd800, 1) || u1 > 0xdfff)		\
8ae002
@@ -235,15 +217,15 @@ gconv_end (struct __gconv_step *data)
8ae002
       }									\
8ae002
     else								\
8ae002
       {									\
8ae002
-        /* An isolated low-surrogate was found.  This has to be         \
8ae002
+	/* An isolated low-surrogate was found.  This has to be         \
8ae002
 	   considered ill-formed.  */					\
8ae002
-        if (__glibc_unlikely (u1 >= 0xdc00))				      \
8ae002
+	if (__glibc_unlikely (u1 >= 0xdc00))				\
8ae002
 	  {								\
8ae002
 	    STANDARD_FROM_LOOP_ERR_HANDLER (2);				\
8ae002
 	  }								\
8ae002
 	/* It's a surrogate character.  At least the first word says	\
8ae002
 	   it is.  */							\
8ae002
-	if (__glibc_unlikely (inptr + 4 > inend))			      \
8ae002
+	if (__glibc_unlikely (inptr + 4 > inend))			\
8ae002
 	  {								\
8ae002
 	    /* We don't have enough input for another complete input	\
8ae002
 	       character.  */						\
8ae002
@@ -266,48 +248,200 @@ gconv_end (struct __gconv_step *data)
8ae002
       }									\
8ae002
     outptr += 4;							\
8ae002
   }
8ae002
-#define LOOP_NEED_FLAGS
8ae002
-#include <iconv/loop.c>
8ae002
+
8ae002
+#define BODY_FROM_VX							\
8ae002
+  {									\
8ae002
+    size_t inlen = inend - inptr;					\
8ae002
+    size_t outlen = outend - outptr;					\
8ae002
+    unsigned long tmp, tmp2, tmp3;					\
8ae002
+    asm volatile (".machine push\n\t"					\
8ae002
+		  ".machine \"z13\"\n\t"				\
8ae002
+		  ".machinemode \"zarch_nohighgprs\"\n\t"		\
8ae002
+		  /* Setup to check for surrogates.  */			\
8ae002
+		  "    larl %[R_TMP],9f\n\t"				\
8ae002
+		  "    vlm %%v30,%%v31,0(%[R_TMP])\n\t"			\
8ae002
+		  /* Loop which handles UTF-16 chars <0xd800, >0xdfff.  */ \
8ae002
+		  "0:  clgijl %[R_INLEN],16,2f\n\t"			\
8ae002
+		  "    clgijl %[R_OUTLEN],32,2f\n\t"			\
8ae002
+		  "1:  vl %%v16,0(%[R_IN])\n\t"				\
8ae002
+		  /* Check for surrogate chars.  */			\
8ae002
+		  "    vstrchs %%v19,%%v16,%%v30,%%v31\n\t"		\
8ae002
+		  "    jno 10f\n\t"					\
8ae002
+		  /* Enlarge to UTF-32.  */				\
8ae002
+		  "    vuplhh %%v17,%%v16\n\t"				\
8ae002
+		  "    la %[R_IN],16(%[R_IN])\n\t"			\
8ae002
+		  "    vupllh %%v18,%%v16\n\t"				\
8ae002
+		  "    aghi %[R_INLEN],-16\n\t"				\
8ae002
+		  /* Store 32 bytes to buf_out.  */			\
8ae002
+		  "    vstm %%v17,%%v18,0(%[R_OUT])\n\t"		\
8ae002
+		  "    aghi %[R_OUTLEN],-32\n\t"			\
8ae002
+		  "    la %[R_OUT],32(%[R_OUT])\n\t"			\
8ae002
+		  "    clgijl %[R_INLEN],16,2f\n\t"			\
8ae002
+		  "    clgijl %[R_OUTLEN],32,2f\n\t"			\
8ae002
+		  "    j 1b\n\t"					\
8ae002
+		  /* Setup to check for ch >= 0xd800 && ch <= 0xdfff. (v30, v31)  */ \
8ae002
+		  "9:  .short 0xd800,0xdfff,0x0,0x0,0x0,0x0,0x0,0x0\n\t" \
8ae002
+		  "    .short 0xa000,0xc000,0x0,0x0,0x0,0x0,0x0,0x0\n\t" \
8ae002
+		  /* At least on uint16_t is in range of surrogates.	\
8ae002
+		     Store the preceding chars.  */			\
8ae002
+		  "10: vlgvb %[R_TMP],%%v19,7\n\t"			\
8ae002
+		  "    vuplhh %%v17,%%v16\n\t"				\
8ae002
+		  "    sllg %[R_TMP3],%[R_TMP],1\n\t" /* Number of out bytes.  */ \
8ae002
+		  "    ahik %[R_TMP2],%[R_TMP3],-1\n\t" /* Highest index to store.  */ \
8ae002
+		  "    jl 12f\n\t"					\
8ae002
+		  "    vstl %%v17,%[R_TMP2],0(%[R_OUT])\n\t"		\
8ae002
+		  "    vupllh %%v18,%%v16\n\t"				\
8ae002
+		  "    ahi %[R_TMP2],-16\n\t"				\
8ae002
+		  "    jl 11f\n\t"					\
8ae002
+		  "    vstl %%v18,%[R_TMP2],16(%[R_OUT])\n\t"		\
8ae002
+		  "11: \n\t" /* Update pointers.  */			\
8ae002
+		  "    la %[R_IN],0(%[R_TMP],%[R_IN])\n\t"		\
8ae002
+		  "    slgr %[R_INLEN],%[R_TMP]\n\t"			\
8ae002
+		  "    la %[R_OUT],0(%[R_TMP3],%[R_OUT])\n\t"		\
8ae002
+		  "    slgr %[R_OUTLEN],%[R_TMP3]\n\t"			\
8ae002
+		  /* Calculate remaining uint16_t values in loaded vrs.  */ \
8ae002
+		  "12: lghi %[R_TMP2],16\n\t"				\
8ae002
+		  "    sgr %[R_TMP2],%[R_TMP]\n\t"			\
8ae002
+		  "    srl %[R_TMP2],1\n\t"				\
8ae002
+		  "    llh %[R_TMP],0(%[R_IN])\n\t"			\
8ae002
+		  "    aghi %[R_OUTLEN],-4\n\t"				\
8ae002
+		  "    j 16f\n\t"					\
8ae002
+		  /* Handle remaining bytes.  */			\
8ae002
+		  "2:  \n\t"						\
8ae002
+		  /* Zero, one or more bytes available?  */		\
8ae002
+		  "    clgfi %[R_INLEN],1\n\t"				\
8ae002
+		  "    je 97f\n\t" /* Only one byte available.  */	\
8ae002
+		  "    jl 99f\n\t" /* End if no bytes available.  */	\
8ae002
+		  /* Calculate remaining uint16_t values in inptr.  */	\
8ae002
+		  "    srlg %[R_TMP2],%[R_INLEN],1\n\t"			\
8ae002
+		  /* Handle remaining uint16_t values.  */		\
8ae002
+		  "13: llh %[R_TMP],0(%[R_IN])\n\t"			\
8ae002
+		  "    slgfi %[R_OUTLEN],4\n\t"				\
8ae002
+		  "    jl 96f \n\t"					\
8ae002
+		  "    clfi %[R_TMP],0xd800\n\t"			\
8ae002
+		  "    jhe 15f\n\t"					\
8ae002
+		  "14: st %[R_TMP],0(%[R_OUT])\n\t"			\
8ae002
+		  "    la %[R_IN],2(%[R_IN])\n\t"			\
8ae002
+		  "    aghi %[R_INLEN],-2\n\t"				\
8ae002
+		  "    la %[R_OUT],4(%[R_OUT])\n\t"			\
8ae002
+		  "    brctg %[R_TMP2],13b\n\t"				\
8ae002
+		  "    j 0b\n\t" /* Switch to vx-loop.  */		\
8ae002
+		  /* Handle UTF-16 surrogate pair.  */			\
8ae002
+		  "15: clfi %[R_TMP],0xdfff\n\t"			\
8ae002
+		  "    jh 14b\n\t" /* Jump away if ch > 0xdfff.  */	\
8ae002
+		  "16: clfi %[R_TMP],0xdc00\n\t"			\
8ae002
+		  "    jhe 98f\n\t" /* Jump away in case of low-surrogate.  */ \
8ae002
+		  "    slgfi %[R_INLEN],4\n\t"				\
8ae002
+		  "    jl 97f\n\t" /* Big enough input?  */		\
8ae002
+		  "    llh %[R_TMP3],2(%[R_IN])\n\t" /* Load low surrogate.  */ \
8ae002
+		  "    slfi %[R_TMP],0xd7c0\n\t"			\
8ae002
+		  "    sll %[R_TMP],10\n\t"				\
8ae002
+		  "    risbgn %[R_TMP],%[R_TMP3],54,63,0\n\t" /* Insert klmnopqrst.  */ \
8ae002
+		  "    nilf %[R_TMP3],0xfc00\n\t"			\
8ae002
+		  "    clfi %[R_TMP3],0xdc00\n\t" /* Check if it starts with 0xdc00.  */ \
8ae002
+		  "    jne 98f\n\t"					\
8ae002
+		  "    st %[R_TMP],0(%[R_OUT])\n\t"			\
8ae002
+		  "    la %[R_IN],4(%[R_IN])\n\t"			\
8ae002
+		  "    la %[R_OUT],4(%[R_OUT])\n\t"			\
8ae002
+		  "    aghi %[R_TMP2],-2\n\t"				\
8ae002
+		  "    jh 13b\n\t" /* Handle remaining uint16_t values.  */ \
8ae002
+		  "    j 0b\n\t" /* Switch to vx-loop.  */		\
8ae002
+		  "96: \n\t" /* Return full output.  */			\
8ae002
+		  "    lghi %[R_RES],%[RES_OUT_FULL]\n\t"		\
8ae002
+		  "    j 99f\n\t"					\
8ae002
+		  "97: \n\t" /* Return incomplete input.  */		\
8ae002
+		  "    lghi %[R_RES],%[RES_IN_FULL]\n\t"		\
8ae002
+		  "    j 99f\n\t"					\
8ae002
+		  "98:\n\t" /* Return Illegal character.  */		\
8ae002
+		  "    lghi %[R_RES],%[RES_IN_ILL]\n\t"			\
8ae002
+		  "99:\n\t"						\
8ae002
+		  ".machine pop"					\
8ae002
+		  : /* outputs */ [R_IN] "+a" (inptr)			\
8ae002
+		    , [R_INLEN] "+d" (inlen), [R_OUT] "+a" (outptr)	\
8ae002
+		    , [R_OUTLEN] "+d" (outlen), [R_TMP] "=a" (tmp)	\
8ae002
+		    , [R_TMP2] "=d" (tmp2), [R_TMP3] "=a" (tmp3)	\
8ae002
+		    , [R_RES] "+d" (result)				\
8ae002
+		  : /* inputs */					\
8ae002
+		    [RES_OUT_FULL] "i" (__GCONV_FULL_OUTPUT)		\
8ae002
+		    , [RES_IN_ILL] "i" (__GCONV_ILLEGAL_INPUT)		\
8ae002
+		    , [RES_IN_FULL] "i" (__GCONV_INCOMPLETE_INPUT)	\
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 ("v30") ASM_CLOBBER_VR ("v31")	\
8ae002
+		  );							\
8ae002
+    if (__glibc_likely (inptr == inend)					\
8ae002
+	|| result != __GCONV_ILLEGAL_INPUT)				\
8ae002
+      break;								\
8ae002
+									\
8ae002
+    STANDARD_FROM_LOOP_ERR_HANDLER (2);					\
8ae002
+  }
8ae002
+
8ae002
+
8ae002
+/* Generate loop-function with software routing.  */
8ae002
+#define MIN_NEEDED_INPUT	MIN_NEEDED_FROM
8ae002
+#define MAX_NEEDED_INPUT	MAX_NEEDED_FROM
8ae002
+#define MIN_NEEDED_OUTPUT	MIN_NEEDED_TO
8ae002
+#if defined HAVE_S390_VX_ASM_SUPPORT
8ae002
+# define LOOPFCT		__from_utf16_loop_c
8ae002
+# define LOOP_NEED_FLAGS
8ae002
+# define BODY			BODY_FROM_C
8ae002
+# include <iconv/loop.c>
8ae002
+
8ae002
+/* Generate loop-function with hardware vector instructions.  */
8ae002
+# define MIN_NEEDED_INPUT	MIN_NEEDED_FROM
8ae002
+# define MAX_NEEDED_INPUT	MAX_NEEDED_FROM
8ae002
+# define MIN_NEEDED_OUTPUT	MIN_NEEDED_TO
8ae002
+# define LOOPFCT		__from_utf16_loop_vx
8ae002
+# define LOOP_NEED_FLAGS
8ae002
+# define BODY			BODY_FROM_VX
8ae002
+# include <iconv/loop.c>
8ae002
+
8ae002
+/* Generate ifunc'ed loop function.  */
8ae002
+__typeof(__from_utf16_loop_c)
8ae002
+__attribute__ ((ifunc ("__from_utf16_loop_resolver")))
8ae002
+__from_utf16_loop;
8ae002
+
8ae002
+static void *
8ae002
+__from_utf16_loop_resolver (unsigned long int dl_hwcap)
8ae002
+{
8ae002
+  if (dl_hwcap & HWCAP_S390_VX)
8ae002
+    return __from_utf16_loop_vx;
8ae002
+  else
8ae002
+    return __from_utf16_loop_c;
8ae002
+}
8ae002
+
8ae002
+strong_alias (__from_utf16_loop_c_single, __from_utf16_loop_single)
8ae002
+#else
8ae002
+# define LOOPFCT		FROM_LOOP
8ae002
+# define LOOP_NEED_FLAGS
8ae002
+# define BODY			BODY_FROM_C
8ae002
+# include <iconv/loop.c>
8ae002
+#endif
8ae002
 
8ae002
 /* Conversion from UTF-32 internal/BE to UTF-16.  */
8ae002
 
8ae002
-#define MIN_NEEDED_INPUT	MIN_NEEDED_TO
8ae002
-#define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
8ae002
-#define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
8ae002
-#define LOOPFCT			TO_LOOP
8ae002
 /* The software routine is copied from utf-16.c (minus bytes
8ae002
    swapping).  */
8ae002
-#define BODY								\
8ae002
+#define BODY_TO_C							\
8ae002
   {									\
8ae002
-    if (GLRO (dl_hwcap) & HWCAP_S390_ETF3EH)				\
8ae002
-      {									\
8ae002
-	HARDWARE_CONVERT ("cu42 %0, %1");				\
8ae002
-									\
8ae002
-	if (inptr != inend)						\
8ae002
-	  {								\
8ae002
-	    result = __GCONV_INCOMPLETE_INPUT;				\
8ae002
-	    break;							\
8ae002
-	  }								\
8ae002
-	continue;							\
8ae002
-      }									\
8ae002
-									\
8ae002
     uint32_t c = get32 (inptr);						\
8ae002
 									\
8ae002
     if (__builtin_expect (c <= 0xd7ff, 1)				\
8ae002
 	|| (c >=0xdc00 && c <= 0xffff))					\
8ae002
       {									\
8ae002
-        /* Two UTF-16 chars.  */					\
8ae002
-        put16 (outptr, c);						\
8ae002
+	/* Two UTF-16 chars.  */					\
8ae002
+	put16 (outptr, c);						\
8ae002
       }									\
8ae002
     else if (__builtin_expect (c >= 0x10000, 1)				\
8ae002
 	     && __builtin_expect (c <= 0x10ffff, 1))			\
8ae002
       {									\
8ae002
 	/* Four UTF-16 chars.  */					\
8ae002
-        uint16_t zabcd = ((c & 0x1f0000) >> 16) - 1;			\
8ae002
+	uint16_t zabcd = ((c & 0x1f0000) >> 16) - 1;			\
8ae002
 	uint16_t out;							\
8ae002
 									\
8ae002
 	/* Generate a surrogate character.  */				\
8ae002
-	if (__glibc_unlikely (outptr + 4 > outend))			      \
8ae002
+	if (__glibc_unlikely (outptr + 4 > outend))			\
8ae002
 	  {								\
8ae002
 	    /* Overflow in the output buffer.  */			\
8ae002
 	    result = __GCONV_FULL_OUTPUT;				\
8ae002
@@ -326,12 +460,165 @@ gconv_end (struct __gconv_step *data)
8ae002
       }									\
8ae002
     else								\
8ae002
       {									\
8ae002
-        STANDARD_TO_LOOP_ERR_HANDLER (4);				\
8ae002
+	STANDARD_TO_LOOP_ERR_HANDLER (4);				\
8ae002
       }									\
8ae002
     outptr += 2;							\
8ae002
     inptr += 4;								\
8ae002
   }
8ae002
+
8ae002
+#define BODY_TO_ETF3EH							\
8ae002
+  {									\
8ae002
+    HARDWARE_CONVERT ("cu42 %0, %1");					\
8ae002
+									\
8ae002
+    if (__glibc_likely (inptr == inend)					\
8ae002
+	|| result == __GCONV_FULL_OUTPUT)				\
8ae002
+      break;								\
8ae002
+									\
8ae002
+    if (inptr + 4 > inend)						\
8ae002
+      {									\
8ae002
+	result = __GCONV_INCOMPLETE_INPUT;				\
8ae002
+	break;								\
8ae002
+      }									\
8ae002
+									\
8ae002
+    STANDARD_TO_LOOP_ERR_HANDLER (4);					\
8ae002
+  }
8ae002
+
8ae002
+#define BODY_TO_VX							\
8ae002
+  {									\
8ae002
+    register const unsigned char* pInput asm ("8") = inptr;		\
8ae002
+    register size_t inlen asm ("9") = inend - inptr;			\
8ae002
+    register unsigned char* pOutput asm ("10") = outptr;		\
8ae002
+    register size_t outlen asm("11") = outend - outptr;			\
8ae002
+    unsigned long tmp, tmp2, tmp3;					\
8ae002
+    asm volatile (".machine push\n\t"					\
8ae002
+		  ".machine \"z13\"\n\t"				\
8ae002
+		  ".machinemode \"zarch_nohighgprs\"\n\t"		\
8ae002
+		  /* Setup to check for surrogates.  */			\
8ae002
+		  "    larl %[R_TMP],9f\n\t"				\
8ae002
+		  "    vlm %%v30,%%v31,0(%[R_TMP])\n\t"			\
8ae002
+		  /* Loop which handles UTF-16 chars			\
8ae002
+		     ch < 0xd800 || (ch > 0xdfff && ch < 0x10000).  */	\
8ae002
+		  "0:  clgijl %[R_INLEN],32,20f\n\t"			\
8ae002
+		  "    clgijl %[R_OUTLEN],16,20f\n\t"			\
8ae002
+		  "1:  vlm %%v16,%%v17,0(%[R_IN])\n\t"			\
8ae002
+		  "    lghi %[R_TMP2],0\n\t"				\
8ae002
+		  /* Shorten to UTF-16.  */				\
8ae002
+		  "    vpkf %%v18,%%v16,%%v17\n\t"			\
8ae002
+		  /* Check for surrogate chars.  */			\
8ae002
+		  "    vstrcfs %%v19,%%v16,%%v30,%%v31\n\t"		\
8ae002
+		  "    jno 10f\n\t"					\
8ae002
+		  "    vstrcfs %%v19,%%v17,%%v30,%%v31\n\t"		\
8ae002
+		  "    jno 11f\n\t"					\
8ae002
+		  /* Store 16 bytes to buf_out.  */			\
8ae002
+		  "    vst %%v18,0(%[R_OUT])\n\t"			\
8ae002
+		  "    la %[R_IN],32(%[R_IN])\n\t"			\
8ae002
+		  "    aghi %[R_INLEN],-32\n\t"				\
8ae002
+		  "    aghi %[R_OUTLEN],-16\n\t"			\
8ae002
+		  "    la %[R_OUT],16(%[R_OUT])\n\t"			\
8ae002
+		  "    clgijl %[R_INLEN],32,20f\n\t"			\
8ae002
+		  "    clgijl %[R_OUTLEN],16,20f\n\t"			\
8ae002
+		  "    j 1b\n\t"					\
8ae002
+		  /* Setup to check for ch >= 0xd800 && ch <= 0xdfff	\
8ae002
+		     and check for ch >= 0x10000. (v30, v31)  */	\
8ae002
+		  "9:  .long 0xd800,0xdfff,0x10000,0x10000\n\t"		\
8ae002
+		  "    .long 0xa0000000,0xc0000000, 0xa0000000,0xa0000000\n\t" \
8ae002
+		  /* At least on UTF32 char is in range of surrogates.	\
8ae002
+		     Store the preceding characters.  */		\
8ae002
+		  "11: ahi %[R_TMP2],16\n\t"				\
8ae002
+		  "10: vlgvb %[R_TMP],%%v19,7\n\t"			\
8ae002
+		  "    agr %[R_TMP],%[R_TMP2]\n\t"			\
8ae002
+		  "    srlg %[R_TMP3],%[R_TMP],1\n\t" /* Number of out bytes.  */ \
8ae002
+		  "    ahik %[R_TMP2],%[R_TMP3],-1\n\t" /* Highest index to store.  */ \
8ae002
+		  "    jl 20f\n\t"					\
8ae002
+		  "    vstl %%v18,%[R_TMP2],0(%[R_OUT])\n\t"		\
8ae002
+		  /* Update pointers.  */				\
8ae002
+		  "    la %[R_IN],0(%[R_TMP],%[R_IN])\n\t"		\
8ae002
+		  "    slgr %[R_INLEN],%[R_TMP]\n\t"			\
8ae002
+		  "    la %[R_OUT],0(%[R_TMP3],%[R_OUT])\n\t"		\
8ae002
+		  "    slgr %[R_OUTLEN],%[R_TMP3]\n\t"			\
8ae002
+		  /* Handles UTF16 surrogates with convert instruction.  */ \
8ae002
+		  "20: cu42 %[R_OUT],%[R_IN]\n\t"			\
8ae002
+		  "    jo 0b\n\t" /* Try vector implemenation again.  */ \
8ae002
+		  "    lochil %[R_RES],%[RES_OUT_FULL]\n\t" /* cc == 1.  */ \
8ae002
+		  "    lochih %[R_RES],%[RES_IN_ILL]\n\t" /* cc == 2.  */ \
8ae002
+		  ".machine pop"					\
8ae002
+		  : /* outputs */ [R_IN] "+a" (pInput)			\
8ae002
+		    , [R_INLEN] "+d" (inlen), [R_OUT] "+a" (pOutput)	\
8ae002
+		    , [R_OUTLEN] "+d" (outlen), [R_TMP] "=a" (tmp)	\
8ae002
+		    , [R_TMP2] "=d" (tmp2), [R_TMP3] "=a" (tmp3)	\
8ae002
+		    , [R_RES] "+d" (result)				\
8ae002
+		  : /* inputs */					\
8ae002
+		    [RES_OUT_FULL] "i" (__GCONV_FULL_OUTPUT)		\
8ae002
+		    , [RES_IN_ILL] "i" (__GCONV_ILLEGAL_INPUT)		\
8ae002
+		    , [RES_IN_FULL] "i" (__GCONV_INCOMPLETE_INPUT)	\
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 ("v30") ASM_CLOBBER_VR ("v31")	\
8ae002
+		  );							\
8ae002
+    inptr = pInput;							\
8ae002
+    outptr = pOutput;							\
8ae002
+									\
8ae002
+    if (__glibc_likely (inptr == inend)					\
8ae002
+	|| result == __GCONV_FULL_OUTPUT)				\
8ae002
+      break;								\
8ae002
+    if (inptr + 4 > inend)						\
8ae002
+      {									\
8ae002
+	result = __GCONV_INCOMPLETE_INPUT;				\
8ae002
+	break;								\
8ae002
+      }									\
8ae002
+    STANDARD_TO_LOOP_ERR_HANDLER (4);					\
8ae002
+  }
8ae002
+
8ae002
+/* Generate loop-function with software routing.  */
8ae002
+#define MIN_NEEDED_INPUT	MIN_NEEDED_TO
8ae002
+#define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
8ae002
+#define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
8ae002
+#define LOOPFCT			__to_utf16_loop_c
8ae002
+#define LOOP_NEED_FLAGS
8ae002
+#define BODY			BODY_TO_C
8ae002
+#include <iconv/loop.c>
8ae002
+
8ae002
+/* Generate loop-function with hardware utf-convert instruction.  */
8ae002
+#define MIN_NEEDED_INPUT	MIN_NEEDED_TO
8ae002
+#define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
8ae002
+#define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
8ae002
+#define LOOPFCT			__to_utf16_loop_etf3eh
8ae002
 #define LOOP_NEED_FLAGS
8ae002
+#define BODY			BODY_TO_ETF3EH
8ae002
 #include <iconv/loop.c>
8ae002
 
8ae002
+#if defined HAVE_S390_VX_ASM_SUPPORT
8ae002
+/* Generate loop-function with hardware vector instructions.  */
8ae002
+# define MIN_NEEDED_INPUT	MIN_NEEDED_TO
8ae002
+# define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
8ae002
+# define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
8ae002
+# define LOOPFCT		__to_utf16_loop_vx
8ae002
+# define LOOP_NEED_FLAGS
8ae002
+# define BODY			BODY_TO_VX
8ae002
+# include <iconv/loop.c>
8ae002
+#endif
8ae002
+
8ae002
+/* Generate ifunc'ed loop function.  */
8ae002
+__typeof(__to_utf16_loop_c)
8ae002
+__attribute__ ((ifunc ("__to_utf16_loop_resolver")))
8ae002
+__to_utf16_loop;
8ae002
+
8ae002
+static void *
8ae002
+__to_utf16_loop_resolver (unsigned long int dl_hwcap)
8ae002
+{
8ae002
+#if defined HAVE_S390_VX_ASM_SUPPORT
8ae002
+  if (dl_hwcap & HWCAP_S390_VX)
8ae002
+    return __to_utf16_loop_vx;
8ae002
+  else
8ae002
+#endif
8ae002
+  if (dl_hwcap & HWCAP_S390_ETF3EH)
8ae002
+    return __to_utf16_loop_etf3eh;
8ae002
+  else
8ae002
+    return __to_utf16_loop_c;
8ae002
+}
8ae002
+
8ae002
+strong_alias (__to_utf16_loop_c_single, __to_utf16_loop_single)
8ae002
+
8ae002
+
8ae002
 #include <iconv/skeleton.c>
8ae002
-- 
8ae002
1.8.3.1
8ae002