Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5261149rwb; Tue, 6 Sep 2022 23:06:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR4kMdNnUAHOjUKipR/1WsFyBhmkkTeVnMKiBFUPjEUxhIWepRF3Ee+pd7vqsMLAbDias86r X-Received: by 2002:a17:903:2cb:b0:171:4f0d:beb6 with SMTP id s11-20020a17090302cb00b001714f0dbeb6mr2288584plk.53.1662530802563; Tue, 06 Sep 2022 23:06:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662530802; cv=none; d=google.com; s=arc-20160816; b=h1my9D1DTf+PfLxSEHhvaO25vG/jv4E0IBl3ArxeGuhpttDp6a+kw1BL6mOOZyzcj5 pSPOrD37TkmaRrXMd0/WXNtmnbK7Jj4ieOe938wg0vhrHohsCOWuu0hqDN6c9WOsbBg8 xoJLdIYnMrtuBPFU7xdMES/vgtVA97eDSQOGfuHrAg8V4MBnY2+jlF45QRQweCeUzKtG UgqAG7v14VBsJLKIXmVKl88+zySJi8BbYLcw/r/dqde09s+7q2LHMjx3XWApoCLUI2QZ SXizZrkbSVO216Cyx8HQNOXD4I408/9s84QWKdU3CvV8/0A0xU0MvW1OTcMag6rwD2FJ UDcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=vdL0JRw13DKnZIvgWCrjye4WeG1glTwaTkY0rU3yNtQ=; b=VdiytD5syUyHa1rXgL+pWygnKVs7oFR4PLkDs4Lqn4UYiRYvJTC1ngEnoIAeWNMb2D xiSrLqS+NUovTSZ6Pj9H4zul2X9JEW4/QTbFfVMWXb/wPLP3ZDMKX+gYYAgRv/QqX1jK lJ1LXCa0y2hiyqj4u9tQFsUpZb6zbjBGHdMZXeb0jLVFcLllAQtf4FzlT/O7IC74Z0oz 1oSu8ne8X/u97p8Yl0xLwVhyHj59+eya6YBzpe9csJfVoWZYgXKxoic7zxjrTnaUs7x9 MkuukZyzLWM7+M49XCLltPBhrxaskPjdVYid884lf0TV46oyJD8DFY8iX+XFsIJ8wQWX iVZQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id li18-20020a17090b48d200b002009090626asi4845311pjb.69.2022.09.06.23.06.30; Tue, 06 Sep 2022 23:06:42 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229736AbiIGFf7 (ORCPT + 99 others); Wed, 7 Sep 2022 01:35:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbiIGFf4 (ORCPT ); Wed, 7 Sep 2022 01:35:56 -0400 Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C9AC72FC1 for ; Tue, 6 Sep 2022 22:35:54 -0700 (PDT) Received: by mail-yb1-f169.google.com with SMTP id 130so14391230ybz.9 for ; Tue, 06 Sep 2022 22:35:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=vdL0JRw13DKnZIvgWCrjye4WeG1glTwaTkY0rU3yNtQ=; b=E7Amsg8JJMFe/At6cNPX5M3W6ULyiKUKC0LqZZbB6YPmWWHg9Zec0fPThMnkb+3llQ 4eG1BpSIrBWdA7OqvPKI7N7xE5mGR9ssMbQJaBXvd3Wc/gYXwHhFq8YsV4gDjKHEPvHG PE6UpHNoii0zPILyxH42fawmVQzaxKxZ6QhXgLY1fYmRrA2c+/tUdlOBgcfRCPsskx4q 9xveD9t2OCOv+03GTQHquQl9YjW74ulM6vdXO/Qkbm7npP6qn6/saDTpCC46nckXCfrm 7m4CApkHcxl3ale/ZUHEPgHun/rJmkJM3vVQhabi+72Fae4oVLoS3IHXaioxxpY4c/X2 5xfw== X-Gm-Message-State: ACgBeo393QQgITnjPuZOdE4pRJJMvSLDVD01s9OCN67RU53cnCf+l2Zl i1ZijCNpqLNjvjbne5Q9j+7vPagiP0lpLpyDBKo= X-Received: by 2002:a25:e6cf:0:b0:6a9:9c99:d8a3 with SMTP id d198-20020a25e6cf000000b006a99c99d8a3mr1492965ybh.500.1662528953184; Tue, 06 Sep 2022 22:35:53 -0700 (PDT) MIME-Version: 1.0 References: <20220812114438.1574-1-mailhol.vincent@wanadoo.fr> <20220812114438.1574-3-mailhol.vincent@wanadoo.fr> In-Reply-To: From: Vincent MAILHOL Date: Wed, 7 Sep 2022 14:35:41 +0900 Message-ID: Subject: Re: [PATCH v5 2/2] x86/asm/bitops: __ffs,ffz: use __builtin_ctzl to evaluate constant expressions To: Borislav Petkov 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 , Yury Norov Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Wed. 7 Sep 2022 at 13:06, Borislav Petkov wrote: > On Sat, Aug 27, 2022 at 06:32:05AM +0900, Vincent MAILHOL wrote: > > Agree that this is only the surface. But, my patch series is about > > constant folding, not about the text of *ffs(). Here, I just *move* > > the existing text, I did not modify anything. > > Can we agree that this is a separate topic? > > Sure we can. > > But then you can't start your commit message with: > > "__ffs(x) is equivalent to (unsigned long)__builtin_ctzl(x) and ffz(x) > is equivalent to (unsigned long)__builtin_ctzl(~x)." > > which will bring unenlightened readers like me into the very same mess. > > So at least mention that there's a difference between the kernel > implementation using hw insns which are well defined on some machines > and what the glibc API does. So that at least people are aware that > there's something dangerous to be cautious about. > > Ok? OK. I rephrased the beginning of the commit message as below: If x is not 0, __ffs(x) is equivalent to: (unsigned long)__builtin_ctzl(x) And if x is not ~0UL, ffz(x) is equivalent to: (unsigned long)__builtin_ctzl(~x) Because __builting_ctzl() returns an int, a cast to (unsigned long) is necessary to avoid potential warnings on implicit casts. Concerning the edge cases, __builtin_ctzl(0) is always undefined, whereas __ffs(0) and ffz(~0UL) may or may not be defined, depending on the processor. Regardless, for both functions, developers are asked to check against 0 or ~0UL so replacing __ffs() or ffz() by __builting_ctzl() is safe. Does this solve the issue? If yes, I will prepare the v8 right away. Yours sincerely, Vincent Mailhol