aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thompson <nick.thompson@ge.com>2010-05-11 11:29:52 +0100
committerWolfgang Denk <wd@denx.de>2010-05-17 23:23:39 +0200
commitf2d76ae4fdde180e120ea2d29d6ef881360b3cba (patch)
treec5627398a3f653f1889e92ce6c5ba2355d9118e5
parenta599cde7698acc5ae3d0f731b4a7d63a931aae63 (diff)
downloadu-boot-linaro-stable-f2d76ae4fdde180e120ea2d29d6ef881360b3cba.tar.gz
Avoid use of divides in print_size
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> Acked-by: Timur Tabi <timur@freescale.com>
-rw-r--r--lib/display_options.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/display_options.c b/lib/display_options.c
index 86df05d9e..a711425b9 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 + (1ULL << (d - 1))) >> d;
if (m >= 10) {
m -= 10;