[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Speeding [u]ltoa by 35%
From: |
Georg-Johann Lay |
Subject: |
Re: [avr-gcc-list] Speeding [u]ltoa by 35% |
Date: |
Tue, 19 Jun 2012 22:51:01 +0200 |
User-agent: |
Thunderbird 2.0.0.24 (Windows/20100228) |
Joerg Wunsch schrieb:
In article <address@hidden> 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