summaryrefslogtreecommitdiffstats
path: root/include/qemu/units.h
Commit message (Collapse)AuthorAgeFilesLines
* block: Eliminate the S_1KiB, S_2KiB, ... macrosMarkus Armbruster2019-02-011-73/+0Star
| | | | | | | | | | | | | | | | | | We define 54 macros for the powers of two >= 1024. We use six, in six macro definitions. Four of them could just as well use the common MiB macro, so do that. The remaining two can't, because they get passed to stringify. Replace the macro by the literal number there. Slightly harder to read in one instance (1048576 vs. S_1MiB), so add a comment there. The other instance is a wash: 65536 vs S_64KiB. 65536 has been good enough for more than seven years there. This effectively reverts commit 540b8492618 and 1240ac558d3. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Alberto Garcia <berto@igalia.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* include: Add a comment to explain the origin of sizes' lookup tableLeonid Bloch2018-11-051-0/+18
| | | | | | | | | | | | | | | | | | | | | | The lookup table for power-of-two sizes was added in commit 540b8492618eb for the purpose of having convenient shortcuts for these sizes in cases when the literal number has to be present at compile time, and expressions as '(1 * KiB)' can not be used. One such case is the stringification of sizes. Beyond that, it is convenient to use these shortcuts for all power-of-two sizes, even if they don't have to be literal numbers. Despite its convenience, this table introduced 55 lines of "dumb" code, the purpose and origin of which are obscure without reading the message of the commit which introduced it. This patch fixes that by adding a comment to the code itself with a brief explanation for the reasoning behind this table. This comment includes the short AWK script that generated the table, so that anyone who's interested could make sure that the values in it are correct (otherwise these values look as if they were typed manually). Signed-off-by: Leonid Bloch <lbloch@janustech.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* include: Add a lookup table of sizesLeonid Bloch2018-10-011-0/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | 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: Add IEC binary prefixes in "qemu/units.h"Philippe Mathieu-Daudé2018-07-021-0/+20
Loosely based on 076b35b5a56. Suggested-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20180625124238.25339-2-f4bug@amsat.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>