mirror of
https://github.com/qemu/qemu.git
synced 2024-12-25 05:03:41 +08:00
include: Add a comment to explain the origin of sizes' lookup table
The lookup table for power-of-two sizes was added in commit 540b849261
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>
This commit is contained in:
parent
3dd5b8f471
commit
1240ac558d
@ -17,6 +17,24 @@
|
||||
#define PiB (INT64_C(1) << 50)
|
||||
#define EiB (INT64_C(1) << 60)
|
||||
|
||||
/*
|
||||
* The following lookup table is intended to be used when a literal string of
|
||||
* the number of bytes is required (for example if it needs to be stringified).
|
||||
* It can also be used for generic shortcuts of power-of-two sizes.
|
||||
* This table is generated using the AWK script below:
|
||||
*
|
||||
* 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);
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
|
||||
#define S_1KiB 1024
|
||||
#define S_2KiB 2048
|
||||
#define S_4KiB 4096
|
||||
|
Loading…
Reference in New Issue
Block a user