From patchwork Fri Sep 21 17:23:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 10610731 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 044DB157B for ; Fri, 21 Sep 2018 17:25:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBB9C2E35E for ; Fri, 21 Sep 2018 17:25:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFDC82E371; Fri, 21 Sep 2018 17:25:27 +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.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 314662E35E for ; Fri, 21 Sep 2018 17:25:26 +0000 (UTC) Received: from localhost ([::1]:56710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3PBG-0000hS-8U for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 13:25:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57496) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3P9j-0007p0-Of for qemu-devel@nongnu.org; Fri, 21 Sep 2018 13:23:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3P9g-000423-V9 for qemu-devel@nongnu.org; Fri, 21 Sep 2018 13:23:51 -0400 Received: from mail-eopbgr730114.outbound.protection.outlook.com ([40.107.73.114]:39168 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 1g3P9g-00040Z-MW; Fri, 21 Sep 2018 13:23:48 -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=4ITiwPXiA0wzJuGRlzkcYaBkfzpPyrSztH1TkFh7aDQ=; b=Gr60uvXMpuMLlQvNwb9bPnKyLVvJGx+V/+/FqFkY3HuF7JcjGIvbiXVPJRPBMs/NrN/p4Oqu++lMcexMEoZm6xW2hSAVtiGM0opHW3rB5cghP17MTYwy7fulwEH+KE+XSPALqNu+YnGJRCd1pqG1X24+//Sj8M8Wdzq0WDPerRk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=lbloch@janustech.com; Received: from Jupiter.local (141.226.29.227) by CY1PR07MB2618.namprd07.prod.outlook.com (2a01:111:e400:c637::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 17:23:44 +0000 From: Leonid Bloch To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 20:23:03 +0300 Message-Id: <20180921172310.10068-3-lbloch@janustech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921172310.10068-1-lbloch@janustech.com> References: <20180921172310.10068-1-lbloch@janustech.com> MIME-Version: 1.0 X-Originating-IP: [141.226.29.227] X-ClientProxiedBy: HE1PR08CA0065.eurprd08.prod.outlook.com (2603:10a6:7:2a::36) To CY1PR07MB2618.namprd07.prod.outlook.com (2a01:111:e400:c637::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a56902c9-e675-4014-7e9a-08d61fe6fd14 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:CY1PR07MB2618; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2618; 3:BSr3Ik+uEOdrMLFB4atPTHGPKYxooZFxAfylQqt/ehJIYHpvqa526SUGlALnpW1Hpz9U2lSYSibIeLZoJbjh3+79P/PJ9OVKnySzu3Uftng7f3yEHQiE/z9EXrTZe9CDvtAjXEQ1pFn6joLjiB76bp7uwi8wI/iYDIBuR1Ht9xp4VTB71WKoUhsfxUWTZ8Da0IAAgaj9mngXOBtsULTGKOfx8b+CxY6/lk7m3zSkdCpXBJju+/JWlWi+6spw3VY3; 25:JnWz4zSekxXowu1imD93d8LxE34HtI2D9iXKIpbECkapNHKZCN2Oc2NuY1g6vEJl8DgP9AzyLjfZpSqbgS1dpLxo+Rji9bDD7JPoAr782NLP0nwx6SjTop243NltQVwBy2auXfbY86UyApCqjaDMBexKjiQ2PeXmdAxqosgmDcJfwpd2HDDnQVvxaeyR+swXFvvSmS72dJv1O+sANQ7BnSnHnRGylFp3qjgUXxP+0nRg30cjzPeBK3JZT9tkZ+llaO8FWHu/LjiP7shW5y4myFENVgqoSNMOIerLO0QV5BzaxQJY4I5xOFjVA/be1VQi9qBtOUZOMCTMf7YMqYtG/Q==; 31:x5N0OEs39M8Z6x19QcRnlpCHbo9Tt7U6Y79KTlTQRK5WLuPfui1gTIbAUQpbiZLqt+luOl2qH+Qwzh9wV5XUF8xnR5eIfK57tDRnyOnDpXZYQE5nFZ+5rnc4ivmDOdGFKskU2iZFSEEYDLEPunQwajkLJBdrvY9NFeaW5Qp0M/4tHG1GbJvi7KUevBr5i+AwKvPtLpX4bI2OO5vASZYyCefL+Ca9qLTs0C8GOelxflM= X-MS-TrafficTypeDiagnostic: CY1PR07MB2618: 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)(10201501046)(93006095)(93001095)(3231355)(944501410)(52105095)(3002001)(149027)(150027)(6041310)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(2016111802025)(6043046)(201708071742011)(7699051); SRVR:CY1PR07MB2618; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2618; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2618; 4:ES4t0KkQMSjQprdug4zPpZkLGZiALle+irLYWByPCRnU/RmPbnrALhgcy0ZMiETFjaMdSvxsE8a9dRUmGSq+sb6b1XKE2ciLHM4a98dcu1vfjcsaVL/yed5w122zk+lCbylF86C53heFtxKzLtpAPOH2BPWwEi3JKzWVHsaNYzjwNaaj5fqECnlySrF9vodnBjaOG3xztwh+CHBEdzHWt2inJEZ9n7gaqz5uSbYSYkbL6/jlNpePuq7c17OC9ms8va+Ydn+XpUnP5W6MSfEiyw== X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(396003)(136003)(366004)(39830400003)(346002)(376002)(199004)(189003)(86362001)(68736007)(50226002)(106356001)(8936002)(1076002)(2906002)(6116002)(4326008)(53936002)(305945005)(8676002)(7736002)(5660300001)(81156014)(25786009)(3846002)(6486002)(36756003)(6666003)(107886003)(6512007)(11346002)(81166006)(97736004)(508600001)(47776003)(105586002)(2361001)(186003)(51416003)(48376002)(6916009)(50466002)(486006)(54906003)(476003)(956004)(66066001)(6506007)(2351001)(16526019)(2616005)(386003)(316002)(16586007)(76176011)(52116002)(446003)(26005); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR07MB2618; 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; CY1PR07MB2618; 23:xRExAYx61Yz38uO1LRC40RuBKUkUZZmAVJDM86YxH?= wStkM6YeN2EmuRuaxso6Kk9kyND4md6dnJ5qiOsG9GxJcFzU7GvjSVBklvmlN0SG78Rfe4md3zSejKrM3WACI5cJrDJF0ph/YepPs8NbrIVmAd53eLLwZLeOltts+QfoZnXQfEKPAB2/B1H80SM7opMvWbWdTrR/pl37pH61hCFXlGprGfgSAaTbKgtaKGfB+1zv8y+1Qe1jqkd4shWd8IN7MVqlHKOB5ZIrGfDDAr+SmUSXxI+oQ/Af3ieXXE+tkDngD4OvX3Wy9yCV2FzrNP9dOTy1MRKI1LnQHYd+E9SuEi7+TGSsb7y+guu7FHGMw4Rwju1hFKWEz7sK/aJul4oMVsWFYblpyHYvDiEJ6Wzd3BX2jmKXscAiKXHR1q4I7jSZmPZErUHTiM+cY+NERBfptyX6dWKW3CzjHUOoE8SKpleV0s4t8L8dIrA16eTGpDgL25K80Bx1/KZ+OAJr9WBSXA3c4/T2gMcriVaoINaf98ROtfNJFtkropP15/nNsfCaE1wlvoSk4lNWd73uEOdu60vHUvR89XjMrMyynUjPY+xo/Tax1Nt0qO77xPiz+bQsvJuaZUX0D4p+vSlq4dGjk5M9DSoX5nQDObbstPu80Uc8iKoNtiO4DrH7AqeObOygeU8E/Njfej1Jcg4CanatQqakD3osUxnyCYVIFviZMGX9UZ/hROXxMf7S0zTXwJWjdsf/UF/pcy6DcwZ/GgHnz8L+O4HFTL0fuiFsoUE6pAlsULtKPmXl+x1nhdXZqORShNpYfMxG+8ew6yGENz3g2eH//F5Nkhf2w+daGZBvseIhqoxmiNBxnUMqXvesfRisOor3XC5rGjVewUpy5GPc4w9fBkHblOYQMZDcEYDrwWRjqVdrVoapB1PdGgpmaEqMlDhrtCHGz3s9LQf9k+Sju+6I0EkejNEAH+HpF8vCwSXh0Xpb8nm3GRd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qYpQmw2pTwDNI8LWq3iNqTKI1p2h14EBAOjA4lrP14OmMtxFMc6O0H9uSbj/VDmCKU/zxHB3IkBwCPzKYsnhtHRSkJJevxgTjg==; 5:Ae/cOx8jMp82UDar+RoWsExwflBInxW/bLo8Q3IaGcINWRt37m6PcWUAZU7tDNERyigZACd/NcuTeeIJ3RLzleVidg8z69cbyoLSr5SL4253IwrFJ6FLeSka8mHzztE4JvrXC/ATcLhr4MRPwTg9sAmv49cJfYe11Vx4UvjfuvI=; 7:zxW7qfj+vBPsQtPfMrGggLg2cFglKeWmwfTIR452JhgXvxQqsxYCdJuV9mbwC9awtz9yzFOVcdK5hdkh8OQG+9+dnU56zOo0flTtvPhZtwEMg0yTpts+ExbafSEsgppYG7Qnj5v7ndcCJn8mT9S28ZXLr+W4CmKz+8+0fUdUZnSqhbLqaTIX/1PmemlEO6XfE7COdbIMrOfHCQQBjsZhRBUKj68Bu2J9ylNzA73maLU8bTI2bCcT1ZHIop5kkHjk SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: janustech.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 17:23:44.6077 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a56902c9-e675-4014-7e9a-08d61fe6fd14 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 34eb020e-3cf3-43a1-afeb-f5cf1310628e X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2618 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.73.114 Subject: [Qemu-devel] [PATCH v10 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 --- 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