olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1375235-7.patch

51f0aa
From 9b9fd1ec26b5386072fa967bac0771df5e86a284 Mon Sep 17 00:00:00 2001
51f0aa
From: Stefan Liebler <stli@linux.vnet.ibm.com>
51f0aa
Date: Thu, 27 Jul 2017 10:53:58 +0200
51f0aa
Subject: [PATCH 07/10] S390: Use cu41 instruction for converting from utf32 to
51f0aa
 utf8.
51f0aa
51f0aa
upstream-commit 23ea69a9d6e9ab28c66a232b767a800b04eaa938
51f0aa
51f0aa
This patch adds an ifunc variant to use the cu instruction on arch12 CPUs.
51f0aa
This new ifunc variant can be built if binutils support z13 vector
51f0aa
instructions.  At runtime, HWCAP_S390_VXE decides if we can use the
51f0aa
cu41 instruction.
51f0aa
51f0aa
ChangeLog:
51f0aa
51f0aa
	* sysdeps/s390/utf8-utf32-z9.c (__to_utf8_loop_vx_cu):
51f0aa
	Use vector and cu41 instruction.
51f0aa
	* sysdeps/s390/multiarch/utf8-utf32-z9.c: Add __to_utf8_loop_vx_cu
51f0aa
	in ifunc resolver.
51f0aa
---
51f0aa
 sysdeps/s390/multiarch/utf8-utf32-z9.c |   8 ++-
51f0aa
 sysdeps/s390/utf8-utf32-z9.c           | 112 +++++++++++++++++++++++++++++++++
51f0aa
 2 files changed, 117 insertions(+), 3 deletions(-)
51f0aa
51f0aa
diff --git a/sysdeps/s390/multiarch/utf8-utf32-z9.c b/sysdeps/s390/multiarch/utf8-utf32-z9.c
51f0aa
index faf1f46..0c6d9e9 100644
51f0aa
--- a/sysdeps/s390/multiarch/utf8-utf32-z9.c
51f0aa
+++ b/sysdeps/s390/multiarch/utf8-utf32-z9.c
51f0aa
@@ -41,8 +41,10 @@ s390_libc_ifunc_expr (FROM_LOOP_DEFAULT, FROM_LOOP,
51f0aa
 			: FROM_LOOP_DEFAULT);
51f0aa
 
51f0aa
 s390_libc_ifunc_expr (TO_LOOP_DEFAULT, TO_LOOP,
51f0aa
-		      (HAVE_TO_VX && (hwcap & HWCAP_S390_VX))
51f0aa
-		      ? TO_LOOP_VX
51f0aa
-		      : TO_LOOP_DEFAULT);
51f0aa
+		      (HAVE_TO_VX_CU && (hwcap & HWCAP_S390_VXE))
51f0aa
+		      ? TO_LOOP_VX_CU
51f0aa
+		      : (HAVE_TO_VX && (hwcap & HWCAP_S390_VX))
51f0aa
+			? TO_LOOP_VX
51f0aa
+			: TO_LOOP_DEFAULT);
51f0aa
 
51f0aa
 #include <iconv/skeleton.c>
51f0aa
diff --git a/sysdeps/s390/utf8-utf32-z9.c b/sysdeps/s390/utf8-utf32-z9.c
51f0aa
index e06d11e..e4f2e0c 100644
51f0aa
--- a/sysdeps/s390/utf8-utf32-z9.c
51f0aa
+++ b/sysdeps/s390/utf8-utf32-z9.c
51f0aa
@@ -52,9 +52,11 @@
51f0aa
 #if defined HAVE_S390_VX_ASM_SUPPORT && defined USE_MULTIARCH
51f0aa
 # define HAVE_FROM_VX		1
51f0aa
 # define HAVE_TO_VX		1
51f0aa
+# define HAVE_TO_VX_CU		1
51f0aa
 #else
51f0aa
 # define HAVE_FROM_VX		0
51f0aa
 # define HAVE_TO_VX		0
51f0aa
+# define HAVE_TO_VX_CU		0
51f0aa
 #endif
51f0aa
 
51f0aa
 #if defined HAVE_S390_VX_GCC_SUPPORT
51f0aa
@@ -863,6 +865,116 @@ gconv_end (struct __gconv_step *data)
51f0aa
 # define TO_LOOP_VX		NULL
51f0aa
 #endif /* HAVE_TO_VX != 1  */
51f0aa
 
51f0aa
+#if HAVE_TO_VX_CU == 1
51f0aa
+#define BODY_TO_VX_CU							\
51f0aa
+  {									\
51f0aa
+    register const unsigned char* pInput asm ("8") = inptr;		\
51f0aa
+    register size_t inlen asm ("9") = inend - inptr;			\
51f0aa
+    register unsigned char* pOutput asm ("10") = outptr;		\
51f0aa
+    register size_t outlen asm ("11") = outend - outptr;		\
51f0aa
+    unsigned long tmp, tmp2;						\
51f0aa
+    asm volatile (".machine push\n\t"					\
51f0aa
+		  ".machine \"z13\"\n\t"				\
51f0aa
+		  ".machinemode \"zarch_nohighgprs\"\n\t"		\
51f0aa
+		  "    vleif %%v20,127,0\n\t"   /* element 0: 127  */	\
51f0aa
+		  "    vzero %%v21\n\t"					\
51f0aa
+		  "    vleih %%v21,8192,0\n\t"  /* element 0:   >  */	\
51f0aa
+		  "    vleih %%v21,-8192,2\n\t" /* element 1: =<>  */	\
51f0aa
+		  CONVERT_32BIT_SIZE_T ([R_INLEN])			\
51f0aa
+		  CONVERT_32BIT_SIZE_T ([R_OUTLEN])			\
51f0aa
+		  /* Loop which handles UTF-32 chars <= 0x7f.  */	\
51f0aa
+		  "0:  clgijl %[R_INLEN],64,20f\n\t"			\
51f0aa
+		  "    clgijl %[R_OUTLEN],16,20f\n\t"			\
51f0aa
+		  "1:  vlm %%v16,%%v19,0(%[R_IN])\n\t"			\
51f0aa
+		  "    lghi %[R_TMP],0\n\t"				\
51f0aa
+		  /* Shorten to byte values.  */			\
51f0aa
+		  "    vpkf %%v23,%%v16,%%v17\n\t"			\
51f0aa
+		  "    vpkf %%v24,%%v18,%%v19\n\t"			\
51f0aa
+		  "    vpkh %%v23,%%v23,%%v24\n\t"			\
51f0aa
+		  /* Checking for values > 0x7f.  */			\
51f0aa
+		  "    vstrcfs %%v22,%%v16,%%v20,%%v21\n\t"		\
51f0aa
+		  "    jno 10f\n\t"					\
51f0aa
+		  "    vstrcfs %%v22,%%v17,%%v20,%%v21\n\t"		\
51f0aa
+		  "    jno 11f\n\t"					\
51f0aa
+		  "    vstrcfs %%v22,%%v18,%%v20,%%v21\n\t"		\
51f0aa
+		  "    jno 12f\n\t"					\
51f0aa
+		  "    vstrcfs %%v22,%%v19,%%v20,%%v21\n\t"		\
51f0aa
+		  "    jno 13f\n\t"					\
51f0aa
+		  /* Store 16bytes to outptr.  */			\
51f0aa
+		  "    vst %%v23,0(%[R_OUT])\n\t"			\
51f0aa
+		  "    aghi %[R_INLEN],-64\n\t"				\
51f0aa
+		  "    aghi %[R_OUTLEN],-16\n\t"			\
51f0aa
+		  "    la %[R_IN],64(%[R_IN])\n\t"			\
51f0aa
+		  "    la %[R_OUT],16(%[R_OUT])\n\t"			\
51f0aa
+		  "    clgijl %[R_INLEN],64,20f\n\t"			\
51f0aa
+		  "    clgijl %[R_OUTLEN],16,20f\n\t"			\
51f0aa
+		  "    j 1b\n\t"					\
51f0aa
+		  /* Found a value > 0x7f.  */				\
51f0aa
+		  "13: ahi %[R_TMP],4\n\t"				\
51f0aa
+		  "12: ahi %[R_TMP],4\n\t"				\
51f0aa
+		  "11: ahi %[R_TMP],4\n\t"				\
51f0aa
+		  "10: vlgvb %[R_I],%%v22,7\n\t"			\
51f0aa
+		  "    srlg %[R_I],%[R_I],2\n\t"			\
51f0aa
+		  "    agr %[R_I],%[R_TMP]\n\t"				\
51f0aa
+		  "    je 20f\n\t"					\
51f0aa
+		  /* Store characters before invalid one...  */		\
51f0aa
+		  "    slgr %[R_OUTLEN],%[R_I]\n\t"			\
51f0aa
+		  "15: aghi %[R_I],-1\n\t"				\
51f0aa
+		  "    vstl %%v23,%[R_I],0(%[R_OUT])\n\t"		\
51f0aa
+		  /* ... and update pointers.  */			\
51f0aa
+		  "    aghi %[R_I],1\n\t"				\
51f0aa
+		  "    la %[R_OUT],0(%[R_I],%[R_OUT])\n\t"		\
51f0aa
+		  "    sllg %[R_I],%[R_I],2\n\t"			\
51f0aa
+		  "    la %[R_IN],0(%[R_I],%[R_IN])\n\t"		\
51f0aa
+		  "    slgr %[R_INLEN],%[R_I]\n\t"			\
51f0aa
+		  /* Handle multibyte utf8-char with convert instruction. */ \
51f0aa
+		  "20: cu41 %[R_OUT],%[R_IN]\n\t"			\
51f0aa
+		  "    jo 0b\n\t" /* Try vector implemenation again.  */ \
51f0aa
+		  "    lochil %[R_RES],%[RES_OUT_FULL]\n\t" /* cc == 1.  */ \
51f0aa
+		  "    lochih %[R_RES],%[RES_IN_ILL]\n\t" /* cc == 2.  */ \
51f0aa
+		  ".machine pop"					\
51f0aa
+		  : /* outputs */ [R_IN] "+a" (pInput)			\
51f0aa
+		    , [R_INLEN] "+d" (inlen), [R_OUT] "+a" (pOutput)	\
51f0aa
+		    , [R_OUTLEN] "+d" (outlen), [R_TMP] "=d" (tmp)	\
51f0aa
+		    , [R_I] "=a" (tmp2)					\
51f0aa
+		    , [R_RES] "+d" (result)				\
51f0aa
+		  : /* inputs */					\
51f0aa
+		    [RES_OUT_FULL] "i" (__GCONV_FULL_OUTPUT)		\
51f0aa
+		    , [RES_IN_ILL] "i" (__GCONV_ILLEGAL_INPUT)		\
51f0aa
+		  : /* clobber list */ "memory", "cc"			\
51f0aa
+		    ASM_CLOBBER_VR ("v16") ASM_CLOBBER_VR ("v17")	\
51f0aa
+		    ASM_CLOBBER_VR ("v18") ASM_CLOBBER_VR ("v19")	\
51f0aa
+		    ASM_CLOBBER_VR ("v20") ASM_CLOBBER_VR ("v21")	\
51f0aa
+		    ASM_CLOBBER_VR ("v22") ASM_CLOBBER_VR ("v23")	\
51f0aa
+		    ASM_CLOBBER_VR ("v24")				\
51f0aa
+		  );							\
51f0aa
+    inptr = pInput;							\
51f0aa
+    outptr = pOutput;							\
51f0aa
+									\
51f0aa
+    if (__glibc_likely (inptr == inend)					\
51f0aa
+	|| result == __GCONV_FULL_OUTPUT)				\
51f0aa
+      break;								\
51f0aa
+    if (inptr + 4 > inend)						\
51f0aa
+      {									\
51f0aa
+	result = __GCONV_INCOMPLETE_INPUT;				\
51f0aa
+	break;								\
51f0aa
+      }									\
51f0aa
+    STANDARD_TO_LOOP_ERR_HANDLER (4);					\
51f0aa
+  }
51f0aa
+
51f0aa
+/* Generate loop-function with hardware vector and utf-convert instructions.  */
51f0aa
+# define MIN_NEEDED_INPUT	MIN_NEEDED_TO
51f0aa
+# define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
51f0aa
+# define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
51f0aa
+# define TO_LOOP_VX_CU		__to_utf8_loop_vx_cu
51f0aa
+# define LOOPFCT		TO_LOOP_VX_CU
51f0aa
+# define BODY			BODY_TO_VX_CU
51f0aa
+# define LOOP_NEED_FLAGS
51f0aa
+# include <iconv/loop.c>
51f0aa
+#else
51f0aa
+# define TO_LOOP_VX_CU		NULL
51f0aa
+#endif /* HAVE_TO_VX_CU != 1  */
51f0aa
+
51f0aa
 /* This file also exists in sysdeps/s390/multiarch/ which
51f0aa
    generates ifunc resolvers for FROM/TO_LOOP functions
51f0aa
    and includes iconv/skeleton.c afterwards.  */
51f0aa
-- 
51f0aa
1.8.3.1
51f0aa