optimize printf size without the common runtime

When a platform is built without the common runtime to optimize for
flash size, remove the 64-bit support in printf to save more space
(mainly by getting rid of the uint64divmod helper).

This saves 376 bytes of flash on Zinger/MiniMuffin.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BRANCH=none
BUG=none
TEST=make buildall and compare flash size with and without the change.
the common runtime binaries are identical excepted the version
information.

Change-Id: I1e7237e693df9ea23291c8c0fe414c3b5c716848
Reviewed-on: https://chromium-review.googlesource.com/265052
Trybot-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Vincent Palatin
2015-04-09 12:28:49 -07:00
committed by ChromeOS Commit Bot
parent 8d47a1de0a
commit 686a23585e

View File

@@ -13,6 +13,22 @@ static const char error_str[] = "ERROR";
#define MAX_FORMAT 1024 /* Maximum chars in a single format field */
#ifdef CONFIG_COMMON_RUNTIME
static inline int divmod(uint64_t *n, int d)
{
return uint64divmod(n, d);
}
#else /* !CONFIG_COMMON_RUNTIME */
/* if we are optimizing for size, remove the 64-bit support */
#define NO_UINT64_SUPPORT
static inline int divmod(uint32_t *n, int d)
{
int r = *n % d;
*n /= d;
return r;
}
#endif
/**
* Convert the lowest nibble of a number to hex
*
@@ -152,8 +168,13 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
continue;
} else {
uint64_t v;
int base = 10;
#ifdef NO_UINT64_SUPPORT
uint32_t v;
v = va_arg(args, uint32_t);
#else /* NO_UINT64_SUPPORT */
uint64_t v;
/* Handle length */
if (c == 'l') {
@@ -171,6 +192,7 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
} else {
v = va_arg(args, uint32_t);
}
#endif
switch (c) {
case 'd':
@@ -224,7 +246,7 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
* numbers.
*/
for (vlen = 0; vlen < precision; vlen++)
*(--vstr) = '0' + uint64divmod(&v, 10);
*(--vstr) = '0' + divmod(&v, 10);
if (precision)
*(--vstr) = '.';
@@ -232,7 +254,7 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
*(--vstr) = '0';
while (v) {
int digit = uint64divmod(&v, base);
int digit = divmod(&v, base);
if (digit < 10)
*(--vstr) = '0' + digit;
else if (c == 'X')