[U-Boot] [PATCH] Avoid use of divides in print_size.

Nick Thompson nick.thompson at ge.com
Tue May 11 10:31:07 CEST 2010


On 10/05/10 20:25, Timur Tabi wrote:
> Here's a more revealing test:
> 
> 		unsigned int i;
> 
> 		for (i = 0; i < 60; i++) {
> 			unsigned long long l = 45ULL << i;
> 			printf("%llu - ", l);
> 			print_size(l, "\n");
> 		}
> 
> prints:
> 
> 45 - 45 Bytes
> 90 - 90 Bytes
> 180 - 180 Bytes
> 360 - 360 Bytes
> 720 - 720 Bytes
> 1440 - 1.9 KiB
> 2880 - 3.3 KiB
> 5760 - 6.1 KiB
[snip]

Ahh, your testing foo is strong. That is a better test than mine. I have
submitted a new patch which, with your test, gives (value - old new):

45 - 45 Bytes 45 Bytes
90 - 90 Bytes 90 Bytes
180 - 180 Bytes 180 Bytes
360 - 360 Bytes 360 Bytes
720 - 720 Bytes 720 Bytes
1440 - 1.4 KiB 1.4 KiB
2880 - 2.8 KiB 2.8 KiB
5760 - 5.6 KiB 5.6 KiB
11520 - 11.3 KiB 11.3 KiB
23040 - 22.5 KiB 22.5 KiB
46080 - 45 KiB 45 KiB
92160 - 90 KiB 90 KiB
184320 - 180 KiB 180 KiB
368640 - 360 KiB 360 KiB
737280 - 720 KiB 720 KiB
1474560 - 1.4 MiB 1.4 MiB
2949120 - 2.8 MiB 2.8 MiB
5898240 - 5.6 MiB 5.6 MiB
11796480 - 11.3 MiB 11.3 MiB
23592960 - 22.5 MiB 22.5 MiB
47185920 - 45 MiB 45 MiB
94371840 - 90 MiB 90 MiB
188743680 - 180 MiB 180 MiB
377487360 - 360 MiB 360 MiB
754974720 - 720 MiB 720 MiB
1509949440 - 1.4 GiB 1.4 GiB
3019898880 - 2.8 GiB 2.8 GiB
6039797760 - 5.6 GiB 5.6 GiB
12079595520 - 11.3 GiB 11.3 GiB
24159191040 - 22.5 GiB 22.5 GiB
48318382080 - 45 GiB 45 GiB
96636764160 - 90 GiB 90 GiB
193273528320 - 180 GiB 180 GiB
386547056640 - 360 GiB 360 GiB
773094113280 - 720 GiB 720 GiB
1546188226560 - 1.4 TiB 1.4 TiB
3092376453120 - 2.8 TiB 2.8 TiB
6184752906240 - 5.6 TiB 5.6 TiB
12369505812480 - 11.3 TiB 11.2 TiB
24739011624960 - 22.5 TiB 22.5 TiB
49478023249920 - 45 TiB 45 TiB
98956046499840 - 90 TiB 90 TiB
197912092999680 - 180 TiB 180 TiB
395824185999360 - 360 TiB 360 TiB
791648371998720 - 720 TiB 720 TiB
1583296743997440 - 1.4 PiB 1.4 PiB
3166593487994880 - 2.8 PiB 2.8 PiB
6333186975989760 - 5.6 PiB 5.6 PiB
12666373951979520 - 11.3 PiB 11.2 PiB
25332747903959040 - 22.5 PiB 22.5 PiB
50665495807918080 - 45 PiB 45 PiB
101330991615836160 - 90 PiB 90 PiB
202661983231672320 - 180 PiB 180 PiB
405323966463344640 - 360 PiB 360 PiB
810647932926689280 - 720 PiB 720 PiB
1621295865853378560 - 1.4 EiB 1.4 EiB
3242591731706757120 - 2.8 EiB 2.8 EiB
6485183463413514240 - 5.6 EiB 5.6 EiB
12970366926827028480 - 11.3 EiB 11.2 EiB
7493989779944505344 - 6.5 EiB 6.5 EiB

I was using 5 as a round-up rather than 0.5 due to some extraneous ()'s.
(10 * 0.5)...

> 
> That last one is probably an overflow.

I believe so, yes.

Thank you for supplying the test code.

Regards,
Nick.


More information about the U-Boot mailing list