From: Nick Thompson <nick.thompson@ge.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Avoid use of divides in print_size.
Date: Mon, 10 May 2010 10:51:40 +0100 [thread overview]
Message-ID: <4BE7D72C.3090002@ge.com> (raw)
Modification of print_size to avoid use of divides and especially
long long divides. Keep the binary scale factor in terms of bit
shifts instead. This should be faster, since the previous code
gave the compiler no clues that the divides where always powers
of two, preventing optimisation.
Signed-off-by: Nick Thompson <nick.thompson@ge.com>
---
This patch should make print_size a little faster, but perhaps
nobody cares about that too much. What it also does though is
reenable U-Boot linking for ARM with standard toolchains.
(e.g. CodeSourcery and MontaVista).
lib/display_options.c | 14 ++++++++------
1 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/lib/display_options.c b/lib/display_options.c
index 86df05d..636916d 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -46,13 +46,14 @@ int display_options (void)
void print_size(unsigned long long size, const char *s)
{
unsigned long m = 0, n;
+ unsigned long long f;
static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
- unsigned long long d = 1ULL << (10 * ARRAY_SIZE(names));
+ unsigned long d = 10 * ARRAY_SIZE(names);
char c = 0;
unsigned int i;
- for (i = 0; i < ARRAY_SIZE(names); i++, d >>= 10) {
- if (size >= d) {
+ for (i = 0; i < ARRAY_SIZE(names); i++, d -= 10) {
+ if (size >> d) {
c = names[i];
break;
}
@@ -63,11 +64,12 @@ void print_size(unsigned long long size, const char *s)
return;
}
- n = size / d;
+ n = size >> d;
+ f = size & ((1ULL << d) - 1);
/* If there's a remainder, deal with it */
- if(size % d) {
- m = (10 * (size - (n * d)) + (d / 2) ) / d;
+ if (f) {
+ m = (10ULL * (f + (1 << (d - 1)))) >> d;
if (m >= 10) {
m -= 10;
--
1.7.0.4
next reply other threads:[~2010-05-10 9:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-10 9:51 Nick Thompson [this message]
2010-05-10 18:51 ` [U-Boot] [PATCH] Avoid use of divides in print_size Timur Tabi
2010-05-10 19:25 ` Timur Tabi
2010-05-11 8:31 ` Nick Thompson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4BE7D72C.3090002@ge.com \
--to=nick.thompson@ge.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox