From patchwork Wed Sep 26 16:04:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 10616101 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 28A62112B for ; Wed, 26 Sep 2018 16:09:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2151A2B356 for ; Wed, 26 Sep 2018 16:09:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F5782B3B6; Wed, 26 Sep 2018 16:09:05 +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=BAD_ENC_HEADER,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 6253D2B378 for ; Wed, 26 Sep 2018 16:09:04 +0000 (UTC) Received: from localhost ([::1]:59606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5CN5-0004cG-97 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 26 Sep 2018 12:09:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5CJi-0001qH-BA for qemu-devel@nongnu.org; Wed, 26 Sep 2018 12:05:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5CJg-0005f4-MS for qemu-devel@nongnu.org; Wed, 26 Sep 2018 12:05:33 -0400 Received: from mail-eopbgr730130.outbound.protection.outlook.com ([40.107.73.130]:13864 helo=NAM05-DM3-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 1g5CJg-0005XJ-7K; Wed, 26 Sep 2018 12:05:32 -0400 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=DzFpL8RwAlrmQBmdow+UgCMSkw2NGLz4zB48sozedxg=; b=QTvo/XmrNBL8qPacRwMfK5bSf3c22QBR4hyW0XDTsgTdNqNr42NKGv3D0xgI9fLoTrcXNjbO4TKe1JKc1haA/RaeebGaEUHbGZTjjc4QakDMw9XJh19I9bHpW/Uj9yjttRv5TuACx7qLMtZhj6KZL99aqSD8mAroLW6awBNm2o4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=lbloch@janustech.com; Received: from Jupiter.local (141.226.29.227) by CY1PR07MB2619.namprd07.prod.outlook.com (2a01:111:e400:c637::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1164.25; Wed, 26 Sep 2018 16:05:22 +0000 From: Leonid Bloch To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 19:04:40 +0300 Message-Id: <20180926160447.5149-3-lbloch@janustech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180926160447.5149-1-lbloch@janustech.com> References: <20180926160447.5149-1-lbloch@janustech.com> MIME-Version: 1.0 X-Originating-IP: [141.226.29.227] X-ClientProxiedBy: HE1PR02CA0116.eurprd02.prod.outlook.com (2603:10a6:7:29::45) To CY1PR07MB2619.namprd07.prod.outlook.com (2a01:111:e400:c637::17) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2fafd561-c313-4330-d1b2-08d623c9de41 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(7021125)(8989299)(4534165)(7022125)(4603075)(4627221)(201702281549075)(8990200)(7048125)(7024125)(7027125)(7023125)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:CY1PR07MB2619; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2619; 3:c1Tqu+Vni9BTzNy1P80Vctljvu2fM7YkBJXmXerVQvbdLxNi21WjgXS/FDr9WrCL+sVbL/3uFFrw9fEPQZv8ME7NRkmTRujNoRGHnqEyufEvS2zeHqxp2MtsiK246EclL2AVIaKQO/DrSLmxzLWs6SbZNeSk08o2x5TKwJnpXv7NqH0qmUlSknHcPwWuQzA1uYFWSCymeXI1SpRwbusFtE68MDpbPG6kaNy1LKMpOmxDN6OkFeqFJxr0s3U8+vpY; 25:5SqbrJw9tnJOeZJZYAXkDOTpIGheQxdb7vsbUGJuryfkTrURlzN4DFIf3rynJAfPPX2liTBHfeXZursKD2fFy60bdjPOhZ/PPo7RoXKJkdjNr9H0JYW8YnRb4xL9g6p4RZlyINmkRqsn27mdkTIL8d9a1VklJGhovIFGOVO2FxL3NYpZ6bUKh/WkUV3jQze0mYnSTTXeN1LL9guoCfbR31he62D/sJdvC622rDJ4TjyOt7G9eG5gd/tF+VMkNElll+xbO31RY8vH6UnDghYPZM0q72zmZOKEjHIpCX7K1Hn4EfRQdZUF7xfZHa5rIhhu8VCITnnofK3ar3vmEsjp0Q==; 31:0m6NJo3KBo+oItKza41Ie3RgqNo6AgGUDaT6am0xUmS5/L24thQahdi2QdqtknyrCdUz7ySRY6N+p3flVI5echo+8nKzPpfkxNAMoRBLNoPzq3mCWFDHFXuvLbTWcl99WdG2fl0JbO646hqh7pOLiFAc1gFMTDcKmQSPIpEkZstkZ1ZZEeXiLWZ2wRpEUeQCnDxbtWwrgMKhc35ZluXh2UrHKwY72t0HzX9a9q+W8go= X-MS-TrafficTypeDiagnostic: CY1PR07MB2619: 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)(5005006)(8121501046)(3231355)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(149066)(150057)(6041310)(20161123562045)(20161123564045)(20161123560045)(2016111802025)(20161123558120)(6043046)(201708071742011)(7699051); SRVR:CY1PR07MB2619; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2619; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2619; 4:Kf3QNRJPTtJMKUY8t4m4QUtIXPeFXPW3q0UzgjsnHGsY0Lt6dKAYetdxJQpy//7hGnESHLYrErIgrHSBlaHrI7CThcnxNlOoneJy1bRdbUJyFQbBlxcrsbZhHDGF47M8Brb+7+Z01VsssGZZSPuJcI+GPetA+YHqr/mhkUnOPcguZrFyof44Ob4S/knarxidOxTZIGaoOxbzNmR8H16xGRKCIqUGCqh0IeW3jEl1PoAdfyERTR/pFPYs6wvgou2lr5XP4eklTGlQp9eto2X+yg== X-Forefront-PRVS: 08076ABC99 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(366004)(136003)(396003)(39830400003)(376002)(346002)(199004)(189003)(106356001)(508600001)(66066001)(6512007)(47776003)(4326008)(48376002)(2616005)(107886003)(446003)(50466002)(956004)(11346002)(36756003)(486006)(6486002)(476003)(2351001)(105586002)(34290500001)(316002)(16586007)(54906003)(2361001)(3846002)(6116002)(6506007)(386003)(1076002)(51416003)(52116002)(76176011)(26005)(2906002)(305945005)(8936002)(81166006)(186003)(16526019)(7736002)(8676002)(81156014)(6916009)(5660300001)(6666003)(50226002)(97736004)(25786009)(86362001)(68736007)(53936002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR07MB2619; H:Jupiter.local; 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-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR07MB2619; 23:0dziKY01f1vR/EIb9IlnBWpr0enL2H0ahcdLG4PEK?= xungTVYGfcjnxo9H6MGJddTbwwUbHnPxDlUdkSUnONWg3K7fwsAM8av+57TZv9It63JtSTRxkgBeNjPxx9LdZ42oSsduVIJeDvDr7qN4rb2b65zyXkKW7nvxEBwMQeczai8kw/i+/iq7Rl8sSz177d9wITLsYud9H0wOan4iEDBtXuzvl1se3c3u7ZRz4f2qmGhH5uEKyPr3y7Kml8EBE2N+t4R13qvVwtFkTFHQ1ArY+6LS3pjKgzwzJ72N/MjHaThBHLM4Tk5dDNY23UHLPkdn6EzGMsoZrep3tFMvj74GsLgdL26Io4mtlEP0/GFHTi4qUAEfODJc3VOHzktxbi+QX3cA/t04G5ZDpd/tHcO/KDN3Xrvkkey1I4uiw8yILzIbgWTts2N52TpV38KKWOQHhYpH2iqJlX3/It7s2lnzbX7X9h/IN6G70VkiXUUwlfBHiXKSx8Dq9LJXzFQOL5ybFE86ljHeVND/kL5NkZsI0PENn9/4VGz23RExQjwstnH2udqrb14AUGFnEmGH69eVWBjYgX29QZ0atjj5ROuFVxbvAC8wBMIRz6eoY6+Cqfp1yoRsp6FBG40s+Qa+aD97/MYbM8Ih8QSh5K9fsZlKG0NyPeztIT2E16MGtNl4MH2jgEvs9JrcibKkPY0edTOdg5ftiacjHlAc4R2nvjd8q91KEB96VveLNfh+jZmWx5zR5ez5haaBucztX9iVAaXGAzK6O18B2JCz9hg/VYZepTnakpoD3Z7aMU5zhCQQ27WdjHGvcjHEjmFUpMaQTYZRm0DczUJzDNt1880dAUlBEMP19ukU0iPQKi9NKHs7t1AK7XXMB4CKekQiptOvH+90kNZ0O2GiyE6ecMBr6Ox7kY4ck5/1Iu+RnWd6mHY88BGXRmAveENcwDjEfr44w33KbsvvxcHZ5UqUpvn3FseWWY/tMfnFrDfTyVHQra3NqFvVHm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r3xfXgGzsk1ObWbbC/K6/wP4Tc82rHxahpKKFC62A+hcctl+Jx5hxQ7aLWkH47zW6Ps7ju+Bf12TzryB/euEzhyi0ENBwa7wnSSXB8rhY5QXOv6g41EE4RMNrIYe6GQ==; 5:G3gHiXmKN0BtbaT9s/1dzczF5pu53hn1Egxmyv2paaVVqSi5sYGZ0jtX3gI6ljVtRJa0iMkaI0jocfIog+pwpfO5VqOrdDoFSLl2knMFVGXWtB4U386/WbPnvZjYCGpG70xZY+0C9+94KbTGMvYgx0UXOnYAEwc/1cbibSlj5TI=; 7:kqELXxMmM2GgE8pQujPnE2YNmxUTRTenHDoUxlU8UFTG5Fs8fT/F2qw5t4Db5ndqmOv1lmCFJKhs4oewmMw5YnNBnNiGJBwnpDSqnZ6yT3C8kbqpnXOBxSyCKgXiZi5TMQeOkDk8RcmzoMpi8Ipw9Y1r36N7B6tJs+5+m66dkNozErm/Sew9xGXNJJsPjEncX4J27y1lu2xQYPK3Yl45Mvno1EnkuDRRtxCfe34Vc2qj07kPcoU+SqNY2avF+bxn SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: janustech.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2018 16:05:22.1429 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2fafd561-c313-4330-d1b2-08d623c9de41 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 34eb020e-3cf3-43a1-afeb-f5cf1310628e X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2619 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.73.130 Subject: [Qemu-devel] [PATCH v12 2/9] include: Add a lookup table of sizes 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, 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 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 Reviewed-by: Alberto Garcia Reviewed-by: Kevin Wolf --- include/qemu/units.h | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/include/qemu/units.h b/include/qemu/units.h index 692db3fbb2..68a7758650 100644 --- a/include/qemu/units.h +++ b/include/qemu/units.h @@ -17,4 +17,59 @@ #define PiB (INT64_C(1) << 50) #define EiB (INT64_C(1) << 60) +#define S_1KiB 1024 +#define S_2KiB 2048 +#define S_4KiB 4096 +#define S_8KiB 8192 +#define S_16KiB 16384 +#define S_32KiB 32768 +#define S_64KiB 65536 +#define S_128KiB 131072 +#define S_256KiB 262144 +#define S_512KiB 524288 +#define S_1MiB 1048576 +#define S_2MiB 2097152 +#define S_4MiB 4194304 +#define S_8MiB 8388608 +#define S_16MiB 16777216 +#define S_32MiB 33554432 +#define S_64MiB 67108864 +#define S_128MiB 134217728 +#define S_256MiB 268435456 +#define S_512MiB 536870912 +#define S_1GiB 1073741824 +#define S_2GiB 2147483648 +#define S_4GiB 4294967296 +#define S_8GiB 8589934592 +#define S_16GiB 17179869184 +#define S_32GiB 34359738368 +#define S_64GiB 68719476736 +#define S_128GiB 137438953472 +#define S_256GiB 274877906944 +#define S_512GiB 549755813888 +#define S_1TiB 1099511627776 +#define S_2TiB 2199023255552 +#define S_4TiB 4398046511104 +#define S_8TiB 8796093022208 +#define S_16TiB 17592186044416 +#define S_32TiB 35184372088832 +#define S_64TiB 70368744177664 +#define S_128TiB 140737488355328 +#define S_256TiB 281474976710656 +#define S_512TiB 562949953421312 +#define S_1PiB 1125899906842624 +#define S_2PiB 2251799813685248 +#define S_4PiB 4503599627370496 +#define S_8PiB 9007199254740992 +#define S_16PiB 18014398509481984 +#define S_32PiB 36028797018963968 +#define S_64PiB 72057594037927936 +#define S_128PiB 144115188075855872 +#define S_256PiB 288230376151711744 +#define S_512PiB 576460752303423488 +#define S_1EiB 1152921504606846976 +#define S_2EiB 2305843009213693952 +#define S_4EiB 4611686018427387904 +#define S_8EiB 9223372036854775808 + #endif