Mercurial > hg > octave-nkf > gnulib-hg
changeset 15959:a18c505b7981
vasnprintf: Optimize bit search operation.
* lib/vasnprintf.c (divide): Use optimizations from integer_length.c.
* m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF): Require
gl_DOUBLE_EXPONENT_LOCATION.
* modules/vasnprintf (Files): Add m4/exponentd.m4.
* modules/unistdio/u8-vasnprintf (Files): Likewise.
* modules/unistdio/u8-u8-vasnprintf (Files): Likewise.
* modules/unistdio/u16-vasnprintf (Files): Likewise.
* modules/unistdio/u16-u16-vasnprintf (Files): Likewise.
* modules/unistdio/u32-vasnprintf (Files): Likewise.
* modules/unistdio/u32-u32-vasnprintf (Files): Likewise.
* modules/unistdio/ulc-vasnprintf (Files): Likewise.
* m4/isnand.m4 (gl_PREREQ_ISNAND): Use AC_REQUIRE.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 15 Oct 2011 13:20:29 +0200 |
parents | ed8603738240 |
children | 85f5b7651b9a |
files | ChangeLog lib/vasnprintf.c m4/isnand.m4 m4/vasnprintf.m4 modules/unistdio/u16-u16-vasnprintf modules/unistdio/u16-vasnprintf modules/unistdio/u32-u32-vasnprintf modules/unistdio/u32-vasnprintf modules/unistdio/u8-u8-vasnprintf modules/unistdio/u8-vasnprintf modules/unistdio/ulc-vasnprintf modules/vasnprintf |
diffstat | 12 files changed, 81 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-10-15 Bruno Haible <bruno@clisp.org> + + vasnprintf: Optimize bit search operation. + * lib/vasnprintf.c (divide): Use optimizations from integer_length.c. + * m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF): Require + gl_DOUBLE_EXPONENT_LOCATION. + * modules/vasnprintf (Files): Add m4/exponentd.m4. + * modules/unistdio/u8-vasnprintf (Files): Likewise. + * modules/unistdio/u8-u8-vasnprintf (Files): Likewise. + * modules/unistdio/u16-vasnprintf (Files): Likewise. + * modules/unistdio/u16-u16-vasnprintf (Files): Likewise. + * modules/unistdio/u32-vasnprintf (Files): Likewise. + * modules/unistdio/u32-u32-vasnprintf (Files): Likewise. + * modules/unistdio/ulc-vasnprintf (Files): Likewise. + * m4/isnand.m4 (gl_PREREQ_ISNAND): Use AC_REQUIRE. + 2011-10-15 Bruno Haible <bruno@clisp.org> vasnprintf: Fix comments.
--- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -553,32 +553,61 @@ size_t s; { mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ - s = 31; - if (msd >= 0x10000) + /* Determine s = GMP_LIMB_BITS - integer_length (msd). + Code copied from gnulib's integer_length.c. */ +# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) + s = __builtin_clz (msd); +# else +# if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT + if (GMP_LIMB_BITS <= DBL_MANT_BIT) { - msd = msd >> 16; - s -= 16; + /* Use 'double' operations. + Assumes an IEEE 754 'double' implementation. */ +# define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7) +# define DBL_EXP_BIAS (DBL_EXP_MASK / 2 - 1) +# define NWORDS \ + ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) + union { double value; unsigned int word[NWORDS]; } m; + + /* Use a single integer to floating-point conversion. */ + m.value = msd; + + s = GMP_LIMB_BITS + - (((m.word[DBL_EXPBIT0_WORD] >> DBL_EXPBIT0_BIT) & DBL_EXP_MASK) + - DBL_EXP_BIAS); } - if (msd >= 0x100) - { - msd = msd >> 8; - s -= 8; - } - if (msd >= 0x10) + else +# undef NWORDS +# endif { - msd = msd >> 4; - s -= 4; + s = 31; + if (msd >= 0x10000) + { + msd = msd >> 16; + s -= 16; + } + if (msd >= 0x100) + { + msd = msd >> 8; + s -= 8; + } + if (msd >= 0x10) + { + msd = msd >> 4; + s -= 4; + } + if (msd >= 0x4) + { + msd = msd >> 2; + s -= 2; + } + if (msd >= 0x2) + { + msd = msd >> 1; + s -= 1; + } } - if (msd >= 0x4) - { - msd = msd >> 2; - s -= 2; - } - if (msd >= 0x2) - { - msd = msd >> 1; - s -= 1; - } +# endif } /* 0 <= s < GMP_LIMB_BITS. Copy b, shifting it left by s bits. */
--- a/m4/isnand.m4 +++ b/m4/isnand.m4 @@ -1,4 +1,4 @@ -# isnand.m4 serial 10 +# isnand.m4 serial 11 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -43,7 +43,7 @@ dnl Prerequisites of replacement isnand definition. It does not need -lm. AC_DEFUN([gl_PREREQ_ISNAND], [ - gl_DOUBLE_EXPONENT_LOCATION + AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION]) ]) dnl Test whether isnand() can be used with libm.
--- a/m4/vasnprintf.m4 +++ b/m4/vasnprintf.m4 @@ -1,4 +1,4 @@ -# vasnprintf.m4 serial 33 +# vasnprintf.m4 serial 34 dnl Copyright (C) 2002-2004, 2006-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -64,6 +64,9 @@ dnl Use the _snprintf function only if it is declared (because on NetBSD it dnl is defined as a weak alias of snprintf; we prefer to use the latter). AC_CHECK_DECLS([_snprintf], , , [[#include <stdio.h>]]) + dnl Knowing DBL_EXPBIT0_WORD and DBL_EXPBIT0_BIT enables an optimization + dnl in the code for NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE. + AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION]) dnl We can avoid a lot of code by assuming that snprintf's return value dnl conforms to ISO C99. So check that. AC_REQUIRE([gl_SNPRINTF_RETVAL_C99])
--- a/modules/unistdio/u16-u16-vasnprintf +++ b/modules/unistdio/u16-u16-vasnprintf @@ -13,6 +13,7 @@ m4/intmax_t.m4 m4/stdint_h.m4 m4/inttypes_h.m4 +m4/exponentd.m4 Depends-on: unistdio/base
--- a/modules/unistdio/u16-vasnprintf +++ b/modules/unistdio/u16-vasnprintf @@ -13,6 +13,7 @@ m4/intmax_t.m4 m4/stdint_h.m4 m4/inttypes_h.m4 +m4/exponentd.m4 Depends-on: unistdio/base
--- a/modules/unistdio/u32-u32-vasnprintf +++ b/modules/unistdio/u32-u32-vasnprintf @@ -13,6 +13,7 @@ m4/intmax_t.m4 m4/stdint_h.m4 m4/inttypes_h.m4 +m4/exponentd.m4 Depends-on: unistdio/base
--- a/modules/unistdio/u32-vasnprintf +++ b/modules/unistdio/u32-vasnprintf @@ -13,6 +13,7 @@ m4/intmax_t.m4 m4/stdint_h.m4 m4/inttypes_h.m4 +m4/exponentd.m4 Depends-on: unistdio/base
--- a/modules/unistdio/u8-u8-vasnprintf +++ b/modules/unistdio/u8-u8-vasnprintf @@ -13,6 +13,7 @@ m4/intmax_t.m4 m4/stdint_h.m4 m4/inttypes_h.m4 +m4/exponentd.m4 Depends-on: unistdio/base
--- a/modules/unistdio/u8-vasnprintf +++ b/modules/unistdio/u8-vasnprintf @@ -13,6 +13,7 @@ m4/intmax_t.m4 m4/stdint_h.m4 m4/inttypes_h.m4 +m4/exponentd.m4 Depends-on: unistdio/base