Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp715113rwb; Thu, 11 Aug 2022 08:44:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR6sa7qQjR0luDL3zpK2JmP8UD6F4tQ+eOPxglrqbr2+Z2Yf0mTeXFmMuLDGRwfxsqJjGbYD X-Received: by 2002:a05:6a00:2446:b0:528:5da9:cc7 with SMTP id d6-20020a056a00244600b005285da90cc7mr32685694pfj.51.1660232661097; Thu, 11 Aug 2022 08:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660232661; cv=none; d=google.com; s=arc-20160816; b=aY+6+Yq/fvar3iqlzVPNOFew8Rf8CG5M/lC2it39fpxXr3AD8l+9UMj5dVjfYWU253 4hR9UXo5sU2JXk0+G5snzZ1bjbz6Q/Ql77oZTB4qIAHYS9h6wDGiNwDf5CndjiIrQWA+ gxlrU28fhEZPwVTWM08jiOe0KH6RiRtA39PjBJi/zrYSI+ry0UYmQKG81PW09H9Ei1qr Xtd/zGUASO2wuDd+S4pAX2OlsGebAltfEzHN8Ub02ivCCRfQE2Pj5hZcBxweiIMTJ8FF 52joLYhsXoFDWssJTrACh5J+mTHxov/9Y077mL/fwBdYdJXTsyNbieR450SA5JB0J2rW jB4A== 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=GeFK2lgYVqxhWRQuhMQEmc/VC301WwhF62rP4d0xu88=; b=jWK8V0FdBlMZfTtsKrY5JFjbKLaoJKw4XNVGsqdZd+y4Ws8wIkET1+5noTAyDJGrWl G/RirpaoPd99BV5R4x77oKewhanoYkHqcL0Wj669ZqtwlL73xh+eX+HWOunU6aqBbJSI sSW7vDvwM0D98I8NI+fQlN0SMPxwru3q4/DO5il+wi6BcagODZ8ZeS2RHy3j/WknWc/l oW+NEI043N5yquh6rTYe2FUZ4gBonDiZ5imwyzCPzH/pFeassmhcrzcuMfwHIC6fht8b 25rqLFNdZpUvS6DMAGE9yp0Wb6s9bM5UP5vXlFEMnatAVZWdnZK36aWBobr+DD9a7BIH bq3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=dLaL7GWu; 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 a6-20020a170902ecc600b0016bcc2046f4si15045157plh.207.2022.08.11.08.43.58; Thu, 11 Aug 2022 08:44:21 -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=dLaL7GWu; 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 S235251AbiHKO7p (ORCPT + 99 others); Thu, 11 Aug 2022 10:59:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234066AbiHKO7o (ORCPT ); Thu, 11 Aug 2022 10:59:44 -0400 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5922A6F549 for ; Thu, 11 Aug 2022 07:59:43 -0700 (PDT) Received: from zn.tnic (p200300ea971b9854329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:971b:9854: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 E43F51EC064A; Thu, 11 Aug 2022 16:59:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1660229978; 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=GeFK2lgYVqxhWRQuhMQEmc/VC301WwhF62rP4d0xu88=; b=dLaL7GWuRmMHmcxfVxRhTvwSphjJdZG7TKtQK58CjRFYOl36RMjQHxj4vpia0fve4YMh4P PTrMVIuBgYHgyrZWD9Xsw/TzDkaijJ+9x9JuW4tQbTWfvU/RjHRmWvZZKdTSdOrjBJY+Yz MPcDNn0Iwh6W7fNwr04lh6xokt5FTcI= Date: Thu, 11 Aug 2022 16:59:33 +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: [RESEND PATCH v4 1/2] x86/asm/bitops: ffs: use __builtin_ffs to evaluate constant expressions Message-ID: References: <20220511160319.1045812-1-mailhol.vincent@wanadoo.fr> <20220723151521.51451-1-mailhol.vincent@wanadoo.fr> <20220723151521.51451-2-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220723151521.51451-2-mailhol.vincent@wanadoo.fr> 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 Sun, Jul 24, 2022 at 12:15:20AM +0900, Vincent Mailhol wrote: > For x86_64, the current ffs() implementation does not produce > optimized code when called with a constant expression. On the > contrary, the __builtin_ffs() function of both GCC and clang is able > to simplify the expression into a single instruction. > > * Example * > > Let's consider two dummy functions foo() and bar() as below: > > | #include > | #define CONST 0x01000000 Those code examples you can simply indent with two spaces. > In both examples, we clearly see the benefit of using __builtin_ffs() Who's "we"? Please use passive voice in your commit message: no "we" or "I", etc, and describe your changes in imperative mood. > instead of the kernel's asm implementation for constant expressions. > > However, for non constant expressions, the ffs() asm version of the > kernel remains better for x86_64 because, contrary to GCC, it doesn't > emit the CMOV assembly instruction, c.f. [1] (noticeably, clang is > able optimize out the CMOV call). > > This patch uses the __builtin_constant_p() to select between the Avoid having "This patch" or "This commit" in the commit message. It is tautologically useless. Also, do $ git grep 'This patch' Documentation/process for more details. > kernel's ffs() and the __builtin_ffs() depending on whether the > argument is constant or not. In general, you don't have to say what the patch does - that should be visible from the diff. The more important part is the *why*. And that you do. Rest looks ok. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette