Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp382479iob; Wed, 11 May 2022 17:05:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4T2esS7AAYxDgFth+IXpI7H/lTuIs/i4xpmineI/Vqc0AcSC1jFQzR3esrftQFMaHsmX0 X-Received: by 2002:a17:90b:4f49:b0:1dc:1762:4e00 with SMTP id pj9-20020a17090b4f4900b001dc17624e00mr7735127pjb.87.1652313904260; Wed, 11 May 2022 17:05:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652313904; cv=none; d=google.com; s=arc-20160816; b=pi9zn/INd/TqhWdRQqC9zlrE48voskE4k/82R/pr/icajWG+x1X19bllKos9xhDVux UfWGOP1U9ZPnPIkoEitUp5yB4FslUlfdtFb+7tWRqiz8bniLTP/9S0Dei9KI33cJ9qi5 5yiguNuts3/uSG9xgUbCL896zc05fp2DAKBfLxTS+6lU7ltNxlTOXYo27Il4Lb/a9Om5 f20C3exWPzy//MVjqfUVHX6/waGNPa5eravIeHEM37vKl1aojxy8uEkSCrSPfKYB0U2s 4eJM7SC8QV1kI7YdRYN0VQyB1lY1419BqtJ6Kr4s02GVWOBa9447qTZidpTwYp+N6V+E lWdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=3NXHqcWjd5AIR1qA2zuQCC2qF/w88LXdc5kcoLV5XsY=; b=qdB8+ZMkHJ+dljXrJ3LHnVwvAymqxBaNwS0xLtKGchELSYBot9a64Y3i1xzkoWkmX9 gWknpeDHLE4/TbQnNcdh7RDAI1CUSNUjeVX5KCwQ7ywD7SsrYySaBT9ns9Vppm02oXsb jSPTQfF+5gH8QqyirIkKVAXRSxzKwALZzyhqkoDEUI69op3e1E8dJoPBScDqbxu6hwsC xhbF40h1Q+vCI1Z06NmDLXx7PUH/EnbLUi/lktvAwdC6U49tBP5hqsmtdhTS9p6QZys0 Ou9O9EQszzkCxz+6P97HrayqqOeIy/Evq5P7d438EOcZP+i5vi6dJ/iY1bCFbGDiRQwM P9Pg== 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 r15-20020a638f4f000000b003ab018efbe3si1432964pgn.433.2022.05.11.17.04.48; Wed, 11 May 2022 17:05:04 -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 S1349353AbiEKXbE convert rfc822-to-8bit (ORCPT + 99 others); Wed, 11 May 2022 19:31:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349375AbiEKXa5 (ORCPT ); Wed, 11 May 2022 19:30:57 -0400 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E378553B6C for ; Wed, 11 May 2022 16:30:56 -0700 (PDT) Received: by mail-yb1-f171.google.com with SMTP id r11so6794624ybg.6 for ; Wed, 11 May 2022 16:30:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=82LtQvcmXEI9bSU6aE32LRoQ75jfHNnbnp/OWfCob4A=; b=YDCV1QwPJPyOEXnVtu/CSOdG8Qn+mkuMlL/tLoRBGDzzFF57u9kKUblnWdJJ2uTQ6n 16j+0bBRNywmjzrUjVruzrHOAad7b9SzRcEV8ojtCTPO77c688ZtK3du3Q75oNvrQrL0 djRawYJnMHu1QJvUnxR+RGfpEs4tA8v8sSFH96v/FrpfvyuAoyB0wSJ4O3ClijxPqTsf oUBA939G63Z8gmJTfucU/TUPzhrP4UP6JMAqGauqI+aTvMJ/Vk085yLKLX7PevBR9wuO LXLBveZifbo3J+wyXkrHRbIEfFkABNnMMCFp2+yMNCP+3LVP1UOVHsaQTG2BtHgnnMbi 8Y9g== X-Gm-Message-State: AOAM531tbK9n5GLOriedmkAhe/7AR33utmyviuaMmBxZDXkWtwN7ANgz DQogKQJvuMtnW5iKP9RbBtHasdLY6p4IrKNDIW0= X-Received: by 2002:a5b:491:0:b0:64a:f42f:6973 with SMTP id n17-20020a5b0491000000b0064af42f6973mr12909923ybp.20.1652311856106; Wed, 11 May 2022 16:30:56 -0700 (PDT) MIME-Version: 1.0 References: <20220511160319.1045812-1-mailhol.vincent@wanadoo.fr> <20220511160319.1045812-2-mailhol.vincent@wanadoo.fr> <324f245e-15e2-a1f2-bc8a-46255a1a859f@wanadoo.fr> In-Reply-To: <324f245e-15e2-a1f2-bc8a-46255a1a859f@wanadoo.fr> From: Vincent MAILHOL Date: Thu, 12 May 2022 08:30:45 +0900 Message-ID: Subject: Re: [PATCH v2 1/2] x86/asm/bitops: ffs: use __builtin_ffs to evaluate constant expressions To: Christophe JAILLET Cc: Nick Desaulniers , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Nathan Chancellor , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, David Howells , Jan Beulich Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT 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 Thu. 12 May 2022 at 05:56, Christophe JAILLET wrote: > Le 11/05/2022 à 18:03, Vincent Mailhol a écrit : > > 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. > > > > [...] > > > > > ** Statistics ** > > > > On a allyesconfig, before applying this patch...: > > > > | $ objdump -d vmlinux.o | grep bsf | wc -l > > | 3607 > > > > ...and after: > > > > | $ objdump -d vmlinux.o | grep bsf | wc -l > > | 792 > > > > So, roughly 26.7% of the call to ffs() were using constant expression > > and were optimized out. > > > > > nitpicking: numbers look odd. And they are. Thanks for spotting the issue. > 3607 is the exact same number as in patch 2/2. (ok, could be) > 26.7% is surprising with these numbers. (I guess it is (total_before > - remaining) / total_before x 100 = (3607-792)/36.07 = 78.0%) The 3607 is incorrect (copy/paste issue, sorry). The correct figure is 1081. And: (1081-792)/1081 = 26.7% Will amend the comment and send v3 right away. > (but patch looks great to me :) Thanks! :) > CJ