]> git.proxmox.com Git - mirror_qemu.git/commit
include: Add a lookup table of sizes
authorLeonid Bloch <lbloch@janustech.com>
Wed, 26 Sep 2018 16:04:40 +0000 (19:04 +0300)
committerKevin Wolf <kwolf@redhat.com>
Mon, 1 Oct 2018 10:51:12 +0000 (12:51 +0200)
commit540b8492618ebbe98e7462bd7d31361b8cb10a05
tree4ccf74af338a00bea794cedfeeac886ee69f96ac
parent40fb215d483ce510e211b843352288894eb13285
include: Add a lookup table of sizes

Adding a lookup table for the powers of two, with the appropriate size
prefixes. This is needed when a size has to be stringified, in which
case something like '(1 * KiB)' would become a literal '(1 * (1L << 10))'
string. Powers of two are used very often for sizes, so such a table
will also make it easier and more intuitive to write them.

This table is generatred using the following AWK script:

BEGIN {
suffix="KMGTPE";
for(i=10; i<64; i++) {
val=2**i;
s=substr(suffix, int(i/10), 1);
n=2**(i%10);
pad=21-int(log(n)/log(10));
printf("#define S_%d%siB %*d\n", n, s, pad, val);
}
}

Signed-off-by: Leonid Bloch <lbloch@janustech.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
include/qemu/units.h