From patchwork Wed Jul 26 10:34:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13327826 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC3BEC41513 for ; Wed, 26 Jul 2023 10:34:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.570290.892020 (Exim 4.92) (envelope-from ) id 1qObqs-0000sa-NW; Wed, 26 Jul 2023 10:34:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 570290.892020; Wed, 26 Jul 2023 10:34:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qObqs-0000sT-Kh; Wed, 26 Jul 2023 10:34:42 +0000 Received: by outflank-mailman (input) for mailman id 570290; Wed, 26 Jul 2023 10:34:41 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qObqr-0000pF-94 for xen-devel@lists.xenproject.org; Wed, 26 Jul 2023 10:34:41 +0000 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on20606.outbound.protection.outlook.com [2a01:111:f400:fe13::606]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0698903f-2ba0-11ee-b242-6b7b168915f2; Wed, 26 Jul 2023 12:34:40 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AS8PR04MB9175.eurprd04.prod.outlook.com (2603:10a6:20b:44a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Wed, 26 Jul 2023 10:34:39 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e%5]) with mapi id 15.20.6609.032; Wed, 26 Jul 2023 10:34:39 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0698903f-2ba0-11ee-b242-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kki6fVBK4bJS/poodZ3FhNqFU38J2KWcqpy5QhAKDaeYBkVtqlKLOkexGP2M4azXVey2Y9bTYYmO7/G2GdXQyWmsu5VA8vyAgrSNhwlI8AwTZrnGcwqd0uHnfoD36dZ52jEDAwH9fCa5cDFaDINEpUjeNVsqGnzmKFA/HTHluDr9Dh/bDRtvvvGuFx5OPkEdclOdy7m1Kc6uX1x0kU+W2uqF0QbAsBaLRqKZPoEFmR+Qb2XraEfvvZvdKCgp4D+E9dgLd/SiXCNDFr30SESDFUNtZrOUThvq5acRKOIbdFXxxrwUsCW4eeB9hYH5yVZkW4bevBTnqaNO32QDBsveIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4bXX4UWXnWt29w89tvGp0cf+LqZaRKTS56ciKBNCO2k=; b=b3P2K6SwCJdzJ1CDg60+v4aRD7vZ7uC3BReNRQD222Q8qeJFAhiFGS2oth9oZJFshJvSkFLsk4ijgzhl46LZpUa4KmR3A/wLzweFDFM0bGKI+fkjMmjT6HEAiOpVn519xYJwdTxUiO+uGqCwLIHthhG0Bsm73ZpxJGX+RC9Sop/xj/CU6xWoPlPTnVVAizYjNlm5EoyU/R+G94iaJ7uIFAs113R+B2hnzGIUF3txw5RUnuIqisPxjTF+SM95+6rPXlp3yGL40WA/Z/nZGTW4aNfURKRVnXPEj84GXI8EjuPyW+TuyT8QRFizi57zAXs/181fcomMjXsfJ79QZbIMqQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4bXX4UWXnWt29w89tvGp0cf+LqZaRKTS56ciKBNCO2k=; b=sEar2vZFCtLy4pccu4KzcUj9IsA3ZHTNPo2KD3JPuCwIP3iNB0+5c+SH9BBxPEKGDqO5znCwz7PnZ0fanYbrF7y5gkhCuPMtqWJpFy495sbseMu9mQzG0EEb5j/XJDS69iSHEPt27+cMRGJONn017mTTCopX9H4pny3g9x53+z7jW2GzNq1NUY1llM/fgg97Ueb9HDzWJcTTwD9wJvlUbguELzZpuNvJDp2Y/kK7udRn6JaqafG7+PDMtPKQiPH3kobh/Gdbl7TXvQG/UTkgzFYOFvnoJZmgGG+TBvE4fMxKnAY4S+5awYIIHBhuMPQ1dymbVvudvk+sSxTp4Tq0Bw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <4fdfecbc-0ed3-dc1c-379c-3a556fea8b89@suse.com> Date: Wed, 26 Jul 2023 12:34:37 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: [PATCH v3 4/5] x86: use POPCNT for hweight() when available Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= References: <10ce72fb-4fb7-67de-41ec-7291dbac0038@suse.com> In-Reply-To: <10ce72fb-4fb7-67de-41ec-7291dbac0038@suse.com> X-ClientProxiedBy: FR2P281CA0139.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9e::10) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AS8PR04MB9175:EE_ X-MS-Office365-Filtering-Correlation-Id: ef695472-c47a-4302-3aca-08db8dc3ea20 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pXLW/0KF4oJYbWL5xCtn/ARmSF8xBgOhebIURnVwOoKCRONcIQDuH3DLlQqFO5XFWdc0OKtlQAYqEoljrK5WcvcG4cBskCnzerq8eYXmr4VHQwLiuWuEaYe9YPCYJkxczQyoUBJmtV/INqgbw+fSbgQCgzv6baFfMiYGVowSWXjSdbMojCzoLqKsA0/ZS7dclQj6bha3dpJDXoLJXTktZrv57nW1gV4obHQmi2hQrFEO5wQocmE8XQAfQdEwTCRkqK6MaptMLf9FnfCsmWwLu3wy/sbkH1nbbkGJs4JDcC+GG256vx75xN7js6oj4N9MECHZTlfdrBOQUhZETHe1vs8vsQcQuBMcv9D8ShB+JtKAs9sMFm0HvZ4f9qFHQWl39XOZCedc2FSr1ktUzbL1vKIYLk/lzCnFbMWv60EDql9ZZde8kT/1ihooBfFnIQWfDDRLf3zhyDEW592wWbvxVRNjYLc08mOS4J1K8M720TPShgb9yT0DI6sefZ9qc0UsLi8gWab+yQbHMhN3d95SWuZS5X/zxXWVDQxOiuGBFdzfr12D7f6U/a5xwz5X9jr5yoehDHntZNOTJoAoXdXug0kDgIwn1Cs1cKSaX7RpUR/NDN/er+SwSXf4DF/Wc4vrklokYLAeOMK75sG0N/CmzWsxp+ahHWzJX/K22zrJBhu+t2cpkfO2ln5wKoCBgwCB X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(346002)(376002)(366004)(396003)(136003)(451199021)(54906003)(6512007)(6486002)(478600001)(66476007)(2616005)(26005)(186003)(6506007)(2906002)(4744005)(66556008)(6916009)(66946007)(316002)(4326008)(5660300002)(8936002)(8676002)(41300700001)(38100700002)(86362001)(31696002)(36756003)(31686004)(16393002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?l1Fr77a+MlfQOf+88UhIwY91qbg5?= =?utf-8?q?Ypk3FxX8t7dsxdEbtpErd8Xd5n7FmLYYDZ3kMOanch70CtwkUvtKrRGA/5N+lLeVx?= =?utf-8?q?qaRoGEiiI0P3TzsfZtC83zakz2AaMD6Dyo8TMdCB93e6+6lXVYhm1S80DPCmF9Xqo?= =?utf-8?q?D0nNdefIKegaCi7enagLFjdSfhBSZAAD/ouIj9vi4eUI2TrZB/Hgv0gdYqSZHJK+P?= =?utf-8?q?DJN9HX+JEjerVpLPcOVB+kn9wJ63YIr780AIwZ8JKZzO6273sKzjukg43NxVoYUPk?= =?utf-8?q?ggIXb7albfmwvkg8HqTjoFgyoysc40xk4lWSeHva9ow1KKVw/IwkljNJdwX5eOJ9h?= =?utf-8?q?Wo8IL0Sq6h4cOfX2j7oRt5ExbhmMTjc8/2B9JVjMct7p714dlOwTdBdefOF2PCn8E?= =?utf-8?q?s6uj97XQy70vlL/ZZnSIP6lwqfgwzrqMyGPzZZW3VsRuBVhnZt4aeDjU5H0M4iayp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+VSK6hJuoBqTTjXLONgLlA4c8gbWH/6yGaT4jtJCP4RUnMdxT9IIMBMKLWjSn3g?= =?utf-8?q?FaogiSdgXO97OL0qvULWg/M1Moe8FdigIeDlgoIz/hHCmQlQtaQ9bhQqDTiia/oFH?= =?utf-8?q?WN6X6Oqd2nznQ7t/KcM+aHp9lQrYoqa2H56t2u62TeBbu0kgZ7IOFOYfIYNJDYo26?= =?utf-8?q?K3A/j3vaxYvF?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ef695472-c47a-4302-3aca-08db8dc3ea20 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2023 10:34:39.0999 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lk65ibqpXKDPWL9c04qQzQapaxG+okr/vOFnnayq0JF7IknSqo+DmEZEiuxZa0dWgG1oP7y2hi6vaokGj8IyIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB9175 This is faster than using the software implementation, and the insn is available on all half-way recent hardware. Use the respective compiler builtins when available. Signed-off-by: Jan Beulich Reviewed-by: Jason Andryuk --- a/xen/arch/x86/include/asm/bitops.h +++ b/xen/arch/x86/include/asm/bitops.h @@ -475,9 +475,16 @@ static inline int fls(unsigned int x) * * The Hamming Weight of a number is the total number of bits set in it. */ +#ifdef __POPCNT__ +#define hweight64(x) __builtin_popcountll(x) +#define hweight32(x) __builtin_popcount(x) +#define hweight16(x) __builtin_popcount((uint16_t)(x)) +#define hweight8(x) __builtin_popcount((uint8_t)(x)) +#else #define hweight64(x) generic_hweight64(x) #define hweight32(x) generic_hweight32(x) #define hweight16(x) generic_hweight16(x) #define hweight8(x) generic_hweight8(x) +#endif #endif /* _X86_BITOPS_H */