fa3bfd
From 418f5be91f4c843d63db0d29eee65ff46eb59202 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 03/10] S390: Move utf8-utf16-z9.c to multiarch folder and use
fa3bfd
 s390_libc_ifunc_expr macro.
fa3bfd
fa3bfd
upstream-commit df6cc7ee3b2e032c6c62cedd30b1c0fefbb43018
fa3bfd
fa3bfd
The utf8-utf16-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/utf8-utf16-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/utf8-utf16-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|CU|VX] to 1 or 0.
fa3bfd
The code below is rearranged and surrounded
fa3bfd
by #if HAVE_[FROM|TO]_[C|CU|VX] == 1.  There is no functional change.
fa3bfd
fa3bfd
The cu instructions are z9 zarch instructions.  As the major distros are
fa3bfd
already using the newer z196 as architecture level set, those instructions
fa3bfd
can be used as fallback version instead of the c-code.  This behaviour is
fa3bfd
decided at compile time via HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT.
fa3bfd
fa3bfd
ChangeLog:
fa3bfd
fa3bfd
	* sysdeps/s390/multiarch/utf8-utf16-z9.c: New File.
fa3bfd
	* sysdeps/s390/utf8-utf16-z9.c: Move ifunc resolvers to multiarch
fa3bfd
	folder and define ifunc versions depending on HAVE_[FROM|TO]_[C|CU|VX].
fa3bfd
	(HAVE_FROM_C, HAVE_FROM_CU, HAVE_FROM_VX, HAVE_TO_C, HAVE_TO_VX,
fa3bfd
	FROM_LOOP_DEFAULT, FROM_LOOP_C, FROM_LOOP_CU, FROM_LOOP_VX,
fa3bfd
---
fa3bfd
 sysdeps/s390/multiarch/utf8-utf16-z9.c |  48 ++++++++
fa3bfd
 sysdeps/s390/utf8-utf16-z9.c           | 197 +++++++++++++++++----------------
fa3bfd
 2 files changed, 150 insertions(+), 95 deletions(-)
fa3bfd
 create mode 100644 sysdeps/s390/multiarch/utf8-utf16-z9.c
fa3bfd
fa3bfd
diff --git a/sysdeps/s390/multiarch/utf8-utf16-z9.c b/sysdeps/s390/multiarch/utf8-utf16-z9.c
fa3bfd
new file mode 100644
fa3bfd
index 0000000..b55ef1a
fa3bfd
--- /dev/null
fa3bfd
+++ b/sysdeps/s390/multiarch/utf8-utf16-z9.c
fa3bfd
@@ -0,0 +1,48 @@
fa3bfd
+/* Conversion between UTF-8 and UTF-16 - 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/utf8-utf16-z9.c>
fa3bfd
+#include <ifunc-resolve.h>
fa3bfd
+
fa3bfd
+#undef FROM_LOOP
fa3bfd
+#define FROM_LOOP	__from_utf8_loop
fa3bfd
+#undef TO_LOOP
fa3bfd
+#define TO_LOOP		__to_utf8_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
+		      : (HAVE_FROM_CU && (hwcap & HWCAP_S390_ZARCH
fa3bfd
+					  && hwcap & HWCAP_S390_HIGH_GPRS
fa3bfd
+					  && hwcap & HWCAP_S390_ETF3EH))
fa3bfd
+			? FROM_LOOP_CU
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/utf8-utf16-z9.c b/sysdeps/s390/utf8-utf16-z9.c
fa3bfd
index d3dc9bd..d870a29 100644
fa3bfd
--- a/sysdeps/s390/utf8-utf16-z9.c
fa3bfd
+++ b/sysdeps/s390/utf8-utf16-z9.c
fa3bfd
@@ -1,4 +1,4 @@
fa3bfd
-/* Conversion between UTF-16 and UTF-32 BE/internal.
fa3bfd
+/* Conversion between UTF-8 and UTF-16 - s390 version.
fa3bfd
 
fa3bfd
    This module uses the Z9-109 variants of the Convert Unicode
fa3bfd
    instructions.
fa3bfd
@@ -27,8 +27,35 @@
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
+#ifdef HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT
fa3bfd
+# define HAVE_FROM_C		0
fa3bfd
+# define FROM_LOOP_DEFAULT	FROM_LOOP_CU
fa3bfd
+#else
fa3bfd
+# define HAVE_FROM_C		1
fa3bfd
+# define FROM_LOOP_DEFAULT	FROM_LOOP_C
fa3bfd
+#endif
fa3bfd
+
fa3bfd
+#define HAVE_TO_C		1
fa3bfd
+#define TO_LOOP_DEFAULT		TO_LOOP_C
fa3bfd
+
fa3bfd
+#if defined HAVE_S390_MIN_Z196_ZARCH_ASM_SUPPORT || defined USE_MULTIARCH
fa3bfd
+# define HAVE_FROM_CU		1
fa3bfd
+#else
fa3bfd
+# define HAVE_FROM_CU		0
fa3bfd
+#endif
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
@@ -49,8 +76,8 @@
fa3bfd
 #define MAX_NEEDED_FROM		4
fa3bfd
 #define MIN_NEEDED_TO		2
fa3bfd
 #define MAX_NEEDED_TO		4
fa3bfd
-#define FROM_LOOP		__from_utf8_loop
fa3bfd
-#define TO_LOOP			__to_utf8_loop
fa3bfd
+#define FROM_LOOP		FROM_LOOP_DEFAULT
fa3bfd
+#define TO_LOOP			TO_LOOP_DEFAULT
fa3bfd
 #define FROM_DIRECTION		(dir == from_utf8)
fa3bfd
 #define ONE_DIRECTION           0
fa3bfd
 
fa3bfd
@@ -214,9 +241,8 @@ gconv_end (struct __gconv_step *data)
fa3bfd
     STANDARD_FROM_LOOP_ERR_HANDLER (i);					\
fa3bfd
   }
fa3bfd
 
fa3bfd
-#define BODY_FROM_ETF3EH BODY_FROM_HW (HARDWARE_CONVERT ("cu12 %0, %1, 1"))
fa3bfd
-
fa3bfd
-#define HW_FROM_VX							\
fa3bfd
+#if HAVE_FROM_VX == 1
fa3bfd
+# define HW_FROM_VX							\
fa3bfd
   {									\
fa3bfd
     register const unsigned char* pInput asm ("8") = inptr;		\
fa3bfd
     register size_t inlen asm ("9") = inend - inptr;			\
fa3bfd
@@ -291,11 +317,42 @@ gconv_end (struct __gconv_step *data)
fa3bfd
     inptr = pInput;							\
fa3bfd
     outptr = pOutput;							\
fa3bfd
   }
fa3bfd
-#define BODY_FROM_VX BODY_FROM_HW (HW_FROM_VX)
fa3bfd
+# define BODY_FROM_VX BODY_FROM_HW (HW_FROM_VX)
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 MAX_NEEDED_OUTPUT	MAX_NEEDED_TO
fa3bfd
+# define FROM_LOOP_VX		__from_utf8_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
+#else
fa3bfd
+# define FROM_LOOP_VX		NULL
fa3bfd
+#endif /* HAVE_FROM_VX != 1  */
fa3bfd
+
fa3bfd
+#if HAVE_FROM_CU == 1
fa3bfd
+# define BODY_FROM_ETF3EH BODY_FROM_HW (HARDWARE_CONVERT ("cu12 %0, %1, 1"))
fa3bfd
 
fa3bfd
+/* Generate loop-function with hardware utf-convert instruction.  */
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 MAX_NEEDED_OUTPUT	MAX_NEEDED_TO
fa3bfd
+# define FROM_LOOP_CU		__from_utf8_loop_etf3eh
fa3bfd
+# define LOOPFCT		FROM_LOOP_CU
fa3bfd
+# define LOOP_NEED_FLAGS
fa3bfd
+# define BODY			BODY_FROM_ETF3EH
fa3bfd
+# include <iconv/loop.c>
fa3bfd
+#else
fa3bfd
+# define FROM_LOOP_CU		NULL
fa3bfd
+#endif /* HAVE_FROM_CU != 1  */
fa3bfd
+
fa3bfd
+#if HAVE_FROM_C == 1
fa3bfd
 /* The software implementation is based on the code in gconv_simple.c.  */
fa3bfd
-#define BODY_FROM_C							\
fa3bfd
+# define BODY_FROM_C							\
fa3bfd
   {									\
fa3bfd
     /* Next input byte.  */						\
fa3bfd
     uint16_t ch = *inptr;						\
fa3bfd
@@ -443,66 +500,26 @@ gconv_end (struct __gconv_step *data)
fa3bfd
   }
fa3bfd
 
fa3bfd
 /* Generate loop-function with software implementation.  */
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 MAX_NEEDED_OUTPUT	MAX_NEEDED_TO
fa3bfd
-#define LOOPFCT			__from_utf8_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 utf-convert instruction.  */
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 MAX_NEEDED_OUTPUT	MAX_NEEDED_TO
fa3bfd
-#define LOOPFCT			__from_utf8_loop_etf3eh
fa3bfd
-#define LOOP_NEED_FLAGS
fa3bfd
-#define BODY			BODY_FROM_ETF3EH
fa3bfd
-#include <iconv/loop.c>
fa3bfd
-
fa3bfd
-#if defined HAVE_S390_VX_ASM_SUPPORT
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 MAX_NEEDED_OUTPUT	MAX_NEEDED_TO
fa3bfd
-# define LOOPFCT		__from_utf8_loop_vx
fa3bfd
+# define FROM_LOOP_C		__from_utf8_loop_c
fa3bfd
+# define LOOPFCT		FROM_LOOP_C
fa3bfd
 # define LOOP_NEED_FLAGS
fa3bfd
-# define BODY			BODY_FROM_VX
fa3bfd
+# define BODY			BODY_FROM_C
fa3bfd
 # include <iconv/loop.c>
fa3bfd
-#endif
fa3bfd
-
fa3bfd
-
fa3bfd
-/* Generate ifunc'ed loop function.  */
fa3bfd
-__typeof(__from_utf8_loop_c)
fa3bfd
-__attribute__ ((ifunc ("__from_utf8_loop_resolver")))
fa3bfd
-__from_utf8_loop;
fa3bfd
-
fa3bfd
-static void *
fa3bfd
-__from_utf8_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 __from_utf8_loop_vx;
fa3bfd
-  else
fa3bfd
-#endif
fa3bfd
-  if (dl_hwcap & HWCAP_S390_ZARCH && dl_hwcap & HWCAP_S390_HIGH_GPRS
fa3bfd
-      && dl_hwcap & HWCAP_S390_ETF3EH)
fa3bfd
-    return __from_utf8_loop_etf3eh;
fa3bfd
-  else
fa3bfd
-    return __from_utf8_loop_c;
fa3bfd
-}
fa3bfd
-
fa3bfd
-strong_alias (__from_utf8_loop_c_single, __from_utf8_loop_single)
fa3bfd
+#else
fa3bfd
+# define FROM_LOOP_C		NULL
fa3bfd
+#endif /* HAVE_FROM_C != 1  */
fa3bfd
 
fa3bfd
 /* Conversion from UTF-16 to UTF-8.  */
fa3bfd
 
fa3bfd
+#if HAVE_TO_C == 1
fa3bfd
 /* The software routine is based on the functionality of the S/390
fa3bfd
    hardware instruction (cu21) as described in the Principles of
fa3bfd
    Operation.  */
fa3bfd
-#define BODY_TO_C							\
fa3bfd
+# define BODY_TO_C							\
fa3bfd
   {									\
fa3bfd
     uint16_t c = get16 (inptr);						\
fa3bfd
 									\
fa3bfd
@@ -601,7 +618,22 @@ strong_alias (__from_utf8_loop_c_single, __from_utf8_loop_single)
fa3bfd
     inptr += 2;								\
fa3bfd
   }
fa3bfd
 
fa3bfd
-#define BODY_TO_VX							\
fa3bfd
+/* Generate loop-function with software implementation.  */
fa3bfd
+# define MIN_NEEDED_INPUT	MIN_NEEDED_TO
fa3bfd
+# define MAX_NEEDED_INPUT	MAX_NEEDED_TO
fa3bfd
+# define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
fa3bfd
+# define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
fa3bfd
+# define TO_LOOP_C		__to_utf8_loop_c
fa3bfd
+# define LOOPFCT		TO_LOOP_C
fa3bfd
+# define BODY                   BODY_TO_C
fa3bfd
+# define LOOP_NEED_FLAGS
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
@@ -771,48 +803,23 @@ strong_alias (__from_utf8_loop_c_single, __from_utf8_loop_single)
fa3bfd
     STANDARD_TO_LOOP_ERR_HANDLER (2);					\
fa3bfd
   }
fa3bfd
 
fa3bfd
-/* Generate loop-function with software implementation.  */
fa3bfd
-#define MIN_NEEDED_INPUT	MIN_NEEDED_TO
fa3bfd
-#define MAX_NEEDED_INPUT	MAX_NEEDED_TO
fa3bfd
-#define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
fa3bfd
-#define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
fa3bfd
-#if defined HAVE_S390_VX_ASM_SUPPORT
fa3bfd
-# define LOOPFCT		__to_utf8_loop_c
fa3bfd
-# define BODY                   BODY_TO_C
fa3bfd
-# define LOOP_NEED_FLAGS
fa3bfd
-# include <iconv/loop.c>
fa3bfd
-
fa3bfd
-/* Generate loop-function with software implementation.  */
fa3bfd
+/* Generate loop-function with vector implementation.  */
fa3bfd
 # define MIN_NEEDED_INPUT	MIN_NEEDED_TO
fa3bfd
 # define MAX_NEEDED_INPUT	MAX_NEEDED_TO
fa3bfd
 # define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
fa3bfd
 # define MAX_NEEDED_OUTPUT	MAX_NEEDED_FROM
fa3bfd
-# define LOOPFCT		__to_utf8_loop_vx
fa3bfd
+# define TO_LOOP_VX		__to_utf8_loop_vx
fa3bfd
+# define LOOPFCT		TO_LOOP_VX
fa3bfd
 # define BODY                   BODY_TO_VX
fa3bfd
 # define LOOP_NEED_FLAGS
fa3bfd
 # include <iconv/loop.c>
fa3bfd
-
fa3bfd
-/* Generate ifunc'ed loop function.  */
fa3bfd
-__typeof(__to_utf8_loop_c)
fa3bfd
-__attribute__ ((ifunc ("__to_utf8_loop_resolver")))
fa3bfd
-__to_utf8_loop;
fa3bfd
-
fa3bfd
-static void *
fa3bfd
-__to_utf8_loop_resolver (unsigned long int dl_hwcap)
fa3bfd
-{
fa3bfd
-  if (dl_hwcap & HWCAP_S390_VX)
fa3bfd
-    return __to_utf8_loop_vx;
fa3bfd
-  else
fa3bfd
-    return __to_utf8_loop_c;
fa3bfd
-}
fa3bfd
-
fa3bfd
-strong_alias (__to_utf8_loop_c_single, __to_utf8_loop_single)
fa3bfd
-
fa3bfd
 #else
fa3bfd
-# define LOOPFCT		TO_LOOP
fa3bfd
-# define BODY                   BODY_TO_C
fa3bfd
-# define LOOP_NEED_FLAGS
fa3bfd
-# include <iconv/loop.c>
fa3bfd
-#endif /* !HAVE_S390_VX_ASM_SUPPORT  */
fa3bfd
-
fa3bfd
-#include <iconv/skeleton.c>
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
1.8.3.1
fa3bfd