[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 36/36] include: Add a comment to explain the origin o
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 36/36] include: Add a comment to explain the origin of sizes' lookup table |
Date: |
Mon, 5 Nov 2018 17:37:44 +0100 |
From: Leonid Bloch <address@hidden>
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 <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
include/qemu/units.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/include/qemu/units.h b/include/qemu/units.h
index 68a7758650..1c959d182e 100644
--- a/include/qemu/units.h
+++ b/include/qemu/units.h
@@ -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
--
2.19.1
- [Qemu-devel] [PULL 32/36] qdev-monitor: Make device options help nicer, (continued)
- [Qemu-devel] [PULL 32/36] qdev-monitor: Make device options help nicer, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 35/36] vdi: Use a literal number of bytes for DEFAULT_CLUSTER_SIZE, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 28/36] block: Make auto-read-only=on default for -drive, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 20/36] block: Add auto-read-only option, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 34/36] fw_cfg: Drop newline in @file description, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 29/36] qemu-iotests: Test auto-read-only with -drive and -blockdev, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 24/36] file-posix: Support auto-read-only option, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 21/36] rbd: Close image in qemu_rbd_open() error path, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 26/36] gluster: Support auto-read-only option, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 36/36] include: Add a comment to explain the origin of sizes' lookup table,
Kevin Wolf <=
- [Qemu-devel] [PULL 33/36] object: Make option help nicer to read, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 25/36] curl: Support auto-read-only option, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 27/36] iscsi: Support auto-read-only option, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 13/36] block/vdi: Don't take address of fields in packed structs, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 16/36] iotest: Test the blkverify mode of the Quorum driver, Kevin Wolf, 2018/11/05
- [Qemu-devel] [PULL 17/36] quorum: Forbid adding children in blkverify mode, Kevin Wolf, 2018/11/05
- Re: [Qemu-devel] [PULL 00/36] Block layer patches, Peter Maydell, 2018/11/05