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