summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2015-04-09 12:28:49 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-04-10 23:29:27 +0000
commit686a23585e2bc8a357842bd30ea3cae0cc5648da (patch)
tree5688630adb272b1bc60e198312416b6a7bed6d1c
parent8d47a1de0a97243aa4e770ad0e332a71890c1e85 (diff)
downloadchrome-ec-686a23585e2bc8a357842bd30ea3cae0cc5648da.tar.gz
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>
-rw-r--r--common/printf.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/common/printf.c b/common/printf.c
index 786d46711d..6e1a7401e9 100644
--- a/common/printf.c
+++ b/common/printf.c
@@ -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')