Refactor *cvt functions implementation (2/2)

This patch refactors the *cvt functions implementation in a way that
makes it easier to re-use them for implementing the IEEE long double on
powerpc64le.  By removing the macros that generate the function names
(APPEND combined with FUNC_PREFIX), the new code makes it easier to
define new function names, such as __qecvtieee128.

Tested that installed stripped binaries for all build-many-glibcs
targets remain identical before and after this patch.  Also tested for
powerpc64le and x86_64.

Reviewed-by: Paul E. Murphy <murphyp@linux.ibm.com>
This commit is contained in:
Gabriel F. T. Gomes 2019-11-26 14:48:49 -03:00
parent e18a305777
commit dce4253411
6 changed files with 62 additions and 59 deletions

View File

@ -25,8 +25,6 @@
#define APPEND(a, b) APPEND2 (a, b) #define APPEND(a, b) APPEND2 (a, b)
#define APPEND2(a, b) a##b #define APPEND2(a, b) a##b
#define __APPEND(a, b) __APPEND2 (a, b)
#define __APPEND2(a, b) __##a##b
#define FCVT_BUFFER APPEND (FUNC_PREFIX, fcvt_buffer) #define FCVT_BUFFER APPEND (FUNC_PREFIX, fcvt_buffer)
@ -39,13 +37,11 @@ static char ECVT_BUFFER[MAXDIG];
libc_freeres_ptr (static char *FCVT_BUFPTR); libc_freeres_ptr (static char *FCVT_BUFPTR);
char * char *
__APPEND (FUNC_PREFIX, fcvt) (FLOAT_TYPE value, int ndigit, int *decpt, __FCVT (FLOAT_TYPE value, int ndigit, int *decpt, int *sign)
int *sign)
{ {
if (FCVT_BUFPTR == NULL) if (FCVT_BUFPTR == NULL)
{ {
if (__APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign, if (__FCVT_R (value, ndigit, decpt, sign, FCVT_BUFFER, MAXDIG) != -1)
FCVT_BUFFER, MAXDIG) != -1)
return FCVT_BUFFER; return FCVT_BUFFER;
FCVT_BUFPTR = (char *) malloc (FCVT_MAXDIG); FCVT_BUFPTR = (char *) malloc (FCVT_MAXDIG);
@ -53,25 +49,22 @@ __APPEND (FUNC_PREFIX, fcvt) (FLOAT_TYPE value, int ndigit, int *decpt,
return FCVT_BUFFER; return FCVT_BUFFER;
} }
(void) __APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign, (void) __FCVT_R (value, ndigit, decpt, sign, FCVT_BUFPTR, FCVT_MAXDIG);
FCVT_BUFPTR, FCVT_MAXDIG);
return FCVT_BUFPTR; return FCVT_BUFPTR;
} }
char * char *
__APPEND (FUNC_PREFIX, ecvt) (FLOAT_TYPE value, int ndigit, int *decpt, __ECVT (FLOAT_TYPE value, int ndigit, int *decpt, int *sign)
int *sign)
{ {
(void) __APPEND (FUNC_PREFIX, ecvt_r) (value, ndigit, decpt, sign, (void) __ECVT_R (value, ndigit, decpt, sign, ECVT_BUFFER, MAXDIG);
ECVT_BUFFER, MAXDIG);
return ECVT_BUFFER; return ECVT_BUFFER;
} }
char * char *
__APPEND (FUNC_PREFIX, gcvt) (FLOAT_TYPE value, int ndigit, char *buf) __GCVT (FLOAT_TYPE value, int ndigit, char *buf)
{ {
sprintf (buf, "%.*" FLOAT_FMT_FLAG "g", MIN (ndigit, NDIGIT_MAX), value); sprintf (buf, "%.*" FLOAT_FMT_FLAG "g", MIN (ndigit, NDIGIT_MAX), value);
return buf; return buf;

View File

@ -16,20 +16,27 @@
License along with the GNU C Library; if not, see License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */ <https://www.gnu.org/licenses/>. */
#define ECVT ecvt
#define FCVT fcvt
#define GCVT gcvt
#define __ECVT __ecvt
#define __FCVT __fcvt
#define __GCVT __gcvt
#define __ECVT_R __ecvt_r
#define __FCVT_R __fcvt_r
#include <efgcvt-dbl-macros.h> #include <efgcvt-dbl-macros.h>
#include <efgcvt-template.c> #include <efgcvt-template.c>
#if LONG_DOUBLE_COMPAT (libc, GLIBC_2_0) #if LONG_DOUBLE_COMPAT (libc, GLIBC_2_0)
# define cvt_symbol(symbol) \ # define cvt_symbol(local, symbol) \
cvt_symbol_1 (libc, __APPEND (FUNC_PREFIX, symbol), \ cvt_symbol_1 (libc, local, APPEND (q, symbol), GLIBC_2_0); \
APPEND (q, symbol), GLIBC_2_0); \ strong_alias (local, symbol)
strong_alias (__APPEND (FUNC_PREFIX, symbol), APPEND (FUNC_PREFIX, symbol))
# define cvt_symbol_1(lib, local, symbol, version) \ # define cvt_symbol_1(lib, local, symbol, version) \
compat_symbol (lib, local, symbol, version) compat_symbol (lib, local, symbol, version)
#else #else
# define cvt_symbol(symbol) \ # define cvt_symbol(local, symbol) \
strong_alias (__APPEND (FUNC_PREFIX, symbol), APPEND (FUNC_PREFIX, symbol)) strong_alias (local, symbol)
#endif #endif
cvt_symbol(fcvt); cvt_symbol (__fcvt, fcvt);
cvt_symbol(ecvt); cvt_symbol (__ecvt, ecvt);
cvt_symbol(gcvt); cvt_symbol (__gcvt, gcvt);

View File

@ -28,12 +28,10 @@
#define APPEND(a, b) APPEND2 (a, b) #define APPEND(a, b) APPEND2 (a, b)
#define APPEND2(a, b) a##b #define APPEND2(a, b) a##b
#define __APPEND(a, b) __APPEND2 (a, b)
#define __APPEND2(a, b) __##a##b
int int
__APPEND (FUNC_PREFIX, fcvt_r) (FLOAT_TYPE value, int ndigit, int *decpt, __FCVT_R (FLOAT_TYPE value, int ndigit, int *decpt, int *sign,
int *sign, char *buf, size_t len) char *buf, size_t len)
{ {
ssize_t n; ssize_t n;
ssize_t i; ssize_t i;
@ -127,8 +125,8 @@ __APPEND (FUNC_PREFIX, fcvt_r) (FLOAT_TYPE value, int ndigit, int *decpt,
} }
int int
__APPEND (FUNC_PREFIX, ecvt_r) (FLOAT_TYPE value, int ndigit, int *decpt, __ECVT_R (FLOAT_TYPE value, int ndigit, int *decpt, int *sign,
int *sign, char *buf, size_t len) char *buf, size_t len)
{ {
int exponent = 0; int exponent = 0;
@ -187,8 +185,8 @@ __APPEND (FUNC_PREFIX, ecvt_r) (FLOAT_TYPE value, int ndigit, int *decpt,
*sign = isfinite (value) ? signbit (value) != 0 : 0; *sign = isfinite (value) ? signbit (value) != 0 : 0;
} }
else else
if (__APPEND (FUNC_PREFIX, fcvt_r) (value, MIN (ndigit, NDIGIT_MAX) - 1, if (__FCVT_R (value, MIN (ndigit, NDIGIT_MAX) - 1,
decpt, sign, buf, len)) decpt, sign, buf, len))
return -1; return -1;
*decpt += exponent; *decpt += exponent;

View File

@ -16,23 +16,24 @@
License along with the GNU C Library; if not, see License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */ <https://www.gnu.org/licenses/>. */
#define ECVT_R ecvt_r
#define FCVT_R fcvt_r
#define __ECVT_R __ecvt_r
#define __FCVT_R __fcvt_r
#include <efgcvt-dbl-macros.h> #include <efgcvt-dbl-macros.h>
#include <efgcvt_r-template.c> #include <efgcvt_r-template.c>
#if LONG_DOUBLE_COMPAT (libc, GLIBC_2_0) #if LONG_DOUBLE_COMPAT (libc, GLIBC_2_0)
# define cvt_symbol(symbol) \ # define cvt_symbol(local, symbol) \
cvt_symbol_1 (libc, __APPEND (FUNC_PREFIX, symbol), \ cvt_symbol_1 (libc, local, APPEND (q, symbol), GLIBC_2_0); \
APPEND (q, symbol), GLIBC_2_0); \ weak_alias (local, symbol)
weak_alias (__APPEND (FUNC_PREFIX, symbol), APPEND (FUNC_PREFIX, symbol))
# define cvt_symbol_1(lib, local, symbol, version) \ # define cvt_symbol_1(lib, local, symbol, version) \
libc_hidden_def (local) \ libc_hidden_def (local) \
compat_symbol (lib, local, symbol, version) compat_symbol (lib, local, symbol, version)
#else #else
# define cvt_symbol(symbol) \ # define cvt_symbol(local, symbol) \
cvt_symbol_1 (__APPEND (FUNC_PREFIX, symbol), APPEND (FUNC_PREFIX, symbol))
# define cvt_symbol_1(local, symbol) \
libc_hidden_def (local) \ libc_hidden_def (local) \
weak_alias (local, symbol) weak_alias (local, symbol)
#endif #endif
cvt_symbol(fcvt_r); cvt_symbol (__fcvt_r, fcvt_r);
cvt_symbol(ecvt_r); cvt_symbol (__ecvt_r, ecvt_r);

View File

@ -16,19 +16,24 @@
License along with the GNU C Library; if not, see License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */ <https://www.gnu.org/licenses/>. */
#define ECVT qecvt
#define FCVT qfcvt
#define GCVT qgcvt
#define __ECVT __qecvt
#define __FCVT __qfcvt
#define __GCVT __qgcvt
#define __ECVT_R __qecvt_r
#define __FCVT_R __qfcvt_r
#include <efgcvt-ldbl-macros.h> #include <efgcvt-ldbl-macros.h>
#include <efgcvt-template.c> #include <efgcvt-template.c>
#if LONG_DOUBLE_COMPAT (libc, GLIBC_2_0) #if LONG_DOUBLE_COMPAT (libc, GLIBC_2_0)
# define cvt_symbol(symbol) \ # define cvt_symbol(local, symbol) \
cvt_symbol_1 (libc, __APPEND (FUNC_PREFIX, symbol), \ versioned_symbol (libc, local, symbol, GLIBC_2_4)
APPEND (FUNC_PREFIX, symbol), GLIBC_2_4)
# define cvt_symbol_1(lib, local, symbol, version) \
versioned_symbol (lib, local, symbol, version)
#else #else
# define cvt_symbol(symbol) \ # define cvt_symbol(local, symbol) \
strong_alias (__APPEND (FUNC_PREFIX, symbol), APPEND (FUNC_PREFIX, symbol)) strong_alias (local, symbol)
#endif #endif
cvt_symbol(fcvt); cvt_symbol (__qfcvt, qfcvt);
cvt_symbol(ecvt); cvt_symbol (__qecvt, qecvt);
cvt_symbol(gcvt); cvt_symbol (__qgcvt, qgcvt);

View File

@ -17,22 +17,21 @@
License along with the GNU C Library; if not, see License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */ <https://www.gnu.org/licenses/>. */
#define ECVT_R qecvt_r
#define FCVT_R qfcvt_r
#define __ECVT_R __qecvt_r
#define __FCVT_R __qfcvt_r
#include <efgcvt-ldbl-macros.h> #include <efgcvt-ldbl-macros.h>
#include <efgcvt_r-template.c> #include <efgcvt_r-template.c>
#if LONG_DOUBLE_COMPAT (libc, GLIBC_2_0) #if LONG_DOUBLE_COMPAT (libc, GLIBC_2_0)
# define cvt_symbol(symbol) \ # define cvt_symbol(local, symbol) \
cvt_symbol_1 (libc, __APPEND (FUNC_PREFIX, symbol), \
APPEND (FUNC_PREFIX, symbol), GLIBC_2_4)
# define cvt_symbol_1(lib, local, symbol, version) \
libc_hidden_def (local) \ libc_hidden_def (local) \
versioned_symbol (lib, local, symbol, version) versioned_symbol (libc, local, symbol, GLIBC_2_4)
#else #else
# define cvt_symbol(symbol) \ # define cvt_symbol(local, symbol) \
cvt_symbol_1 (__APPEND (FUNC_PREFIX, symbol), APPEND (FUNC_PREFIX, symbol))
# define cvt_symbol_1(local, symbol) \
libc_hidden_def (local) \ libc_hidden_def (local) \
weak_alias (local, symbol) weak_alias (local, symbol)
#endif #endif
cvt_symbol(fcvt_r); cvt_symbol (__qfcvt_r, qfcvt_r);
cvt_symbol(ecvt_r); cvt_symbol (__qecvt_r, qecvt_r);