[U-Boot] [PATCH] *** SUBJECT HERE ***

This trivial patch remove the 64-bit division into print_size code.
Luigi 'Comio' Mantellini (1): [OLT-M68K] Avoid 64bit division in print_size
lib/display_options.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-)

Signed-off-by: Luigi 'Comio' Mantellini luigi.mantellini@idf-hit.com --- lib/display_options.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/display_options.c b/lib/display_options.c index 86df05d..eca5415 100644 --- a/lib/display_options.c +++ b/lib/display_options.c @@ -45,14 +45,14 @@ int display_options (void) */ void print_size(unsigned long long size, const char *s) { - unsigned long m = 0, n; + unsigned long m = 0, n, rem; static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'}; - unsigned long long d = 1ULL << (10 * ARRAY_SIZE(names)); + unsigned int d_shift = 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_shift -= 10) { + if (size >= (1ULL << d_shift)) { c = names[i]; break; } @@ -63,11 +63,12 @@ void print_size(unsigned long long size, const char *s) return; }
- n = size / d; + n = size >> d_shift; + rem = size - (n << d_shift);
/* If there's a remainder, deal with it */ - if(size % d) { - m = (10 * (size - (n * d)) + (d / 2) ) / d; + if(rem) { + m = (10 * rem + (1ULL << (d_shift -1 ))) >> d_shift;
if (m >= 10) { m -= 10;

On Wed, May 26, 2010 at 9:01 AM, Luigi 'Comio' Mantellini luigi.mantellini@idf-hit.com wrote:
Signed-off-by: Luigi 'Comio' Mantellini luigi.mantellini@idf-hit.com
You're a little late:
http://git.denx.de/?p=u-boot.git;a=commit;h=f2d76ae4fdde180e120ea2d29d6ef881...

I'm sorry! my tree is out of date (2010/05/15) :)
I'm using the toolchain coldfire-4.4 from Codesourcery (Sourcery G++ Lite 4.4-217)
Today I tried to build the cf547x_8x target and I noticed a div by 0 issue on the __udivdi3 (n = size / d) ... I checked the operands that were ok, but I wasn't able to understand the real problem. In order to avoid the (bugged?) __udivdi3 call I wrote this workaroud. Any idea regarding this issue?
Of course, avoiding the __udivdi3 call, the u-boot works fine.
best regards,
luigi
mercoledì 26 maggio 2010 17:32 Timur Tabi timur.tabi@gmail.com ha scritto:
On Wed, May 26, 2010 at 9:01 AM, Luigi 'Comio' Mantellini
luigi.mantellini@idf-hit.com wrote:
Signed-off-by: Luigi 'Comio' Mantellini luigi.mantellini@idf-hit.com
You're a little late:
http://git.denx.de/?p=u-boot.git;a=commit;h=f2d76ae4fdde180e120ea2d29d6ef88 1360b3cba
participants (2)
-
Luigi 'Comio' Mantellini
-
Timur Tabi