From nobody Thu Nov 6 12:14:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541210542745943.5614601450415; Fri, 2 Nov 2018 19:02:22 -0700 (PDT) Received: from localhost ([::1]:53937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIlGO-0004Q2-RU for importer@patchew.org; Fri, 02 Nov 2018 22:02:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIlF6-0003uY-7f for qemu-devel@nongnu.org; Fri, 02 Nov 2018 22:00:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gIlD8-0006Q5-H8 for qemu-devel@nongnu.org; Fri, 02 Nov 2018 21:58:56 -0400 Received: from mail-bl2nam02on0123.outbound.protection.outlook.com ([104.47.38.123]:13885 helo=NAM02-BL2-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 1gIlD8-0006KU-1e; Fri, 02 Nov 2018 21:58:50 -0400 Received: from CY1PR07MB2619.namprd07.prod.outlook.com (10.167.16.145) by CY1PR07MB2460.namprd07.prod.outlook.com (10.166.195.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.26; Sat, 3 Nov 2018 01:58:47 +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.024; Sat, 3 Nov 2018 01:58:47 +0000 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=rdnDPLYKdBOyVA6yOoOvqmA1l57mhJTPDOYnI4zSYbs=; b=FcUFiO+3cHv8D763CN8FuWTeSROuexqM15+2I3CALH10TpVC9LqmweWymZ8ZwrKDGndHpjiCTNy4uFHDpIcBGyv5S8aXfiqshvgpKeYqpym+9QiDlVA7RfCtVEzFbui/kKEFGHJ5FBJne4+o4sHjZGB75XSwotXvys6TuqtoXD8= From: Leonid Bloch To: "qemu-devel@nongnu.org" , =?iso-8859-1?Q?Philippe_Mathieu-Daud=E9?= Thread-Topic: [PATCH] include: Add a comment to explain the origin of sizes' lookup table Thread-Index: AQHUcxjBB5rHlQqMVUKKZScDlqwckw== Date: Sat, 3 Nov 2018 01:58:46 +0000 Message-ID: <20181103015821.30074-1-lbloch@janustech.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM5PR0601CA0030.eurprd06.prod.outlook.com (2603:10a6:203:68::16) To CY1PR07MB2619.namprd07.prod.outlook.com (2a01:111:e400:c637::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=lbloch@janustech.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [141.226.29.227] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CY1PR07MB2460; 6:NLKcTuKZXxUlCtCWuvfSktd98NF2uBQknf5ogXq4bWyN98PEIu4v3Ig1eVDxsIBKayz21b1WoaobqIEISTiXpcNV5bmtqyYmYkkuf5+Svvwat9QTWEpxXCREIyDnBql+unpzJWYPWplagiYiPqz3t9W7FJ00lq81NzN0cOOxGK4xXpCiMQcycv6eqiwT3dS32Zx7eUqWXAOxoYFbNB9sZF31lA2BpIZ/53sWmUulkmRuo5o7WfhTvn/DoO6cD850sO42bjMjoFwvDAL7hrQ2dn4c262l2HpABJG+JLhq7yMXCjx+Rqvyj5dWEjMa+94E9RMovf/Jr6QGHeCWhLQ/LikLhaeYSrJKedJ0BtFrorQZhHXCsLYJOB4U55DOEMc33D5zLBcdKJU0+czk9QlQqBggNuKCJSVXAPxdcRKGZkkXBzYc9/FsJ2AY6UYQleMbok8w7K6pVnTT69oLHBUquw==; 5:IcU7sZH3ztZZlOh2FzZ6EZXSTPX8g4ELNx0UDHl1u2+265InvXwzsEilQ+XxctcRUyHvku0YRJegrQsTymZEuXPKYYEwjEPMFj2Do7datl/YfnqveblfDRy62k+6FWiXoYU9luE8y09mNXcE1ZBr3ZqvyECq+aquu4vSUyDxad0=; 7:FyAkkDO5EF3VzTTul2iN/bVs89ktIJ9torJ8N+QEfIbT4WXper3Ujkpk78l9qVmAdQXctzOg0dTaI2MfYGK3FN3fYX6JehFWmg+WUBA2Jm8irw/yxH//4/A0aDLJ28Lx2u3wlP4W+iV/Jqnu68OSPA== x-ms-office365-filtering-correlation-id: fe4de107-1836-437f-573c-08d6412fe425 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:CY1PR07MB2460; x-ms-traffictypediagnostic: CY1PR07MB2460: 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)(10201501046)(3002001)(93006095)(93001095)(3231382)(944501410)(52105095)(148016)(149066)(150057)(6041310)(20161123564045)(20161123562045)(20161123558120)(2016111802025)(20161123560045)(6043046)(201708071742011)(7699051)(76991095); SRVR:CY1PR07MB2460; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2460; x-forefront-prvs: 08457955C4 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(366004)(346002)(136003)(39830400003)(396003)(189003)(199004)(486006)(3846002)(26005)(105586002)(86362001)(256004)(186003)(4326008)(25786009)(68736007)(476003)(2616005)(2501003)(106356001)(99286004)(1076002)(6116002)(107886003)(2900100001)(7736002)(52116002)(305945005)(53936002)(6512007)(508600001)(36756003)(8676002)(2906002)(97736004)(54906003)(110136005)(316002)(66066001)(1857600001)(6486002)(6506007)(386003)(6436002)(81166006)(8936002)(71190400001)(14454004)(5660300001)(81156014)(71200400001)(102836004); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR07MB2460; H:CY1PR07MB2619.namprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; received-spf: None (protection.outlook.com: janustech.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: +8u0Nf0z9ZTKZieOPacE4MtnB08QGWU9/SAEBcuGqr8ohZsyvwoPakf3O2vBUt3Mv/zytSUcUn1RcJON4HuTmDaQK6eajBUFAMUoNL59c7fRw/M8/1rkXfU5TbpJ32Mbb9jPRk5Hv++z39mkFN6Fu21o+4txll6d4tCPLchaJMjSqUUjXYxOTGg5rSPPDEbrDRKR4P/tELj2XtOdaPYk8z0RaCArYdzzgGrKRQFLBbbsvwWU36360+Kf4NJN321owAhlxBN6E3wio9dlw1ZWo6Jr7cNOF/MqqUKl3mc822pD+nAFiEYEaGJ+kug7A+OM6nLex62u3ESKoSbT4m9ptvkAbBxVIezVpOCQRjYAxd4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: janustech.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe4de107-1836-437f-573c-08d6412fe425 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Nov 2018 01:58:46.9549 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 34eb020e-3cf3-43a1-afeb-f5cf1310628e X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2460 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.38.123 Subject: [Qemu-devel] [PATCH] 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Eric Blake --- include/qemu/units.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/qemu/units.h b/include/qemu/units.h index 68a7758650..051c274ca2 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) =20 +/* + * 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 stringif= ied). + * It can also be used for generic shortcuts of power-of-two sizes. + * This table is generated using the AWK script below: + * + * BEGIN { + * suffix=3D"KMGTPE"; + * for(i=3D10; i<64; i++) { + * val=3D2**i; + * s=3Dsubstr(suffix, int(i/10), 1); + * n=3D2**(i%10); + * pad=3D21-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 --=20 2.17.1