From d4c3a750e74112d5ea316a35a4ae61c623c5169a Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Tue, 7 Jan 2003 19:52:27 +0000 Subject: [PATCH] 2003-01-07 Jeff Johnston * configure.host: Support long double I/O for x86-linux. * libc/stdlib/ldtoa.c (_ldtoa_r): Fix code to allocate a buffer large enough to hold formatted result. * libc/machine/powerpc/simdldtoa.c (_simdldtoa_r): Ditto. --- newlib/ChangeLog | 7 +++++++ newlib/configure.host | 2 +- newlib/libc/machine/powerpc/simdldtoa.c | 20 ++++++++++++++------ newlib/libc/stdlib/ldtoa.c | 20 ++++++++++++++------ 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index ea5f76976..72b77cb6d 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,10 @@ +2003-01-07 Jeff Johnston + + * configure.host: Support long double I/O for x86-linux. + * libc/stdlib/ldtoa.c (_ldtoa_r): Fix code to allocate a buffer + large enough to hold formatted result. + * libc/machine/powerpc/simdldtoa.c (_simdldtoa_r): Ditto. + 2003-01-06 Charles Wilson * Makefile.am: Add vasprintf. diff --git a/newlib/configure.host b/newlib/configure.host index 3780366d6..2d16fd882 100644 --- a/newlib/configure.host +++ b/newlib/configure.host @@ -338,7 +338,7 @@ case "${host}" in newlib_cflags="${newlib_cflags} -Wall" newlib_cflags="${newlib_cflags} -D_I386MACH_ALLOW_HW_INTERRUPTS" newlib_cflags="${newlib_cflags} -D_LOOSE_KERNEL_NAMES -DHAVE_FCNTL" - newlib_cflags="${newlib_cflags} -DWANT_IO_POS_ARGS" + newlib_cflags="${newlib_cflags} -DWANT_IO_POS_ARGS -DWANT_IO_LONG_DBL" # --- Required when building a shared library ------------------------ newlib_cflags="${newlib_cflags} -fPIC -D_I386MACH_NEED_SOTYPE_FUNCTION" # --- The three lines below are optional ------------------------------ diff --git a/newlib/libc/machine/powerpc/simdldtoa.c b/newlib/libc/machine/powerpc/simdldtoa.c index d4299186d..d15133afa 100644 --- a/newlib/libc/machine/powerpc/simdldtoa.c +++ b/newlib/libc/machine/powerpc/simdldtoa.c @@ -39,6 +39,9 @@ int _simdldcheck (LONG_DOUBLE_UNION *); /* The exponent of 1.0 */ #define EXONE (0x3fff) + /* Maximum exponent digits - base 10 */ + #define MAX_EXP_DIGITS 5 + /* Control structure for long doublue conversion including rounding precision values. * rndprc can be set to 80 (if NE=6), 64, 56, 53, or 24 bits. */ @@ -2701,7 +2704,7 @@ _simdldtoa_r (struct _reent *ptr, LONG_DOUBLE_UNION *d, int mode, int ndigits, i { unsigned short e[NI]; char *s, *p; -int k; +int i, j, k; LDPARMS rnd; LDPARMS *ldp = &rnd; char *outstr; @@ -2742,16 +2745,21 @@ if( mode != 3 ) For now, just ask for 20 digits which is enough but sometimes too many. */ if( mode == 0 ) ndigits = 20; + +/* reentrancy addition to use mprec storage pool */ +/* we want to have enough space to hold the formatted result */ +i = ndigits + (mode == 3 ? (MAX_EXP_DIGITS + 1) : 1); +j = sizeof (__ULong); +for (_REENT_MP_RESULT_K(ptr) = 0; sizeof (_Bigint) - sizeof (__ULong) + j <= i; j <<= 1) + _REENT_MP_RESULT_K(ptr)++; +_REENT_MP_RESULT(ptr) = Balloc (ptr, _REENT_MP_RESULT_K(ptr)); +outstr = (char *)_REENT_MP_RESULT(ptr); + /* This sanity limit must agree with the corresponding one in etoasc, to keep straight the returned value of outexpon. */ if( ndigits > NDEC ) ndigits = NDEC; -/* reentrancy addition to use mprec storage pool */ -_REENT_MP_RESULT(ptr) = Balloc (ptr, 3); -_REENT_MP_RESULT_K(ptr) = 3; -outstr = (char *)_REENT_MP_RESULT(ptr); - etoasc( e, outstr, ndigits, mode, ldp ); s = outstr; if( eisinf(e) || eisnan(e) ) diff --git a/newlib/libc/stdlib/ldtoa.c b/newlib/libc/stdlib/ldtoa.c index ca8b9f363..0e4476e66 100644 --- a/newlib/libc/stdlib/ldtoa.c +++ b/newlib/libc/stdlib/ldtoa.c @@ -41,6 +41,9 @@ void _IO_ldtostr(long double *, char *, int, int, char); /* The exponent of 1.0 */ #define EXONE (0x3fff) + /* Maximum exponent digits - base 10 */ + #define MAX_EXP_DIGITS 5 + /* Control structure for long doublue conversion including rounding precision values. * rndprc can be set to 80 (if NE=6), 64, 56, 53, or 24 bits. */ @@ -2703,7 +2706,7 @@ _ldtoa_r (struct _reent *ptr, long double d, int mode, int ndigits, int *decpt, { unsigned short e[NI]; char *s, *p; -int k; +int i, j, k; LDPARMS rnd; LDPARMS *ldp = &rnd; char *outstr; @@ -2744,16 +2747,21 @@ if( mode != 3 ) For now, just ask for 20 digits which is enough but sometimes too many. */ if( mode == 0 ) ndigits = 20; + +/* reentrancy addition to use mprec storage pool */ +/* we want to have enough space to hold the formatted result */ +i = ndigits + (mode == 3 ? (MAX_EXP_DIGITS + 1) : 1); +j = sizeof (__ULong); +for (_REENT_MP_RESULT_K(ptr) = 0; sizeof (_Bigint) - sizeof (__ULong) + j <= i; j <<= 1) + _REENT_MP_RESULT_K(ptr)++; +_REENT_MP_RESULT(ptr) = Balloc (ptr, _REENT_MP_RESULT_K(ptr)); +outstr = (char *)_REENT_MP_RESULT(ptr); + /* This sanity limit must agree with the corresponding one in etoasc, to keep straight the returned value of outexpon. */ if( ndigits > NDEC ) ndigits = NDEC; -/* reentrancy addition to use mprec storage pool */ -_REENT_MP_RESULT(ptr) = Balloc (ptr, 3); -_REENT_MP_RESULT_K(ptr) = 3; -outstr = (char *)_REENT_MP_RESULT(ptr); - etoasc( e, outstr, ndigits, mode, ldp ); s = outstr; if( eisinf(e) || eisnan(e) )