From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AA59C32772 for ; Tue, 23 Aug 2022 19:13:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229795AbiHWTNE (ORCPT ); Tue, 23 Aug 2022 15:13:04 -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: 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