|
|
fa3bfd |
From 8430e4e5d5da2ed14d33638c476654c2a0474d2a Mon Sep 17 00:00:00 2001
|
|
|
fa3bfd |
From: Stefan Liebler <stli@linux.vnet.ibm.com>
|
|
|
fa3bfd |
Date: Thu, 27 Jul 2017 10:53:59 +0200
|
|
|
fa3bfd |
Subject: [PATCH 09/10] S390: Use cu24 instruction for converting from utf16 to
|
|
|
fa3bfd |
utf32.
|
|
|
fa3bfd |
|
|
|
fa3bfd |
upstream-commit f0137ff31da85bc7d9bd4e621af958d8b7249475
|
|
|
fa3bfd |
|
|
|
fa3bfd |
This patch adds an ifunc variant to use the cu instruction on arch12 CPUs.
|
|
|
fa3bfd |
This new ifunc variant can be built if binutils support z13 vector
|
|
|
fa3bfd |
instructions. At runtime, HWCAP_S390_VXE decides if we can use the
|
|
|
fa3bfd |
cu24 instruction.
|
|
|
fa3bfd |
|
|
|
fa3bfd |
ChangeLog:
|
|
|
fa3bfd |
|
|
|
fa3bfd |
* sysdeps/s390/utf16-utf32-z9.c (__from_utf16_loop_vx_cu):
|
|
|
fa3bfd |
Use vector and cu24 instruction.
|
|
|
fa3bfd |
* sysdeps/s390/multiarch/utf16-utf32-z9.c:
|
|
|
fa3bfd |
Add __from_utf16_loop_vx_cu in ifunc resolver.
|
|
|
fa3bfd |
---
|
|
|
fa3bfd |
sysdeps/s390/multiarch/utf16-utf32-z9.c | 8 ++-
|
|
|
fa3bfd |
sysdeps/s390/utf16-utf32-z9.c | 113 +++++++++++++++++++++++++++++++-
|
|
|
fa3bfd |
2 files changed, 117 insertions(+), 4 deletions(-)
|
|
|
fa3bfd |
|
|
|
fa3bfd |
diff --git a/sysdeps/s390/multiarch/utf16-utf32-z9.c b/sysdeps/s390/multiarch/utf16-utf32-z9.c
|
|
|
fa3bfd |
index ded3cc2..917de5f 100644
|
|
|
fa3bfd |
--- a/sysdeps/s390/multiarch/utf16-utf32-z9.c
|
|
|
fa3bfd |
+++ b/sysdeps/s390/multiarch/utf16-utf32-z9.c
|
|
|
fa3bfd |
@@ -32,9 +32,11 @@ strong_alias (SINGLE_NAME (TO_LOOP_DEFAULT), SINGLE_NAME (TO_LOOP))
|
|
|
fa3bfd |
|
|
|
fa3bfd |
/* Generate ifunc'ed loop functions for FROM/TO_LOOP. */
|
|
|
fa3bfd |
s390_libc_ifunc_expr (FROM_LOOP_DEFAULT, FROM_LOOP,
|
|
|
fa3bfd |
- (HAVE_FROM_VX && (hwcap & HWCAP_S390_VX))
|
|
|
fa3bfd |
- ? FROM_LOOP_VX
|
|
|
fa3bfd |
- : FROM_LOOP_DEFAULT);
|
|
|
fa3bfd |
+ (HAVE_FROM_VX_CU && (hwcap & HWCAP_S390_VXE))
|
|
|
fa3bfd |
+ ? FROM_LOOP_VX_CU
|
|
|
fa3bfd |
+ : (HAVE_FROM_VX && (hwcap & HWCAP_S390_VX))
|
|
|
fa3bfd |
+ ? FROM_LOOP_VX
|
|
|
fa3bfd |
+ : FROM_LOOP_DEFAULT);
|
|
|
fa3bfd |
|
|
|
fa3bfd |
s390_libc_ifunc_expr (TO_LOOP_DEFAULT, TO_LOOP,
|
|
|
fa3bfd |
(HAVE_TO_VX_CU && (hwcap & HWCAP_S390_VXE))
|
|
|
fa3bfd |
diff --git a/sysdeps/s390/utf16-utf32-z9.c b/sysdeps/s390/utf16-utf32-z9.c
|
|
|
fa3bfd |
index b1728d6..c09a425 100644
|
|
|
fa3bfd |
--- a/sysdeps/s390/utf16-utf32-z9.c
|
|
|
fa3bfd |
+++ b/sysdeps/s390/utf16-utf32-z9.c
|
|
|
fa3bfd |
@@ -39,10 +39,12 @@
|
|
|
fa3bfd |
|
|
|
fa3bfd |
#if defined HAVE_S390_VX_ASM_SUPPORT && defined USE_MULTIARCH
|
|
|
fa3bfd |
# define HAVE_FROM_VX 1
|
|
|
fa3bfd |
+# define HAVE_FROM_VX_CU 1
|
|
|
fa3bfd |
# define HAVE_TO_VX 1
|
|
|
fa3bfd |
# define HAVE_TO_VX_CU 1
|
|
|
fa3bfd |
#else
|
|
|
fa3bfd |
# define HAVE_FROM_VX 0
|
|
|
fa3bfd |
+# define HAVE_FROM_VX_CU 0
|
|
|
fa3bfd |
# define HAVE_TO_VX 0
|
|
|
fa3bfd |
# define HAVE_TO_VX_CU 0
|
|
|
fa3bfd |
#endif
|
|
|
fa3bfd |
@@ -383,7 +385,6 @@ gconv_end (struct __gconv_step *data)
|
|
|
fa3bfd |
STANDARD_FROM_LOOP_ERR_HANDLER (2); \
|
|
|
fa3bfd |
}
|
|
|
fa3bfd |
|
|
|
fa3bfd |
-
|
|
|
fa3bfd |
/* Generate loop-function with hardware vector instructions. */
|
|
|
fa3bfd |
# define MIN_NEEDED_INPUT MIN_NEEDED_FROM
|
|
|
fa3bfd |
# define MAX_NEEDED_INPUT MAX_NEEDED_FROM
|
|
|
fa3bfd |
@@ -397,6 +398,116 @@ gconv_end (struct __gconv_step *data)
|
|
|
fa3bfd |
# define FROM_LOOP_VX NULL
|
|
|
fa3bfd |
#endif /* HAVE_FROM_VX != 1 */
|
|
|
fa3bfd |
|
|
|
fa3bfd |
+#if HAVE_FROM_VX_CU == 1
|
|
|
fa3bfd |
+#define BODY_FROM_VX_CU \
|
|
|
fa3bfd |
+ { \
|
|
|
fa3bfd |
+ register const unsigned char* pInput asm ("8") = inptr; \
|
|
|
fa3bfd |
+ register size_t inlen asm ("9") = inend - inptr; \
|
|
|
fa3bfd |
+ register unsigned char* pOutput asm ("10") = outptr; \
|
|
|
fa3bfd |
+ register size_t outlen asm ("11") = outend - outptr; \
|
|
|
fa3bfd |
+ unsigned long tmp, tmp2, tmp3; \
|
|
|
fa3bfd |
+ asm volatile (".machine push\n\t" \
|
|
|
fa3bfd |
+ ".machine \"z13\"\n\t" \
|
|
|
fa3bfd |
+ ".machinemode \"zarch_nohighgprs\"\n\t" \
|
|
|
fa3bfd |
+ /* Setup to check for surrogates. */ \
|
|
|
fa3bfd |
+ " larl %[R_TMP],9f\n\t" \
|
|
|
fa3bfd |
+ " vlm %%v30,%%v31,0(%[R_TMP])\n\t" \
|
|
|
fa3bfd |
+ CONVERT_32BIT_SIZE_T ([R_INLEN]) \
|
|
|
fa3bfd |
+ CONVERT_32BIT_SIZE_T ([R_OUTLEN]) \
|
|
|
fa3bfd |
+ /* Loop which handles UTF-16 chars <0xd800, >0xdfff. */ \
|
|
|
fa3bfd |
+ "0: clgijl %[R_INLEN],16,20f\n\t" \
|
|
|
fa3bfd |
+ " clgijl %[R_OUTLEN],32,20f\n\t" \
|
|
|
fa3bfd |
+ "1: vl %%v16,0(%[R_IN])\n\t" \
|
|
|
fa3bfd |
+ /* Check for surrogate chars. */ \
|
|
|
fa3bfd |
+ " vstrchs %%v19,%%v16,%%v30,%%v31\n\t" \
|
|
|
fa3bfd |
+ " jno 10f\n\t" \
|
|
|
fa3bfd |
+ /* Enlarge to UTF-32. */ \
|
|
|
fa3bfd |
+ " vuplhh %%v17,%%v16\n\t" \
|
|
|
fa3bfd |
+ " la %[R_IN],16(%[R_IN])\n\t" \
|
|
|
fa3bfd |
+ " vupllh %%v18,%%v16\n\t" \
|
|
|
fa3bfd |
+ " aghi %[R_INLEN],-16\n\t" \
|
|
|
fa3bfd |
+ /* Store 32 bytes to buf_out. */ \
|
|
|
fa3bfd |
+ " vstm %%v17,%%v18,0(%[R_OUT])\n\t" \
|
|
|
fa3bfd |
+ " aghi %[R_OUTLEN],-32\n\t" \
|
|
|
fa3bfd |
+ " la %[R_OUT],32(%[R_OUT])\n\t" \
|
|
|
fa3bfd |
+ " clgijl %[R_INLEN],16,20f\n\t" \
|
|
|
fa3bfd |
+ " clgijl %[R_OUTLEN],32,20f\n\t" \
|
|
|
fa3bfd |
+ " j 1b\n\t" \
|
|
|
fa3bfd |
+ /* Setup to check for ch >= 0xd800 && ch <= 0xdfff. (v30, v31) */ \
|
|
|
fa3bfd |
+ "9: .short 0xd800,0xdfff,0x0,0x0,0x0,0x0,0x0,0x0\n\t" \
|
|
|
fa3bfd |
+ " .short 0xa000,0xc000,0x0,0x0,0x0,0x0,0x0,0x0\n\t" \
|
|
|
fa3bfd |
+ /* At least one uint16_t is in range of surrogates. \
|
|
|
fa3bfd |
+ Store the preceding chars. */ \
|
|
|
fa3bfd |
+ "10: vlgvb %[R_TMP],%%v19,7\n\t" \
|
|
|
fa3bfd |
+ " vuplhh %%v17,%%v16\n\t" \
|
|
|
fa3bfd |
+ " sllg %[R_TMP3],%[R_TMP],1\n\t" /* Number of out bytes. */ \
|
|
|
fa3bfd |
+ " ahik %[R_TMP2],%[R_TMP3],-1\n\t" /* Highest index to store. */ \
|
|
|
fa3bfd |
+ " jl 20f\n\t" \
|
|
|
fa3bfd |
+ " vstl %%v17,%[R_TMP2],0(%[R_OUT])\n\t" \
|
|
|
fa3bfd |
+ " vupllh %%v18,%%v16\n\t" \
|
|
|
fa3bfd |
+ " ahi %[R_TMP2],-16\n\t" \
|
|
|
fa3bfd |
+ " jl 11f\n\t" \
|
|
|
fa3bfd |
+ " vstl %%v18,%[R_TMP2],16(%[R_OUT])\n\t" \
|
|
|
fa3bfd |
+ "11: \n\t" /* Update pointers. */ \
|
|
|
fa3bfd |
+ " la %[R_IN],0(%[R_TMP],%[R_IN])\n\t" \
|
|
|
fa3bfd |
+ " slgr %[R_INLEN],%[R_TMP]\n\t" \
|
|
|
fa3bfd |
+ " la %[R_OUT],0(%[R_TMP3],%[R_OUT])\n\t" \
|
|
|
fa3bfd |
+ " slgr %[R_OUTLEN],%[R_TMP3]\n\t" \
|
|
|
fa3bfd |
+ /* Handles UTF16 surrogates with convert instruction. */ \
|
|
|
fa3bfd |
+ "20: cu24 %[R_OUT],%[R_IN],1\n\t" \
|
|
|
fa3bfd |
+ " jo 0b\n\t" /* Try vector implemenation again. */ \
|
|
|
fa3bfd |
+ " lochil %[R_RES],%[RES_OUT_FULL]\n\t" /* cc == 1. */ \
|
|
|
fa3bfd |
+ " lochih %[R_RES],%[RES_IN_ILL]\n\t" /* cc == 2. */ \
|
|
|
fa3bfd |
+ ".machine pop" \
|
|
|
fa3bfd |
+ : /* outputs */ [R_IN] "+a" (pInput) \
|
|
|
fa3bfd |
+ , [R_INLEN] "+d" (inlen), [R_OUT] "+a" (pOutput) \
|
|
|
fa3bfd |
+ , [R_OUTLEN] "+d" (outlen), [R_TMP] "=a" (tmp) \
|
|
|
fa3bfd |
+ , [R_TMP2] "=d" (tmp2), [R_TMP3] "=a" (tmp3) \
|
|
|
fa3bfd |
+ , [R_RES] "+d" (result) \
|
|
|
fa3bfd |
+ : /* inputs */ \
|
|
|
fa3bfd |
+ [RES_OUT_FULL] "i" (__GCONV_FULL_OUTPUT) \
|
|
|
fa3bfd |
+ , [RES_IN_ILL] "i" (__GCONV_ILLEGAL_INPUT) \
|
|
|
fa3bfd |
+ : /* clobber list */ "memory", "cc" \
|
|
|
fa3bfd |
+ ASM_CLOBBER_VR ("v16") ASM_CLOBBER_VR ("v17") \
|
|
|
fa3bfd |
+ ASM_CLOBBER_VR ("v18") ASM_CLOBBER_VR ("v19") \
|
|
|
fa3bfd |
+ ASM_CLOBBER_VR ("v30") ASM_CLOBBER_VR ("v31") \
|
|
|
fa3bfd |
+ ); \
|
|
|
fa3bfd |
+ inptr = pInput; \
|
|
|
fa3bfd |
+ outptr = pOutput; \
|
|
|
fa3bfd |
+ \
|
|
|
fa3bfd |
+ if (__glibc_likely (inlen == 0) \
|
|
|
fa3bfd |
+ || result == __GCONV_FULL_OUTPUT) \
|
|
|
fa3bfd |
+ break; \
|
|
|
fa3bfd |
+ if (inlen == 1) \
|
|
|
fa3bfd |
+ { \
|
|
|
fa3bfd |
+ /* Input does not contain a complete utf16 character. */ \
|
|
|
fa3bfd |
+ result = __GCONV_INCOMPLETE_INPUT; \
|
|
|
fa3bfd |
+ break; \
|
|
|
fa3bfd |
+ } \
|
|
|
fa3bfd |
+ else if (result != __GCONV_ILLEGAL_INPUT) \
|
|
|
fa3bfd |
+ { \
|
|
|
fa3bfd |
+ /* Input is >= 2 and < 4 bytes (as cu24 would have processed \
|
|
|
fa3bfd |
+ a possible next utf16 character) and not illegal. \
|
|
|
fa3bfd |
+ => we have a single high surrogate at end of input. */ \
|
|
|
fa3bfd |
+ result = __GCONV_INCOMPLETE_INPUT; \
|
|
|
fa3bfd |
+ break; \
|
|
|
fa3bfd |
+ } \
|
|
|
fa3bfd |
+ \
|
|
|
fa3bfd |
+ STANDARD_FROM_LOOP_ERR_HANDLER (2); \
|
|
|
fa3bfd |
+ }
|
|
|
fa3bfd |
+
|
|
|
fa3bfd |
+/* Generate loop-function with hardware vector and utf-convert instructions. */
|
|
|
fa3bfd |
+# define MIN_NEEDED_INPUT MIN_NEEDED_FROM
|
|
|
fa3bfd |
+# define MAX_NEEDED_INPUT MAX_NEEDED_FROM
|
|
|
fa3bfd |
+# define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
|
|
|
fa3bfd |
+# define FROM_LOOP_VX_CU __from_utf16_loop_vx_cu
|
|
|
fa3bfd |
+# define LOOPFCT FROM_LOOP_VX_CU
|
|
|
fa3bfd |
+# define LOOP_NEED_FLAGS
|
|
|
fa3bfd |
+# define BODY BODY_FROM_VX_CU
|
|
|
fa3bfd |
+# include <iconv/loop.c>
|
|
|
fa3bfd |
+#else
|
|
|
fa3bfd |
+# define FROM_LOOP_VX_CU NULL
|
|
|
fa3bfd |
+#endif /* HAVE_FROM_VX_CU != 1 */
|
|
|
fa3bfd |
|
|
|
fa3bfd |
/* Conversion from UTF-32 internal/BE to UTF-16. */
|
|
|
fa3bfd |
|
|
|
fa3bfd |
--
|
|
|
fa3bfd |
1.8.3.1
|
|
|
fa3bfd |
|