The patch below boosts performance of decimal formatting of integers by
roughly a factor of 2 on ARM7 CPU without hardware integer division. In
fact it replaces integer modulo operation with multiply and subtract,
that hopefully is either faster or roughly the same on all supported
CPUs.

Index: packages/language/c/libc/stdio/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdio/current/ChangeLog,v
retrieving revision 1.38
diff -u -r1.38 ChangeLog
--- packages/language/c/libc/stdio/current/ChangeLog	27 Sep 2006 16:18:18 -0000	1.38
+++ packages/language/c/libc/stdio/current/ChangeLog	22 Dec 2006 16:13:47 -0000
@@ -1,3 +1,9 @@
+2006-12-22  Sergei Organov  <[EMAIL PROTECTED]>
+
+	* src/output/vfnprintf.cxx (vfnprintf): Speed-up formatting of
+	decimal integers by replacing modulo operation with multiply and
+	subtract.
+
 2006-09-27  Jonathan Larmour  <[EMAIL PROTECTED]>
 
 	* include/stdio.h: Make fpos_t be signed to allow negative
Index: packages/language/c/libc/stdio/current/src/output/vfnprintf.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdio/current/src/output/vfnprintf.cxx,v
retrieving revision 1.8
diff -u -r1.8 vfnprintf.cxx
--- packages/language/c/libc/stdio/current/src/output/vfnprintf.cxx	15 Mar 2004 15:21:44 -0000	1.8
+++ packages/language/c/libc/stdio/current/src/output/vfnprintf.cxx	22 Dec 2006 16:13:51 -0000
@@ -555,8 +555,9 @@
                                 case DEC:
                                         /* many numbers are 1 digit */
                                         while (_uquad >= 10) {
-                                                *--cp = to_char(_uquad % 10);
-                                                _uquad /= 10;
+                                                u_quad_t next = _uquad / 10;
+                                                *--cp = to_char(_uquad - (next * 10));
+                                                _uquad = next;
                                         }
                                         *--cp = to_char(_uquad);
                                         break;

Reply via email to