fa3bfd
From 9acd7055583a99e912d353ded6a3b4715ee2562a Mon Sep 17 00:00:00 2001
fa3bfd
From: Stefan Liebler <stli@linux.vnet.ibm.com>
fa3bfd
Date: Thu, 27 Jul 2017 10:53:58 +0200
fa3bfd
Subject: [PATCH 04/10] S390: Move utf16-utf32-z9.c to multiarch folder and use
fa3bfd
 s390_libc_ifunc_expr macro.
fa3bfd
fa3bfd
upstream-commit 85286aaf1dd7216a64964752d147c5ce3c4067d0
fa3bfd
fa3bfd
The utf16-utf32-z9.c iconv module is using ifunc and thus the ifunc part should
fa3bfd
be in multiarch folder.  Otherwise ifunc is used even if you configure
fa3bfd
with --disable-multi-arch.
fa3bfd
fa3bfd
This patch moves the ifunc resolvers to the new file
fa3bfd
sysdeps/s390/multiarch/utf16-utf32-z9.c. The resolvers are now implemented
fa3bfd
with s390_libc_ifunc_expr macro instead of using gcc attribute ifunc directly.
fa3bfd
fa3bfd
The ifunc versions are implemented in sysdeps/s390/utf16-utf32-z9.c.
fa3bfd
Each version is only implemented if needed or supported.  Therefore there is
fa3bfd
a block at beginning of the file which selects the versions which should be
fa3bfd
defined depending on support for multiarch, vector-support and used minimum
fa3bfd
architecture level.  This block defines HAVE_[FROM|TO]_[C|VX] to 1 or 0.
fa3bfd
The code below is rearranged and surrounded
fa3bfd
by #if HAVE_[FROM|TO]_[C|VX] == 1.  There is no functional change.
fa3bfd
fa3bfd
ChangeLog:
fa3bfd
fa3bfd
	* sysdeps/s390/multiarch/utf16-utf32-z9.c: New File.
fa3bfd
	* sysdeps/s390/utf16-utf32-z9.c: Move ifunc resolvers to multiarch
fa3bfd
	folder and define ifunc versions depending on HAVE_[FROM|TO]_[C|VX].
fa3bfd
	(HAVE_FROM_C, HAVE_FROM_VX, HAVE_TO_C, HAVE_TO_VX, FROM_LOOP_DEFAULT,
fa3bfd
	FROM_LOOP_C, FROM_LOOP_VX, TO_LOOP_DEFAULT, TO_LOOP_C, TO_LOOP_VX):
fa3bfd
	New Define.
fa3bfd
---
fa3bfd
 sysdeps/s390/multiarch/utf16-utf32-z9.c |  44 ++++++++++
fa3bfd
 sysdeps/s390/utf16-utf32-z9.c           | 142 ++++++++++++++++----------------
fa3bfd
 2 files changed, 114 insertions(+), 72 deletions(-)
fa3bfd
 create mode 100644 sysdeps/s390/multiarch/utf16-utf32-z9.c
fa3bfd
fa3bfd
diff --git a/sysdeps/s390/multiarch/utf16-utf32-z9.c b/sysdeps/s390/multiarch/utf16-utf32-z9.c
fa3bfd
new file mode 100644
fa3bfd
index 0000000..6e64169
fa3bfd
--- /dev/null
fa3bfd
+++ b/sysdeps/s390/multiarch/utf16-utf32-z9.c
fa3bfd
@@ -0,0 +1,44 @@
fa3bfd
+/* Conversion between UTF-16 and UTF-32 BE/internal - multiarch s390 version.
fa3bfd
+
fa3bfd
+   Copyright (C) 2017 Free Software Foundation, Inc.
fa3bfd
+   This file is part of the GNU C Library.
fa3bfd
+
fa3bfd
+   The GNU C Library is free software; you can redistribute it and/or
fa3bfd
+   modify it under the terms of the GNU Lesser General Public
fa3bfd
+   License as published by the Free Software Foundation; either
fa3bfd
+   version 2.1 of the License, or (at your option) any later version.
fa3bfd
+
fa3bfd
+   The GNU C Library is distributed in the hope that it will be useful,
fa3bfd
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
fa3bfd
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
fa3bfd
+   Lesser General Public License for more details.
fa3bfd
+
fa3bfd
+   You should have received a copy of the GNU Lesser General Public
fa3bfd
+   License along with the GNU C Library; if not, see
fa3bfd
+   <http://www.gnu.org/licenses/>.  */
fa3bfd
+
fa3bfd
+#include <sysdeps/s390/utf16-utf32-z9.c>
fa3bfd
+#include <ifunc-resolve.h>
fa3bfd
+
fa3bfd
+#undef FROM_LOOP
fa3bfd
+#define FROM_LOOP	__from_utf16_loop
fa3bfd
+#undef TO_LOOP
fa3bfd
+#define TO_LOOP		__to_utf16_loop
fa3bfd
+
fa3bfd
+#define _SINGLE_NAME(NAME) NAME##_single
fa3bfd
+#define SINGLE_NAME(NAME) _SINGLE_NAME(NAME)
fa3bfd
+strong_alias (SINGLE_NAME (FROM_LOOP_DEFAULT), SINGLE_NAME (FROM_LOOP))
fa3bfd
+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
+
fa3bfd
+s390_libc_ifunc_expr (TO_LOOP_DEFAULT, TO_LOOP,
fa3bfd
+		      (HAVE_TO_VX && (hwcap & HWCAP_S390_VX))
fa3bfd
+		      ? TO_LOOP_VX
fa3bfd
+		      : TO_LOOP_DEFAULT);
fa3bfd
+
fa3bfd
+#include <iconv/skeleton.c>
fa3bfd
diff --git a/sysdeps/s390/utf16-utf32-z9.c b/sysdeps/s390/utf16-utf32-z9.c
fa3bfd
index 5d2ac44..5a39d5d 100644
fa3bfd
--- a/sysdeps/s390/utf16-utf32-z9.c
fa3bfd
+++ b/sysdeps/s390/utf16-utf32-z9.c
fa3bfd
@@ -27,8 +27,23 @@
fa3bfd
 #include <dlfcn.h>
fa3bfd
 #include <stdint.h>
fa3bfd
 #include <unistd.h>
fa3bfd
-#include <dl-procinfo.h>
fa3bfd
 #include <gconv.h>
fa3bfd
+#include <string.h>
fa3bfd
+
fa3bfd
+/* Select which versions should be defined depending on support
fa3bfd
+   for multiarch, vector and used minimum architecture level.  */
fa3bfd
+#define HAVE_FROM_C		1
fa3bfd
+#define FROM_LOOP_DEFAULT	FROM_LOOP_C
fa3bfd
+#define HAVE_TO_C		1
fa3bfd
+#define TO_LOOP_DEFAULT		TO_LOOP_C
fa3bfd
+
fa3bfd
+#if defined HAVE_S390_VX_ASM_SUPPORT && defined USE_MULTIARCH
fa3bfd
+# define HAVE_FROM_VX		1
fa3bfd
+# define HAVE_TO_VX		1
fa3bfd
+#else
fa3bfd
+# define HAVE_FROM_VX		0
fa3bfd
+# define HAVE_TO_VX		0
fa3bfd
+#endif
fa3bfd
 
fa3bfd
 #if defined HAVE_S390_VX_GCC_SUPPORT
fa3bfd
 # define ASM_CLOBBER_VR(NR) , NR
fa3bfd
@@ -53,8 +68,8 @@
fa3bfd
 #define MIN_NEEDED_FROM		2
fa3bfd
 #define MAX_NEEDED_FROM		4
fa3bfd
 #define MIN_NEEDED_TO		4
fa3bfd
-#define FROM_LOOP		__from_utf16_loop
fa3bfd
-#define TO_LOOP			__to_utf16_loop
fa3bfd
+#define FROM_LOOP		FROM_LOOP_DEFAULT
fa3bfd
+#define TO_LOOP			TO_LOOP_DEFAULT
fa3bfd
 #define FROM_DIRECTION		(dir == from_utf16)
fa3bfd
 #define ONE_DIRECTION           0
fa3bfd
 
fa3bfd
@@ -174,9 +189,10 @@ gconv_end (struct __gconv_step *data)
fa3bfd
 
fa3bfd
 /* Conversion function from UTF-16 to UTF-32 internal/BE.  */
fa3bfd
 
fa3bfd
+#if HAVE_FROM_C == 1
fa3bfd
 /* The software routine is copied from utf-16.c (minus bytes
fa3bfd
    swapping).  */
fa3bfd
-#define BODY_FROM_C							\
fa3bfd
+# define BODY_FROM_C							\
fa3bfd
   {									\
fa3bfd
     uint16_t u1 = get16 (inptr);					\
fa3bfd
 									\
fa3bfd
@@ -220,7 +236,22 @@ gconv_end (struct __gconv_step *data)
fa3bfd
     outptr += 4;							\
fa3bfd
   }
fa3bfd
 
fa3bfd
-#define BODY_FROM_VX							\
fa3bfd
+
fa3bfd
+/* Generate loop-function with software routing.  */
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_C		__from_utf16_loop_c
fa3bfd
+# define LOOPFCT		FROM_LOOP_C
fa3bfd
+# define LOOP_NEED_FLAGS
fa3bfd
+# define BODY			BODY_FROM_C
fa3bfd
+# include <iconv/loop.c>
fa3bfd
+#else
fa3bfd
+# define FROM_LOOP_C		NULL
fa3bfd
+#endif /* HAVE_FROM_C != 1  */
fa3bfd
+
fa3bfd
+#if HAVE_FROM_VX == 1
fa3bfd
+# define BODY_FROM_VX							\
fa3bfd
   {									\
fa3bfd
     size_t inlen = inend - inptr;					\
fa3bfd
     size_t outlen = outend - outptr;					\
fa3bfd
@@ -255,7 +286,7 @@ gconv_end (struct __gconv_step *data)
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 on uint16_t is in range of surrogates.	\
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
@@ -351,52 +382,26 @@ gconv_end (struct __gconv_step *data)
fa3bfd
   }
fa3bfd
 
fa3bfd
 
fa3bfd
-/* Generate loop-function with software routing.  */
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
-#if defined HAVE_S390_VX_ASM_SUPPORT
fa3bfd
-# define LOOPFCT		__from_utf16_loop_c
fa3bfd
-# define LOOP_NEED_FLAGS
fa3bfd
-# define BODY			BODY_FROM_C
fa3bfd
-# include <iconv/loop.c>
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
 # define MIN_NEEDED_OUTPUT	MIN_NEEDED_TO
fa3bfd
-# define LOOPFCT		__from_utf16_loop_vx
fa3bfd
+# define FROM_LOOP_VX		__from_utf16_loop_vx
fa3bfd
+# define LOOPFCT		FROM_LOOP_VX
fa3bfd
 # define LOOP_NEED_FLAGS
fa3bfd
 # define BODY			BODY_FROM_VX
fa3bfd
 # include <iconv/loop.c>
fa3bfd
-
fa3bfd
-/* Generate ifunc'ed loop function.  */
fa3bfd
-__typeof(__from_utf16_loop_c)
fa3bfd
-__attribute__ ((ifunc ("__from_utf16_loop_resolver")))
fa3bfd
-__from_utf16_loop;
fa3bfd
-
fa3bfd
-static void *
fa3bfd
-__from_utf16_loop_resolver (unsigned long int dl_hwcap)
fa3bfd
-{
fa3bfd
-  if (dl_hwcap & HWCAP_S390_VX)
fa3bfd
-    return __from_utf16_loop_vx;
fa3bfd
-  else
fa3bfd
-    return __from_utf16_loop_c;
fa3bfd
-}
fa3bfd
-
fa3bfd
-strong_alias (__from_utf16_loop_c_single, __from_utf16_loop_single)
fa3bfd
 #else
fa3bfd
-# define LOOPFCT		FROM_LOOP
fa3bfd
-# define LOOP_NEED_FLAGS
fa3bfd
-# define BODY			BODY_FROM_C
fa3bfd
-# include <iconv/loop.c>
fa3bfd
-#endif
fa3bfd
+# define FROM_LOOP_VX		NULL
fa3bfd
+#endif /* HAVE_FROM_VX != 1  */
fa3bfd
+
fa3bfd
 
fa3bfd
 /* Conversion from UTF-32 internal/BE to UTF-16.  */
fa3bfd
 
fa3bfd
+#if HAVE_TO_C == 1
fa3bfd
 /* The software routine is copied from utf-16.c (minus bytes
fa3bfd
    swapping).  */
fa3bfd
-#define BODY_TO_C							\
fa3bfd
+# define BODY_TO_C							\
fa3bfd
   {									\
fa3bfd
     uint32_t c = get32 (inptr);						\
fa3bfd
 									\
fa3bfd
@@ -439,7 +444,21 @@ strong_alias (__from_utf16_loop_c_single, __from_utf16_loop_single)
fa3bfd
     inptr += 4;								\
fa3bfd
   }
fa3bfd
 
fa3bfd
-#define BODY_TO_VX							\
fa3bfd
+/* Generate loop-function with software routing.  */
fa3bfd
+# define MIN_NEEDED_INPUT	MIN_NEEDED_TO
fa3bfd
+# define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
fa3bfd
+# define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
fa3bfd
+# define TO_LOOP_C		__to_utf16_loop_c
fa3bfd
+# define LOOPFCT		TO_LOOP_C
fa3bfd
+# define LOOP_NEED_FLAGS
fa3bfd
+# define BODY			BODY_TO_C
fa3bfd
+# include <iconv/loop.c>
fa3bfd
+#else
fa3bfd
+# define TO_LOOP_C		NULL
fa3bfd
+#endif /* HAVE_TO_C != 1  */
fa3bfd
+
fa3bfd
+#if HAVE_TO_VX == 1
fa3bfd
+# define BODY_TO_VX							\
fa3bfd
   {									\
fa3bfd
     size_t inlen = inend - inptr;					\
fa3bfd
     size_t outlen = outend - outptr;					\
fa3bfd
@@ -563,43 +582,22 @@ strong_alias (__from_utf16_loop_c_single, __from_utf16_loop_single)
fa3bfd
     STANDARD_TO_LOOP_ERR_HANDLER (4);					\
fa3bfd
   }
fa3bfd
 
fa3bfd
-/* Generate loop-function with software routing.  */
fa3bfd
-#define MIN_NEEDED_INPUT	MIN_NEEDED_TO
fa3bfd
-#define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
fa3bfd
-#define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
fa3bfd
-#define LOOPFCT			__to_utf16_loop_c
fa3bfd
-#define LOOP_NEED_FLAGS
fa3bfd
-#define BODY			BODY_TO_C
fa3bfd
-#include <iconv/loop.c>
fa3bfd
-
fa3bfd
-#if defined HAVE_S390_VX_ASM_SUPPORT
fa3bfd
 /* Generate loop-function with hardware vector instructions.  */
fa3bfd
 # define MIN_NEEDED_INPUT	MIN_NEEDED_TO
fa3bfd
 # define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
fa3bfd
 # define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
fa3bfd
-# define LOOPFCT		__to_utf16_loop_vx
fa3bfd
+# define TO_LOOP_VX		__to_utf16_loop_vx
fa3bfd
+# define LOOPFCT		TO_LOOP_VX
fa3bfd
 # define LOOP_NEED_FLAGS
fa3bfd
 # define BODY			BODY_TO_VX
fa3bfd
 # include <iconv/loop.c>
fa3bfd
+#else
fa3bfd
+# define TO_LOOP_VX		NULL
fa3bfd
+#endif /* HAVE_TO_VX != 1  */
fa3bfd
+
fa3bfd
+/* This file also exists in sysdeps/s390/multiarch/ which
fa3bfd
+   generates ifunc resolvers for FROM/TO_LOOP functions
fa3bfd
+   and includes iconv/skeleton.c afterwards.  */
fa3bfd
+#if ! defined USE_MULTIARCH
fa3bfd
+# include <iconv/skeleton.c>
fa3bfd
 #endif
fa3bfd
-
fa3bfd
-/* Generate ifunc'ed loop function.  */
fa3bfd
-__typeof(__to_utf16_loop_c)
fa3bfd
-__attribute__ ((ifunc ("__to_utf16_loop_resolver")))
fa3bfd
-__to_utf16_loop;
fa3bfd
-
fa3bfd
-static void *
fa3bfd
-__to_utf16_loop_resolver (unsigned long int dl_hwcap)
fa3bfd
-{
fa3bfd
-#if defined HAVE_S390_VX_ASM_SUPPORT
fa3bfd
-  if (dl_hwcap & HWCAP_S390_VX)
fa3bfd
-    return __to_utf16_loop_vx;
fa3bfd
-  else
fa3bfd
-#endif
fa3bfd
-    return __to_utf16_loop_c;
fa3bfd
-}
fa3bfd
-
fa3bfd
-strong_alias (__to_utf16_loop_c_single, __to_utf16_loop_single)
fa3bfd
-
fa3bfd
-
fa3bfd
-#include <iconv/skeleton.c>
fa3bfd
-- 
fa3bfd
1.8.3.1
fa3bfd