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

Timur Tabi timur.tabi at gmail.com
Mon May 10 21:25:02 CEST 2010


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

That last one is probably an overflow.
-- 
Timur Tabi
Linux kernel developer at Freescale


More information about the U-Boot mailing list