improve printf locality

Eric Blake ebb9@byu.net
Thu May 10 20:07:00 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On cygwin, where newlib is configured with --enable-newlib-io-long-double,
print consumed more than an entire page of virtual memory in stack space!
 This causes unnecessary page faults, decreased cache locality, and other
potential slowdowns.  It was because at one point in history, newlib used
to stack allocate the worst case length for %Lf output (if you have a
128-bit long double with a 15 bit exponent, this can result in more than
4900 characters).  But now newlib uses struct _reent to manage %f output,
so the storage claimed by buf[BUF] was 90% unused.

This also fixes some problems with the radix character (if newlib ever
supports non-C locales, it must use the radix in a thread-safe and
consistent manner), and optimizes %S processing to avoid malloc for short
strings.

OK to apply?

2007-05-10  Eric Blake  <ebb9@byu.net>

	* libc/stdio/vfprintf.c (_VFPRINTF_R): Fix use of decimal point
	in %f and %e.  Avoid malloc when possible for %S.
	(BUF): Improve stack locality by using smaller size.
	(MAXEXP): Define.
	(exponent): Use for smaller stack size.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGQxjP84KuGfSFAYARAkHVAJ9h+3AtSHn/GguQUdaRR/D1x5CYwgCgghzJ
bvJXSbMXLwfyIKFu28pNrmc=
=BdL0
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: newlib.patch14
URL: <http://sourceware.org/pipermail/newlib/attachments/20070510/d5b0c383/attachment.ksh>


More information about the Newlib mailing list