Joerg Wunsch schrieb:
In article <4fe0237c.9020...@gjlay.de> you write:
* Speed gain 34%..39% see [1] and [2] for detail analysis

* Code size is same as old implementation

Sounds appealing!

Here is a commented version with an average time reduction
of ~45% for the signed version.

Size for ATmega168 is (no relaxing)

Old: 104 (signed)
New:  94 (signed)
New:  64 (unsigned)

If the maintainers don't like the C code, they can use the
sanity check from the original post to get a pure assembler
implementation and equal code size.




#define SIGNED 1

#if SIGNED
static __inline__ __attribute__((__always_inline__))
char* ltoa (long x, char *str, int radix)
{
    if (radix < 2 || radix > 36)
    {
        *str = '\0';
        return str;
    }
    else
    {
        extern char* __ltoa_asm (long, char*, unsigned char);
        return __ltoa_asm (x, str, (unsigned char) radix);
    }
}
#else
static __inline__ __attribute__((__always_inline__))
char* ultoa (unsigned long x, char *str, int radix)
{
    if (radix < 2 || radix > 36)
    {
        *str = '\0';
        return str;
    }
    else
    {
        extern char* __ultoa_asm (unsigned long, char*, unsigned char);
        return __ultoa_asm (x, str, (unsigned char) radix);
    }
}
#endif // SIGNED

<<inline: ltoa.asm>>

_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to