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 927D6C32789 for ; Tue, 23 Aug 2022 18:11:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233478AbiHWSLt (ORCPT ); Tue, 23 Aug 2022 14:11:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231338AbiHWSLZ (ORCPT ); Tue, 23 Aug 2022 14:11:25 -0400 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70FCA90815 for ; Tue, 23 Aug 2022 09:23:09 -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 7586E1EC068B; Tue, 23 Aug 2022 18:23:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1661271784; 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=2YdN7I7EJkAjB7pRvLwBmHF9rFEsbFHXYh/pr0t1L0M=; b=kKohZL3GTd4xwIo/TOImx2hDG3yPJrGf2P3IhJjAslpJz1hrhr8629stu026rh9U17pmvH LfsMlcMORzLuwANlJ4qt5A2fs51SzvyT+mRkb3g42O35OpY9xlwAo/pgXZaueeD5wWPT+w 2i/yadC/ub1nzjT80dmwNTMF0MZfdkU= Date: Tue, 23 Aug 2022 18:23:00 +0200 From: Borislav Petkov To: Vincent Mailhol Cc: Nick Desaulniers , 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: <20220812114438.1574-3-mailhol.vincent@wanadoo.fr> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 12, 2022 at 08:44:38PM +0900, Vincent Mailhol wrote: > __ffs(x) is equivalent to (unsigned long)__builtin_ctzl(x) Are you sure about this? My gcc documentation says: "Built-in Function: int __builtin_ctz (unsigned int x) Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined." Note the undefined part. Also, __builtin_ctzl(0): 0x40 ffs(0): 0x0 I'm using the kernel ffs() version in a small program which is basically a wrapper around BSF. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette