vfprintf.c patch

Joel Sherrill joel.sherrill@OARcorp.com
Fri Dec 1 06:22:00 GMT 2000

Minor modification to trick gcc into avoiding referencing
a floating point register unless someone really tries
to print a floating point number.  On the PowerPC gcc
will save a FP register all the time without this patch.

The ideal solution would be to break out the FP printing 
into a separate function but that was more risky to implement.

[NOTE: In RTEMS, you specify on a task per task basis whether
floating point is required.  On cpus which can disable the FPU,
it does so.  This runs into trouble in cases like this. On CPUs
which use the FPU for multiplication like the HPPA, the FPU
has to be left on for all tasks.  The purpose of this is to
avoid saving and restoring the FPU context.]

Joel Sherrill, Ph.D.             Director of Research & Development
joel@OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985
Index: newlib/libc/stdio/vfprintf.c
RCS file: /cvs/src/src/newlib/libc/stdio/vfprintf.c,v
retrieving revision 1.5
diff -u -r1.5 vfprintf.c
--- vfprintf.c	2000/08/16 18:30:40	1.5
+++ vfprintf.c	2000/12/01 13:20:18
@@ -301,7 +301,21 @@
 	char *decimal_point = localeconv()->decimal_point;
 	char softsign;		/* temporary negative sign for floats */
+	/*
+	 * Although it is natural to declare this double here, the 
+	 * declaration causes gcc to save FP registers even when not
+	 * printing an FP number.  This results in surprising use
+	 * of FP registers to print integers or strings on at least the
+	 * PowerPC.  A more proper solution would be to move FP printing
+	 * to another file, but this does seem to work.
+	 */
+#if 0
 	double _double;		/* double precision arguments %[eEfgG] */
+			        /* double precision arguments %[eEfgG] */
+	union { int i; double d; } _double_ = {0};
+#define _double (_double_.d)
 	int expt;		/* integer value of exponent */
 	int expsize;		/* character count for expstr */
 	int ndig;		/* actual number of digits returned by cvt */

More information about the Newlib mailing list