Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3906983rwa; Tue, 23 Aug 2022 12:15:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR4OC2r4nkxErbYJipZBHxkj1hotZOtHQrY9vORlFzJQ6Vt5mLzarlbojOpZa7B7ExRi/QIe X-Received: by 2002:a05:6402:3681:b0:446:ba68:573f with SMTP id ej1-20020a056402368100b00446ba68573fmr4915043edb.137.1661282146715; Tue, 23 Aug 2022 12:15:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661282146; cv=none; d=google.com; s=arc-20160816; b=lt6MyfWL8AR4aCql2rTxaxSRbgncjDigELw0UC94UTRkt6YSx1C6dqiSsmZYL3d2vd Y9Q3ZyCvWrEsoBeNrIL5culyjAzDhT0tEaKXnIOLzpNU4C35SsnDbbrJXsaCCJfvv+mo wiCwofKZ0FiYHt3Q517iEYJAVOsEaCnfTv/3aUERhSohzpY2F5D4Q4GO0yZzxtgp0wu4 i6VrJyc/9h6MMuLd7/POeLav850ZqoMqpOy7inXHtxcgL/tcg4qUDF4IutBsgJHlRLGy tjc4lWv3s98cUlzVQrE1qHJJPnraVIStpwX10PV+isg5lkJRj9UoT41T3MN5Otbv76SY 2x7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bJ92OKZPqF5z/8Ots4W3Sw8SoBp1QDbQQUg4ZfVRBcA=; b=M6PNcqDUYJNEvzrwjl51zcLKSjSaC9RT5yopodmRbXsQUc6IxDjUhMZhB20pXmUW5f xbkEHBcULaHrXSxnnXqL2RWBi6kx3lHaDTPh+udBPCoLWYF4ETSWWPZ9h59a8IxjMPLW wD/04K1GF2Bv6Ih+7ZnQuPRPijhA3r6I/33GgutJPBDDT6jHXrRG2553kugvRgVgZXky sCClL9rA9wMAOrOUY1mN72UQ/DsvKckfyGOyXthFKhdfjpLQNoigavFCCDsQu6+jS5in S/CeZqLPYYBx5tYZdHVTGbZp31jeweGSqNP+wJ6sfeX1vtSSqwyhpFlie75/tGBMGsI8 Is3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=pUDxgrvJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m17-20020a509311000000b00445ef5c7240si2342052eda.519.2022.08.23.12.15.20; Tue, 23 Aug 2022 12:15:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=pUDxgrvJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229594AbiHWTND (ORCPT + 99 others); Tue, 23 Aug 2022 15:13:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232411AbiHWTMp (ORCPT ); Tue, 23 Aug 2022 15:12:45 -0400 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35FCF89919 for ; Tue, 23 Aug 2022 10:50:20 -0700 (PDT) Received: from zn.tnic (p200300ea971b9893329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:971b:9893:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id BC37D1EC063A; Tue, 23 Aug 2022 19:44:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1661276643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=bJ92OKZPqF5z/8Ots4W3Sw8SoBp1QDbQQUg4ZfVRBcA=; b=pUDxgrvJQC51177dBRmleFtC88cWc5cNTsL9lbwZWh0/c5mnyiEb5EYiicetPTBfnhG2nz 5EZHbtPV+0NYttToIlXVzmdCUvA8PNkF72GDT7ij3jZJitwUmHHsZuSxbpVNL/RBRxJldz d8bcRxsjSBCCKg12oOaNY7DQHAVXspo= Date: Tue, 23 Aug 2022 19:43:59 +0200 From: Borislav Petkov To: Nick Desaulniers Cc: Vincent Mailhol , Thomas Gleixner , Ingo Molnar , x86@kernel.org, Peter Zijlstra , Dave Hansen , "H . Peter Anvin" , Nathan Chancellor , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, David Howells , Jan Beulich , Christophe Jaillet , Joe Perches , Josh Poimboeuf Subject: Re: [PATCH v5 2/2] x86/asm/bitops: __ffs,ffz: use __builtin_ctzl to evaluate constant expressions Message-ID: References: <20220511160319.1045812-1-mailhol.vincent@wanadoo.fr> <20220812114438.1574-1-mailhol.vincent@wanadoo.fr> <20220812114438.1574-3-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 23, 2022 at 10:12:17AM -0700, Nick Desaulniers wrote: > Callers of these need to guard against zero input, as the pre-existing > comment notes: > > >> Undefined if no bit exists, so code should check against 0 first. This is just silly. And then there's * ffs(value) returns 0 if value is 0 or the position of the first * set bit if value is nonzero. The first (least significant) bit * is at position 1. */ static __always_inline int ffs(int x) Can we unify the two and move the guard against 0 inside the function or, like ffs() does, have it return 0 if value is 0? -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette