00db10
From ed26260ce20cd6c05e8c8526bd2bd9fadfee8d19 Mon Sep 17 00:00:00 2001
00db10
From: Stefan Liebler <stli@linux.vnet.ibm.com>
00db10
Date: Thu, 27 Jul 2017 10:53:59 +0200
00db10
Subject: [PATCH 08/10] S390: Use cu42 instruction for converting from utf32 to
00db10
 utf16.
00db10
00db10
upstream-commit 593e4da186906525e2a0bdc4d87601bd0c2625eb
00db10
00db10
This patch adds an ifunc variant to use the cu instruction on arch12 CPUs.
00db10
This new ifunc variant can be built if binutils support z13 vector
00db10
instructions.  At runtime, HWCAP_S390_VXE decides if we can use the
00db10
cu42 instruction.
00db10
00db10
ChangeLog:
00db10
00db10
	* sysdeps/s390/utf16-utf32-z9.c (__to_utf16_loop_vx_cu):
00db10
	Use vector and cu42 instruction.
00db10
	* sysdeps/s390/multiarch/utf16-utf32-z9.c:
00db10
	Add __to_utf16_loop_vx_cu in ifunc resolver.
00db10
---
00db10
 sysdeps/s390/multiarch/utf16-utf32-z9.c |   8 ++-
00db10
 sysdeps/s390/utf16-utf32-z9.c           | 107 +++++++++++++++++++++++++++++++-
00db10
 2 files changed, 111 insertions(+), 4 deletions(-)
00db10
00db10
diff --git a/sysdeps/s390/multiarch/utf16-utf32-z9.c b/sysdeps/s390/multiarch/utf16-utf32-z9.c
00db10
index 6e64169..ded3cc2 100644
00db10
--- a/sysdeps/s390/multiarch/utf16-utf32-z9.c
00db10
+++ b/sysdeps/s390/multiarch/utf16-utf32-z9.c
00db10
@@ -37,8 +37,10 @@ s390_libc_ifunc_expr (FROM_LOOP_DEFAULT, FROM_LOOP,
00db10
 		      : FROM_LOOP_DEFAULT);
00db10
 
00db10
 s390_libc_ifunc_expr (TO_LOOP_DEFAULT, TO_LOOP,
00db10
-		      (HAVE_TO_VX && (hwcap & HWCAP_S390_VX))
00db10
-		      ? TO_LOOP_VX
00db10
-		      : TO_LOOP_DEFAULT);
00db10
+		      (HAVE_TO_VX_CU && (hwcap & HWCAP_S390_VXE))
00db10
+		      ? TO_LOOP_VX_CU
00db10
+		      : (HAVE_TO_VX && (hwcap & HWCAP_S390_VX))
00db10
+			? TO_LOOP_VX
00db10
+			: TO_LOOP_DEFAULT);
00db10
 
00db10
 #include <iconv/skeleton.c>
00db10
diff --git a/sysdeps/s390/utf16-utf32-z9.c b/sysdeps/s390/utf16-utf32-z9.c
00db10
index 5a39d5d..b1728d6 100644
00db10
--- a/sysdeps/s390/utf16-utf32-z9.c
00db10
+++ b/sysdeps/s390/utf16-utf32-z9.c
00db10
@@ -40,9 +40,11 @@
00db10
 #if defined HAVE_S390_VX_ASM_SUPPORT && defined USE_MULTIARCH
00db10
 # define HAVE_FROM_VX		1
00db10
 # define HAVE_TO_VX		1
00db10
+# define HAVE_TO_VX_CU		1
00db10
 #else
00db10
 # define HAVE_FROM_VX		0
00db10
 # define HAVE_TO_VX		0
00db10
+# define HAVE_TO_VX_CU		0
00db10
 #endif
00db10
 
00db10
 #if defined HAVE_S390_VX_GCC_SUPPORT
00db10
@@ -471,7 +473,7 @@ gconv_end (struct __gconv_step *data)
00db10
 		  "    vlm %%v30,%%v31,0(%[R_TMP])\n\t"			\
00db10
 		  CONVERT_32BIT_SIZE_T ([R_INLEN])			\
00db10
 		  CONVERT_32BIT_SIZE_T ([R_OUTLEN])			\
00db10
-		  /* Loop which handles UTF-16 chars			\
00db10
+		  /* Loop which handles UTF-32 chars			\
00db10
 		     ch < 0xd800 || (ch > 0xdfff && ch < 0x10000).  */	\
00db10
 		  "0:  clgijl %[R_INLEN],32,2f\n\t"			\
00db10
 		  "    clgijl %[R_OUTLEN],16,2f\n\t"			\
00db10
@@ -595,6 +597,109 @@ gconv_end (struct __gconv_step *data)
00db10
 # define TO_LOOP_VX		NULL
00db10
 #endif /* HAVE_TO_VX != 1  */
00db10
 
00db10
+#if HAVE_TO_VX_CU == 1
00db10
+#define BODY_TO_VX_CU							\
00db10
+  {									\
00db10
+    register const unsigned char* pInput asm ("8") = inptr;		\
00db10
+    register size_t inlen asm ("9") = inend - inptr;			\
00db10
+    register unsigned char* pOutput asm ("10") = outptr;		\
00db10
+    register size_t outlen asm ("11") = outend - outptr;		\
00db10
+    unsigned long tmp, tmp2, tmp3;					\
00db10
+    asm volatile (".machine push\n\t"					\
00db10
+		  ".machine \"z13\"\n\t"				\
00db10
+		  ".machinemode \"zarch_nohighgprs\"\n\t"		\
00db10
+		  /* Setup to check for surrogates.  */			\
00db10
+		  "    larl %[R_TMP],9f\n\t"				\
00db10
+		  "    vlm %%v30,%%v31,0(%[R_TMP])\n\t"			\
00db10
+		  CONVERT_32BIT_SIZE_T ([R_INLEN])			\
00db10
+		  CONVERT_32BIT_SIZE_T ([R_OUTLEN])			\
00db10
+		  /* Loop which handles UTF-32 chars			\
00db10
+		     ch < 0xd800 || (ch > 0xdfff && ch < 0x10000).  */	\
00db10
+		  "0:  clgijl %[R_INLEN],32,20f\n\t"			\
00db10
+		  "    clgijl %[R_OUTLEN],16,20f\n\t"			\
00db10
+		  "1:  vlm %%v16,%%v17,0(%[R_IN])\n\t"			\
00db10
+		  "    lghi %[R_TMP2],0\n\t"				\
00db10
+		  /* Shorten to UTF-16.  */				\
00db10
+		  "    vpkf %%v18,%%v16,%%v17\n\t"			\
00db10
+		  /* Check for surrogate chars.  */			\
00db10
+		  "    vstrcfs %%v19,%%v16,%%v30,%%v31\n\t"		\
00db10
+		  "    jno 10f\n\t"					\
00db10
+		  "    vstrcfs %%v19,%%v17,%%v30,%%v31\n\t"		\
00db10
+		  "    jno 11f\n\t"					\
00db10
+		  /* Store 16 bytes to buf_out.  */			\
00db10
+		  "    vst %%v18,0(%[R_OUT])\n\t"			\
00db10
+		  "    la %[R_IN],32(%[R_IN])\n\t"			\
00db10
+		  "    aghi %[R_INLEN],-32\n\t"				\
00db10
+		  "    aghi %[R_OUTLEN],-16\n\t"			\
00db10
+		  "    la %[R_OUT],16(%[R_OUT])\n\t"			\
00db10
+		  "    clgijl %[R_INLEN],32,20f\n\t"			\
00db10
+		  "    clgijl %[R_OUTLEN],16,20f\n\t"			\
00db10
+		  "    j 1b\n\t"					\
00db10
+		  /* Setup to check for ch >= 0xd800 && ch <= 0xdfff	\
00db10
+		     and check for ch >= 0x10000. (v30, v31)  */	\
00db10
+		  "9:  .long 0xd800,0xdfff,0x10000,0x10000\n\t"		\
00db10
+		  "    .long 0xa0000000,0xc0000000, 0xa0000000,0xa0000000\n\t" \
00db10
+		  /* At least one UTF32 char is in range of surrogates.	\
00db10
+		     Store the preceding characters.  */		\
00db10
+		  "11: ahi %[R_TMP2],16\n\t"				\
00db10
+		  "10: vlgvb %[R_TMP],%%v19,7\n\t"			\
00db10
+		  "    agr %[R_TMP],%[R_TMP2]\n\t"			\
00db10
+		  "    srlg %[R_TMP3],%[R_TMP],1\n\t" /* Number of out bytes.  */ \
00db10
+		  "    ahik %[R_TMP2],%[R_TMP3],-1\n\t" /* Highest index to store.  */ \
00db10
+		  "    jl 20f\n\t"					\
00db10
+		  "    vstl %%v18,%[R_TMP2],0(%[R_OUT])\n\t"		\
00db10
+		  /* Update pointers.  */				\
00db10
+		  "    la %[R_IN],0(%[R_TMP],%[R_IN])\n\t"		\
00db10
+		  "    slgr %[R_INLEN],%[R_TMP]\n\t"			\
00db10
+		  "    la %[R_OUT],0(%[R_TMP3],%[R_OUT])\n\t"		\
00db10
+		  "    slgr %[R_OUTLEN],%[R_TMP3]\n\t"			\
00db10
+		  /* Handles UTF16 surrogates with convert instruction.  */ \
00db10
+		  "20: cu42 %[R_OUT],%[R_IN]\n\t"			\
00db10
+		  "    jo 0b\n\t" /* Try vector implemenation again.  */ \
00db10
+		  "    lochil %[R_RES],%[RES_OUT_FULL]\n\t" /* cc == 1.  */ \
00db10
+		  "    lochih %[R_RES],%[RES_IN_ILL]\n\t" /* cc == 2.  */ \
00db10
+		  ".machine pop"					\
00db10
+		  : /* outputs */ [R_IN] "+a" (pInput)			\
00db10
+		    , [R_INLEN] "+d" (inlen), [R_OUT] "+a" (pOutput)	\
00db10
+		    , [R_OUTLEN] "+d" (outlen), [R_TMP] "=a" (tmp)	\
00db10
+		    , [R_TMP2] "=d" (tmp2), [R_TMP3] "=a" (tmp3)	\
00db10
+		    , [R_RES] "+d" (result)				\
00db10
+		  : /* inputs */					\
00db10
+		    [RES_OUT_FULL] "i" (__GCONV_FULL_OUTPUT)		\
00db10
+		    , [RES_IN_ILL] "i" (__GCONV_ILLEGAL_INPUT)		\
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 ("v30") ASM_CLOBBER_VR ("v31")	\
00db10
+		  );							\
00db10
+    inptr = pInput;							\
00db10
+    outptr = pOutput;							\
00db10
+									\
00db10
+    if (__glibc_likely (inlen == 0)					\
00db10
+	|| result == __GCONV_FULL_OUTPUT)				\
00db10
+      break;								\
00db10
+    if (inlen < 4)							\
00db10
+      {									\
00db10
+	result = __GCONV_INCOMPLETE_INPUT;				\
00db10
+	break;								\
00db10
+      }									\
00db10
+									\
00db10
+    STANDARD_TO_LOOP_ERR_HANDLER (4);					\
00db10
+  }
00db10
+
00db10
+/* Generate loop-function with hardware vector and utf-convert instructions.  */
00db10
+# define MIN_NEEDED_INPUT	MIN_NEEDED_TO
00db10
+# define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
00db10
+# define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
00db10
+# define TO_LOOP_VX_CU		__to_utf16_loop_vx_cu
00db10
+# define LOOPFCT		TO_LOOP_VX_CU
00db10
+# define LOOP_NEED_FLAGS
00db10
+# define BODY			BODY_TO_VX_CU
00db10
+# include <iconv/loop.c>
00db10
+#else
00db10
+# define TO_LOOP_VX_CU		NULL
00db10
+#endif /* HAVE_TO_VX_CU != 1  */
00db10
+
00db10
 /* This file also exists in sysdeps/s390/multiarch/ which
00db10
    generates ifunc resolvers for FROM/TO_LOOP functions
00db10
    and includes iconv/skeleton.c afterwards.  */
00db10
-- 
00db10
1.8.3.1
00db10