From patchwork Mon Sep 24 22:53:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 10613027 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 33FB2112B for ; Mon, 24 Sep 2018 23:15:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4268E2A083 for ; Mon, 24 Sep 2018 23:15:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 334812A086; Mon, 24 Sep 2018 23:15:41 +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 A5D092A083 for ; Mon, 24 Sep 2018 23:15:40 +0000 (UTC) Received: from localhost ([::1]:49198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4a4p-0000yO-OX for patchwork-qemu-devel@patchwork.kernel.org; Mon, 24 Sep 2018 19:15:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g4ZwP-0002Vi-0f for qemu-devel@nongnu.org; Mon, 24 Sep 2018 19:07:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g4ZkV-0003H1-9i for qemu-devel@nongnu.org; Mon, 24 Sep 2018 18:54:42 -0400 Received: from mail-by2nam01on0127.outbound.protection.outlook.com ([104.47.34.127]:58181 helo=NAM01-BY2-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 1g4ZkV-0003Gm-03; Mon, 24 Sep 2018 18:54:39 -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=o3YC+SZoUzylZ2bST/jk0A79zUSZnbasjkfdOlqMgbA=; b=DsrhtOyzg8qKyPnbGTIOjRQSrdIMYTaLOvzibrBaI4Gou9bwMZZ6N1awSXJ3rOQ9AiyN8fNNr1h4ryyJ33FuwmuOK0u3l0zICGDuXINxVYeFtZ/AdvCbpV96sviPb1RjcESSZ/NE8AzwlWqkMF3xQxIGELzvjSGW3qcZrtkRTOA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=lbloch@janustech.com; Received: from Jupiter.local (141.226.29.227) by CY1PR07MB2617.namprd07.prod.outlook.com (2a01:111:e400:c637::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1164.25; Mon, 24 Sep 2018 22:54:35 +0000 From: Leonid Bloch To: qemu-devel@nongnu.org Date: Tue, 25 Sep 2018 01:53:50 +0300 Message-Id: <20180924225357.24245-3-lbloch@janustech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180924225357.24245-1-lbloch@janustech.com> References: <20180924225357.24245-1-lbloch@janustech.com> MIME-Version: 1.0 X-Originating-IP: [141.226.29.227] X-ClientProxiedBy: LO2P265CA0063.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:60::27) To CY1PR07MB2617.namprd07.prod.outlook.com (2a01:111:e400:c637::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8807fb1c-d9f9-4bbf-e872-08d62270b3eb 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:CY1PR07MB2617; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2617; 3:szGY7gOP2UuKClWdahF2x66ii48o+oAKBXjY9SKTOZK4+ebx/uAcnuaWyjkl1509fb5WNvRoCaRdqGdEEmj7Aa4qE0k+MZujypJoktusLw6rNBHvJ74colNSWpBYIXpifICyt85Ns9VNVUN9euqkJeMzc2CjP41WAgk4uKo7Kg4fHd6IWQ0YELc1OEWU+teoBHXqpmn32eC4LfHhlZNs0Pevf9FvmHKApZh3K0QOGu0cMKU53xKRDmGFnROO1eyM; 25:45olA5QD45JnvD9N6hqlsEuUxxh0hoAVBc8weBHYheK9dAJOQmrPnWgBCJYEkDVa9bgK6psHzKJy4pdlvyfcdl8QA5PCDdq4FVC9vhluxiZ40wLQfxXqQ1WNkM5NqzexHVxFbBetyCbMU4U/njF39kA4cNBoCqPhBhC5Q55Ehl1NNYeki3Bxaq0VL5kyaaUGmIzHQ4JGmjAhUt2mC35kKRyKoPr11aNPbsB0ViZQXfAXwxOGZVoJKPXHakcklkGAgfb2xvyQEwJyWFhQpgVwlxnXT6oexIx2ngjImVSn3/XjTZo0fTz+Mdg+cuB4Rfqn3HzHIkZrxsqutwMc0pS+Tg==; 31:5+fWsN+ROYHKWucMQuJQUK/0VKeEV70m+Q6z7Hvf0Ln+z8VaQcS0JIUo2pHl01N/y9yW8YyY+oocTuEgp3UqxPsb7gNyE2SCUQ6Qs9GFW16/ux0LHnUAm9qPCf6lknxzlza7W/6kpWEWFyM1yZHz5+cRcb7SdJRbw9S9u0MwoviGy7YgI6M/RdoznnSiyctXtzSKVZSn3I6p1CeR6GItaw160sUP4sFsMOxHjpdNd5g= X-MS-TrafficTypeDiagnostic: CY1PR07MB2617: 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)(3231355)(944501410)(52105095)(93006095)(93001095)(3002001)(149066)(150027)(6041310)(2016111802025)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6043046)(201708071742011)(7699051); SRVR:CY1PR07MB2617; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2617; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2617; 4:j07de/ISOKuSS57bdldZd5OR+Pt2nRNQLc6PuecCAeX/dkkokeh0aHwAI6ZzA6Yx5LY8LedZVwMR/h9eaFDqsdUr7HC64Hr0Tvsa49LqoGSSJYYF71EyeiKCIOTu+EdXdzqLaypyQSUf0CqJNZdGhpDORKPg/hRV4ueWTXuuoZQKlXJ6pMNMJgxvbw+VZWpmVqXUmuzyTaJUR3GNtkAlRmp1tVa1mVBwYU3SIyO2MBR1I53wrV/ArOvCgRW9jPrjQyYSnspO10uSPhX1+16w4A== X-Forefront-PRVS: 0805EC9467 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(396003)(346002)(136003)(39830400003)(376002)(366004)(189003)(199004)(476003)(54906003)(68736007)(956004)(2616005)(16586007)(105586002)(86362001)(66066001)(6666003)(7736002)(486006)(47776003)(106356001)(51416003)(11346002)(76176011)(36756003)(446003)(6506007)(2361001)(316002)(52116002)(386003)(97736004)(186003)(5660300001)(8936002)(16526019)(1076002)(2351001)(81166006)(8676002)(81156014)(26005)(50226002)(6512007)(4326008)(6916009)(53936002)(3846002)(25786009)(107886003)(6486002)(6116002)(50466002)(305945005)(2906002)(508600001)(48376002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR07MB2617; H:Jupiter.local; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: janustech.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR07MB2617; 23:jaYJNBUmenzFv+aKpzv+xrlaeqSHnVRQqMBq+NxIm?= n2nrAeH0ekOzRRMu6J6E7ZfwgEmVp+iasEspDtKZsxtihCVS9uWOcdA9mBKHLnMscmhrVC56Jdbf4WLPHbObp89R8lBWy3WdS1Igo7w41Y0wM4iReULcPDrWHc70xslSw1QG+QjkLEJyf5T4sVzY0w9jSKwG6Vpw6710gEfEcidUOw3L6NKca15bjoAvAPObZzgb2xEMQP4xpeRwpfVioFf3bvCCKgGCqFd8yk9YgtkZdz447+X3yiE0yo7zbpPvtd5vdJCCy+ryC9DUYVabPBnzpLip7JIAoNxDIl5UIYqTYtOANWf14s404DAP645x7ORA6B02BWZCCzuH1XdoQE0eu1SC0k4cQqSKTfR5cEYM8WKk+XHAoxaZjaP1AY0aguGIvpK1VPlnsCByxE9hwye6hJfalBL9DIFGCKhMjLGxGdNJ90Bl2pnYtiDc01+MIuxSOlldbVHVxM+9siRjIPXyX7d5rKjFqOsrWLPPIRydSIZ6NTHo629yOZCdIC+tTNLya5bqEG29SGfoWHCFFt7EIAg8YQR4gVuEZ4ovZr0pmlpxaTz4qRoWSziGVYWeAentbzWeWeAKNvewhApcYYok1fvyKRCrIhjBJwNyzwscZr0s3acPNLxUd1jtfZ70OrSvyhrDHAwaS08YPxWVGCdJkD3yL5sj/avU/EhDgeZildbAHyq0kl6Cz+V0XRv9MmFmbLxQvmaklEEhRtTKnrlPEDoxOb3OPtd0kljVXNxCc8HhaNr+uXh8DnBp7Ss6Vib5njv4k2AALOM18+6beNJMPqO41jNzeb4rAafqAzTK7x7+0yh4zDK35CR/PMX2/TW2TVyNGdUqFjbzPK9SXM4801Yu5JZ+pWXLa2gECHrWeJ4RWg430iwvQTVcnFm8or+bpJOwzPmQFLgbA5Rg856s+g0P7e78dSfc7jtb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UxG8SIGGeLx5tdOQSS6tUGMSSfgMsi1V2hJOjtR03Klbt49qr4X21QPfHEWtj6Hlu7DmULxQzkul+eyk+WzqtD91imoQtwap2khmB3FSQyGGPbgUebOkIWMEpUn/DoQ==; 5:ud+wcMemQKTHm5n3ZclTT91ukYEiUm2L+2pjPQ18doYeXJwBdUUzhIkX9FrkyILMTyCkSqnpJ6dInSEHkrYbTpJU64A2p3Ysneg5xwBI4JmazHEBqflgOFcCMPws9KVKMEIc1Qt77FjRScZpk38acEfyW1MB/SZP5DBdVH52bOg=; 7:QgqkY82OcFCXJNIYLDMtHC5dNWlz/sZPzzoF0WcueqyL7gw9oMrPzi5Zhn/GVCxYmyqHjJgXEERczR/g1YItwObhUhoXCYKxiBNpUgzUtSCLmcKW+L7fZx4cYX4j7/aYIP5KqGKK6J7rMgRZ70KU39rdDXv1VuFTM4zW0JNLtX49FH/RQ4iv/m1fMNeRQa77qP6KrNTLDEHo00UjiybZOKa6zgDV/NYRPzzBeuQJmrYMAQ12PLkj606gg/oM9YsA SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: janustech.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2018 22:54:35.2227 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8807fb1c-d9f9-4bbf-e872-08d62270b3eb X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 34eb020e-3cf3-43a1-afeb-f5cf1310628e X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2617 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.34.127 Subject: [Qemu-devel] [PATCH v11 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