From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] fix print_size printing fractional gigabyte numbers on 32-bit platforms
Date: Tue, 30 Mar 2010 17:39:31 -0500 [thread overview]
Message-ID: <4BB27DA3.1010302@freescale.com> (raw)
In-Reply-To: <4BB27C1B.8000301@freescale.com>
Timur Tabi wrote:
> Scott Wood wrote:
>
>> It would make the 10 * (...) product 64-bit regardless of phys_size_t,
>> without changing the function signature (overflow is an internal
>> implementation detail).
>
> You are right that (n * d) is evaluated as a 32-bit integer:
>
> print_size(5905580032)= 6.35 GB
>
> However, changing "10" to "10ULL" does not fix this.
It's not supposed to.
There are two different overflows, 10*expr and n*d.
Today, 10*expr overflows and n*d doesn't. With your patch, n*d
overflows and 10*expr doesn't.
I was suggesting a simple way to fix 10*expr without other changes.
> I think this is because we are both expecting integer sizes to commute across arithmetic operations. That is, I assumed that:
>
> u64 - (u32 * u32)
>
> would be treated as
>
> u64 - ((u64)u32 * u32)
>
> And you assumed that
>
> u64 * (u32 - u32)
>
> would be treated as
>
> u64 * (u32 - (u64) u32)
I assumed no such thing.
What I assumed was that the n*d overflow only matters if phys_size_t is
64-bit, because it should always be less than size.
-Scott
prev parent reply other threads:[~2010-03-30 22:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-30 21:53 [U-Boot] [PATCH] fix print_size printing fractional gigabyte numbers on 32-bit platforms Timur Tabi
2010-03-30 22:05 ` Scott Wood
2010-03-30 22:08 ` Timur Tabi
2010-03-30 22:19 ` Scott Wood
2010-03-30 22:32 ` Timur Tabi
2010-03-30 22:39 ` Scott Wood [this message]
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=4BB27DA3.1010302@freescale.com \
--to=scottwood@freescale.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