From patchwork Wed Jan 2 11:09:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 10746285 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 98E5191E for ; Wed, 2 Jan 2019 11:10:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86CCB2837D for ; Wed, 2 Jan 2019 11:10:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B13E284F1; Wed, 2 Jan 2019 11:10:28 +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 B68B52837D for ; Wed, 2 Jan 2019 11:10:27 +0000 (UTC) Received: from localhost ([127.0.0.1]:43704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1geePr-0002Rf-0p for patchwork-qemu-devel@patchwork.kernel.org; Wed, 02 Jan 2019 06:10:27 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1geeOf-0001Mz-Gm for qemu-devel@nongnu.org; Wed, 02 Jan 2019 06:09:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1geeOc-0008CT-Bs for qemu-devel@nongnu.org; Wed, 02 Jan 2019 06:09:13 -0500 Received: from mail-eopbgr770100.outbound.protection.outlook.com ([40.107.77.100]:23523 helo=NAM02-SN1-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 1geeOc-0008Bt-4o; Wed, 02 Jan 2019 06:09:10 -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=blQuHKHwANEWo8q5ldcnivD3SLDtUq/aXj0s3+BXeOA=; b=EPugxl+JMjiE2Ch80DBdm29oxn1Ui6/IP60bAFmmaTfj3CDncA2rH8TqtrbUGPxb4HjngTWycg52CU4p6RU/uQMufVDLPfLI2E0oIusGft7KpAGBkZe7E3+kGHh30/64cuDTUSM/3VxQBhqFG8GBGOzy75pwO0VBd/KeZcjrJfk= Received: from CY1PR07MB2619.namprd07.prod.outlook.com (10.167.16.145) by CY1PR07MB2538.namprd07.prod.outlook.com (10.167.16.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1495.6; Wed, 2 Jan 2019 11:09:05 +0000 Received: from CY1PR07MB2619.namprd07.prod.outlook.com ([fe80::64b4:97dd:3f6f:c474]) by CY1PR07MB2619.namprd07.prod.outlook.com ([fe80::64b4:97dd:3f6f:c474%3]) with mapi id 15.20.1471.019; Wed, 2 Jan 2019 11:09:05 +0000 From: Leonid Bloch To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH 1/1] include: Auto-generate the sizes lookup table Thread-Index: AQHUoouTJJ8bZeiB5UW7JYVo4rg8GA== Date: Wed, 2 Jan 2019 11:09:05 +0000 Message-ID: <20190102110804.18155-2-lbloch@janustech.com> References: <20190102110804.18155-1-lbloch@janustech.com> In-Reply-To: <20190102110804.18155-1-lbloch@janustech.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0126.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9f::18) 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: [37.26.148.152] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CY1PR07MB2538; 6:kG4QT97Bw7UAa2vweWPaBFObGITcuS9DYlbv6KJjhcAXkS/4xYScwgP2usdDiq7q+CIVELNc+C/sS9f4t62oZzfl0aYTsvc+aKML7nZKUdrZEqI0dc3nSDGlsXnSXjMuTB9YZGk+y3Gl9mU+N8jf/ZYT3oDaxuu7bdPO8CmdW+VwA2kJgSUyH1IEcBEmVIQfQ+Cn/93n6mQSOW31gL9vWey4k2UwurV8dd+dapHyEJYvLLSMKAmLO/EhfYELuy2+1OTx59VosXf4U87MQiW8eXhKV/iiLosrexWnBBYFYhWo7QJh8m1xbsZxBrSNRsCEdmsaFzaN0UdZ9TZPP0H4UgEhQHmiuD2iDaqBHDfPN8/o4jVdsSEzCKrnPVprjopOjVh/u/sKzgXhMNk0mQ8rs5I6XqWikk1wlh9CodnLyXfeTg5euQwD212iPbXC2yWL8nNYVG3zIxX2d3eQMZo8pw==; 5:oRwjtw9fDOp08++7mmeHB+mUPgCtAjNbR/gmGpwdIIMuxUYX5xWEy9zLB/ki9LJMF3jHYEYrsu4AXvmTh2H4ohM2dOSXL0sogJ4a1rE8LhUXBxA62QJqL+QMVk5ju1IEEe7vVOuuCyLQtxvvWaorsEyk/A70cxVW5hFCqH3nncO7qEzzA0YCasGiB1m6Ar1QmzyHiuxMJsSZd18/fbRoNA==; 7:LdW++wpX1fBD8OtBWYA9AB3FVt6GfIO+H453UwK6FeFWxFIBKo3G7DC3qlMNKvlJ/5mLfD/EqD3S5fUOGm5ieFIDhTuYu5Zb+7JkVLHSHOGd3o+JV4qywECMS35GljG8KTD+L7s4Sqt0cTGKUzuN9g== x-ms-office365-filtering-correlation-id: 3d8fd520-97d5-4641-11f7-08d670a2b524 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(2017052603328)(7153060)(7193020); SRVR:CY1PR07MB2538; x-ms-traffictypediagnostic: CY1PR07MB2538: x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(3230021)(908002)(999002)(5005026)(6040522)(8220060)(2401047)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231475)(944501520)(52105112)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:CY1PR07MB2538; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2538; x-forefront-prvs: 0905A6B2C7 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(346002)(366004)(39830400003)(396003)(136003)(199004)(189003)(6116002)(3846002)(99286004)(14454004)(102836004)(97736004)(316002)(6436002)(2351001)(5640700003)(486006)(1076003)(6916009)(26005)(476003)(6486002)(25786009)(478600001)(6506007)(446003)(54906003)(5660300001)(11346002)(68736007)(386003)(2616005)(52116002)(186003)(53936002)(71190400001)(575784001)(8936002)(71200400001)(256004)(6512007)(76176011)(36756003)(106356001)(66066001)(305945005)(105586002)(7736002)(2501003)(4326008)(8676002)(81156014)(81166006)(86362001)(2906002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR07MB2538; H:CY1PR07MB2619.namprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:3; received-spf: None (protection.outlook.com: janustech.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 4RSZykeOPINSR2YldGcLehH4jqArHJPBXwjKFUwLucvU2iXtEH3Tpx2o+fDmqCMVNJu3Z490toGvWUT1RtNv7j3F1goZaiAFrCAgzOTd0S7TZqMEWuqIdH171hPXn+WAbPcyi607QpbmjdiJ+oCwxMWivnS4yDvM0hb6KcYfafQIJC92OobywFDMgTmw7LdN3fMNXhw7djs+Pvzdmt7BzPwR52tojG5SFyIzXZZkNEyTLw5DnmcxhU9jMf9K2lQafAiFBy253/PO9kUopgC9c93ounvkOTdvZ42PXduIGalrLvO7uv1SFZSTMBuAGN2y spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: janustech.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3d8fd520-97d5-4641-11f7-08d670a2b524 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Jan 2019 11:09:05.6766 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 34eb020e-3cf3-43a1-afeb-f5cf1310628e X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2538 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.77.100 Subject: [Qemu-devel] [PATCH 1/1] include: Auto-generate the 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" , Stefan Weil , Markus Armbruster , Max Reitz , Leonid Bloch , =?iso-8859-1?q?Philippe_Mathieu-Daud=E9?= 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 is now auto-generated during the build, and not hard-coded into the units.h file. Signed-off-by: Leonid Bloch --- .gitignore | 1 + Makefile | 5 +++ block/qcow2.h | 2 +- block/vdi.c | 1 + include/qemu/units.h | 73 -------------------------------------------- scripts/gen-sizes.sh | 66 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 74 deletions(-) create mode 100755 scripts/gen-sizes.sh diff --git a/.gitignore b/.gitignore index 0430257313..5945220303 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ /qemu-version.h /qemu-version.h.tmp /module_block.h +/include/qemu/sizes.h /scsi/qemu-pr-helper /vhost-user-scsi /vhost-user-blk diff --git a/Makefile b/Makefile index dd53965f77..435d92821b 100644 --- a/Makefile +++ b/Makefile @@ -122,6 +122,8 @@ endif GENERATED_FILES += module_block.h +GENERATED_FILES += $(SRC_PATH)/include/qemu/sizes.h + TRACE_HEADERS = trace-root.h $(trace-events-subdirs:%=%/trace.h) TRACE_SOURCES = trace-root.c $(trace-events-subdirs:%=%/trace.c) TRACE_DTRACE = @@ -499,6 +501,9 @@ ifdef CONFIG_MPATH scsi/qemu-pr-helper$(EXESUF): LIBS += -ludev -lmultipath -lmpathpersist endif +$(SRC_PATH)/include/qemu/sizes.h: $(SRC_PATH)/scripts/gen-sizes.sh + $(call quiet-command,sh $(SRC_PATH)/scripts/gen-sizes.sh $@,"GEN","$@") + qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$@") diff --git a/block/qcow2.h b/block/qcow2.h index a98d24500b..41d14baa17 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -27,7 +27,7 @@ #include "crypto/block.h" #include "qemu/coroutine.h" -#include "qemu/units.h" +#include "qemu/sizes.h" //#define DEBUG_ALLOC //#define DEBUG_ALLOC2 diff --git a/block/vdi.c b/block/vdi.c index 2380daa583..62dafe0cc6 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -51,6 +51,7 @@ #include "qemu/osdep.h" #include "qemu/units.h" +#include "qemu/sizes.h" #include "qapi/error.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qapi-visit-block-core.h" diff --git a/include/qemu/units.h b/include/qemu/units.h index 1c959d182e..692db3fbb2 100644 --- a/include/qemu/units.h +++ b/include/qemu/units.h @@ -17,77 +17,4 @@ #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 -#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 diff --git a/scripts/gen-sizes.sh b/scripts/gen-sizes.sh new file mode 100755 index 0000000000..e388164c32 --- /dev/null +++ b/scripts/gen-sizes.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +size_suffix() { + case ${1} in + 1) + printf "KiB" + ;; + 2) + printf "MiB" + ;; + 3) + printf "GiB" + ;; + 4) + printf "TiB" + ;; + 5) + printf "PiB" + ;; + 6) + printf "EiB" + ;; + esac +} + +print_sizes() { + local p=10 + while [ ${p} -lt 64 ] + do + local pad=' ' + local n=$((p % 10)) + n=$((1 << n)) + [ $((n / 100)) -eq 0 ] && pad=' ' + [ $((n / 10)) -eq 0 ] && pad=' ' + local suff=$((p / 10)) + printf "#define S_%u%s%s%20u\n" ${n} "$(size_suffix ${suff})" \ + "${pad}" $((1 << p)) + p=$((p + 1)) + done +} + +print_header() { + cat < + */ + +#ifndef QEMU_SIZES_H +#define QEMU_SIZES_H + +EOF +} + +print_footer() { + printf "\n#endif\n" +} + +print_header > "${1}" +print_sizes >> "${1}" +print_footer >> "${1}"