From mboxrd@z Thu Jan 1 00:00:00 1970 From: Timur Tabi Date: Tue, 30 Mar 2010 17:32:59 -0500 Subject: [U-Boot] [PATCH] fix print_size printing fractional gigabyte numbers on 32-bit platforms In-Reply-To: <4BB278F1.40705@freescale.com> References: <1269985996-13130-1-git-send-email-timur@freescale.com> <4BB275B7.90509@freescale.com> <4BB2766F.9070808@freescale.com> <4BB278F1.40705@freescale.com> Message-ID: <4BB27C1B.8000301@freescale.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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. 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) Both appear to be wrong. If we want to treat (n * d) as a u64, we need to be explicit. Casting "(n * d)" to a u64 just doesn't work. We have to cast (or make) either 'n' or 'd' to a u64. I think the simplest approach is make 'd' into a u64. -- Timur Tabi Linux kernel developer at Freescale