[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] printf speed up and presentation of new functions

From: Dmitry K.
Subject: [avr-libc-dev] printf speed up and presentation of new functions
Date: Mon, 7 Feb 2005 17:22:53 +1000
User-agent: KMail/1.5

Hi all.

Now performance of function `sprintf(s,"%d",12345)' takes more than
7000 clocks. The reason -- division (long) which is required for a
conversion of each digit. I have tried to replace division into more
simple operations. In result this time became 1500 clocks. For 'hex' or
'octal' -- 1100 clocks. The general size has a little decreased. (After
the termination of testing I shall send a patch on `savannah'.)

The code which is carrying out transformation, is made out as separate
function. I believe, that this function (the family of functions on its
base is more exact) could be useful as well independently.

I suggest to discuss details of design of such family of functions.

char * itoa_fast (int val, char *s, int base);
char * utoa_fast (unsigned val, char *s, int base);
char * ltoa_fast (long val, char *s, int base);
char * ultoa_fast (unsigned long val, char *s, int base);

/* Internal function for use from `printf'.     */
char * ultoa_invert (unsigned long val, char *s, int base);

/* Next flags are to use with `base'. Unused fields are reserved
   for future extensions.       */

#define XTOA_PREFIX     0x0100  /* put prefix for octal or hex  */
#define XTOA_UPPER      0x0200  /* use upper case letters       */
#define XTOA_BYTE       0x0400  /* expand width to full byte    */
#define XTOA_WORD       0x0800  /* expand width to full 2 bytes */
#define XTOA_DWORD      0x1000  /* expand width to full 4 bytes */

1. These functions do not replace 'itoa' (and other) as work with values
'base' only 8, 10 and 16.

2. Besides actually transformation of number, it is probably elementary
formatting (a prefix, a choice of the register of letters, filling of a
field to the fixed length).  For example:
    utoa_fast (255, s, XTOA_PREFIX | XTOA_WORD | 16)

3. Filling is done by spaces for the decimal basis and zero for other.
The width of a field depends from 'base'. In case of an output of result
abroad truncation is not done (similarly 'printf').


reply via email to

[Prev in Thread] Current Thread [Next in Thread]