From patchwork Sun Nov 4 18:07:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 10666975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 984FB13A4 for ; Sun, 4 Nov 2018 18:08:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AF20297C1 for ; Sun, 4 Nov 2018 18:08:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C881296D0; Sun, 4 Nov 2018 18:08:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F160B294FE for ; Sun, 4 Nov 2018 18:08:52 +0000 (UTC) Received: from localhost ([::1]:59802 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJMpQ-0006a7-1x for patchwork-qemu-devel@patchwork.kernel.org; Sun, 04 Nov 2018 13:08:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJMoF-0004P3-4I for qemu-devel@nongnu.org; Sun, 04 Nov 2018 13:07:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJMoB-0002SQ-8s for qemu-devel@nongnu.org; Sun, 04 Nov 2018 13:07:38 -0500 Received: from mail-eopbgr720123.outbound.protection.outlook.com ([40.107.72.123]:3488 helo=NAM05-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJMoA-0002F1-FQ; Sun, 04 Nov 2018 13:07:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janustech.onmicrosoft.com; s=selector1-janustech-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E3aK7+XBZBZgCd9d7xu2EBjfqECk89G0HelicbHhnRU=; b=DVaBmLt7ZPKrW9XiUpogCXApBpaUj3u0wS1x4TQlG1i3NLkRimSCqEs8TsfIA/tcU6RPUMa9dupBmRZIGuC8egEZQBAksb7yxoXO+fswdL6nqhylVVSuzTC5cO0LT/BXqWtj4W4/HU/QKfoCf5kYc7az+SSjZbm/yTF+B0DUMYA= Received: from CY1PR07MB2619.namprd07.prod.outlook.com (10.167.16.145) by CY1PR07MB2730.namprd07.prod.outlook.com (10.166.206.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.23; Sun, 4 Nov 2018 18:07:28 +0000 Received: from CY1PR07MB2619.namprd07.prod.outlook.com ([fe80::4148:a47b:92b5:588c]) by CY1PR07MB2619.namprd07.prod.outlook.com ([fe80::4148:a47b:92b5:588c%7]) with mapi id 15.20.1294.028; Sun, 4 Nov 2018 18:07:28 +0000 From: Leonid Bloch To: "qemu-devel@nongnu.org" , =?iso-8859-1?q?Philippe?= =?iso-8859-1?q?_Mathieu-Daud=E9?= Thread-Topic: [PATCH v2 1/1] include: Add a comment to explain the origin of sizes' lookup table Thread-Index: AQHUdGk/ihewJnrQdEaDpbhXOocung== Date: Sun, 4 Nov 2018 18:07:28 +0000 Message-ID: <20181104180657.7471-2-lbloch@janustech.com> References: <20181104180657.7471-1-lbloch@janustech.com> In-Reply-To: <20181104180657.7471-1-lbloch@janustech.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6P192CA0097.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::38) To CY1PR07MB2619.namprd07.prod.outlook.com (2a01:111:e400:c637::17) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [141.226.29.227] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CY1PR07MB2730; 6:XSwipR3gyTS9s3n+ZJqGDoe8mAQtn5Hpf5MUue+TAFLjGJu3RiK1RMZzsfCPGvORgC6QvkKpc/To9XAKB2jvMhZvrQC1Y5mgCwexEP3SV3laqWH83CgTpNMCbqCBJc04epESNxrJYNWzzxtOAFUo30pMi3FJMlara0GLS37nDC3zEqQVMIpN7CoNBsHAmCfOeurc5pjww7GYb7ezObpk6tuTPFzC03H00RypB/CulzqnYc28EArhyVUQsevabDWKN++/HlD5xIkjsuVrq9XAWbvqMe24QjFuKPW4f0YGikFp29T3J06MYDr0mQZbBbebXKY6ke5mQ7yInftStL/zn/bPl7Wl9aDxpU20JnLzf6A0E1hmtFMDYBhUdZzF/BpXh9RsjgXvaN+vOhvB0+d2g+xPIhWZy0galVPeNLe/YBoowb7x2946aBC77uG0E3PzdvoYLv2+4I6/kocNnF0Dcw==; 5:cWbSMu6cf7jRUf3HLVSE3WVyN0IfaQJhI/AAeuOy5z9hXZqcvKtGX0cHpUhqvcKD4Um2aN3rhJ3St6XPT3ud43JkqunTZFB/fHe6KQ+ed2QQC5m6ZOP3IFiiEqGB5XoPy02RpxJ2GPGmXO2WEi5HOyHW74T2A2vcy+bXTieFIr0=; 7:YK3Rn0spS3l4hYZ6Q433MbJ+qsh2moET01eYdHKbPncxqcaGMcfFExm3xq3AMZFkU/v/iUHXzpe1d9srScOoLDImvKM5Z2Tzctc2Rsw7XYbZI5PGZI3RRNnJ3egV4Zw6jilVkJTx1xlEaP1bbbbqVg== x-ms-office365-filtering-correlation-id: 40fcc3af-beea-4efa-62ef-08d6428061e2 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(7021145)(8989299)(5600074)(711020)(4534185)(7022145)(4603075)(4627221)(201702281549075)(8990200)(7048125)(7024125)(7027125)(7023125)(2017052603328)(7153060)(7193020); SRVR:CY1PR07MB2730; x-ms-traffictypediagnostic: CY1PR07MB2730: authentication-results: spf=none (sender IP is ) smtp.mailfrom=lbloch@janustech.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3231382)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(148016)(149066)(150057)(6041310)(2016111802025)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(6043046)(201708071742011)(7699051)(76991095); SRVR:CY1PR07MB2730; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2730; x-forefront-prvs: 084674B2CF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(346002)(366004)(376002)(136003)(39830400003)(199004)(189003)(2501003)(25786009)(8936002)(6436002)(11346002)(2616005)(446003)(5660300001)(476003)(81166006)(81156014)(8676002)(6116002)(3846002)(97736004)(86362001)(53936002)(486006)(105586002)(508600001)(6486002)(2900100001)(4326008)(14454004)(106356001)(68736007)(305945005)(66066001)(107886003)(316002)(386003)(6506007)(54906003)(110136005)(36756003)(26005)(186003)(102836004)(99286004)(1076002)(7736002)(76176011)(52116002)(2906002)(71200400001)(71190400001)(256004)(6512007); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR07MB2730; H:CY1PR07MB2619.namprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: janustech.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: ZYm5gnNZ41+mKT44CVEXe1KC+qKClN9lrq4S8TMVXAjodBEq7HeNnyuNiI6d8RXjwqR8Li2n6I3oBWVNk6quVzsUV4J5gyBT0QU6cjwHj2zcxjLT2M35tPZpmRS4fGyFwdFhgwh/VxhDaVRlfcgEKZeepY/+7ueUDjea0Q4MO4//yEvj38rUh/j8C50l1NMF5F1qm9+sAKnZC+Fu9M5xSSLwDx0r/sP+zCykOuJjdgDCiCEHPTE3ylMPLhhHGut0Vb9M2ZO5XpkJx1WVPzM4FRzssoxKEpdPj4mVbiYAGv84aot8tcBpSni+J6ZAYjOznUlj3zevwi0Oge5n/mdsWAKgtQj++VGwwquJNwUV/rA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: janustech.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40fcc3af-beea-4efa-62ef-08d6428061e2 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Nov 2018 18:07:28.8258 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 34eb020e-3cf3-43a1-afeb-f5cf1310628e X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2730 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.72.123 Subject: [Qemu-devel] [PATCH v2 1/1] include: Add a comment to explain the origin of sizes' lookup table X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , "qemu-block@nongnu.org" , Markus Armbruster , Max Reitz , Leonid Bloch Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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