From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 4E5323857C61 for ; Wed, 5 May 2021 19:52:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4E5323857C61 Received: by mail-pg1-x52b.google.com with SMTP id t22so2612813pgu.0 for ; Wed, 05 May 2021 12:52:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=RIm0LJQktgSza3Nh9LZtuwWT4YWrmMJFPvrcIGgJdqs=; b=npYNDOvuK6o9Ttd8byCj24z8S3A5NP3Y3T4UisRLuW9s87aUdsdlFdSnTDC9Pa8gtj 9i9yITITs9jqe4ozoD1vCNKN2bTvyG1UrU0AE69HCNwm5wKoIa04FpZ7+EEXs43uyxmP XPnajRRAXQUgsujjORSf1UFMDtbCJ3Ro6h/XQpbdH6NxQLLvzxbmX2VajCO3daC8bwyB 2rJP44QIoCqAm3IhiRGLjf3b1CG5TCy9y4+oue/TZa92JWPQ5Kuqor8rvT/qH1YqfyMX r/Ngwzkqc490EHxG2pxbyMtCPViGfwdYdiIFSy85dU7RgsBiFh2ePz0Ur7trvuxHlkMq xvGA== X-Gm-Message-State: AOAM533mhOvSeFmySyxjgKLe/TFuxEcYDuFkWGL7XExWXt0idO8JPYHE FqQc+xmJ8XC6GDLYeGWrElUwooGN14AviOs8vOg= X-Google-Smtp-Source: ABdhPJxnaQsIg+6v8tXGE9axP3KiJGs82A8A8+BPvsdr1My/mViuOybxwXvjjHsUYbPXk76xRcsPEaJXugYUvh2OPrw= X-Received: by 2002:a65:4c0c:: with SMTP id u12mr567276pgq.122.1620244370536; Wed, 05 May 2021 12:52:50 -0700 (PDT) MIME-Version: 1.0 References: <20210329182520.323665-1-adhemerval.zanella@linaro.org> <87a6p9dr9n.fsf@oldenburg.str.redhat.com> <61040ff8-caac-a3d9-91cc-9b445c4e98fd@cs.ucla.edu> In-Reply-To: <61040ff8-caac-a3d9-91cc-9b445c4e98fd@cs.ucla.edu> From: Noah Goldstein Date: Wed, 5 May 2021 12:52:39 -0700 Message-ID: Subject: Re: [PATCH 1/4] Remove architecture specific sched_cpucount optimizations To: Paul Eggert Cc: Florian Weimer , Adhemerval Zanella via Libc-alpha , crrodriguez@opensuse.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 May 2021 19:52:52 -0000 On Wed, May 5, 2021 at 12:32 PM Paul Eggert wrote: > > On 5/5/21 10:28 AM, Florian Weimer via Libc-alpha wrote: > >> diff --git a/posix/sched_cpucount.c b/posix/sched_cpucount.c > >> index b0ca4ea7bc..529286e777 100644 > >> --- a/posix/sched_cpucount.c > >> +++ b/posix/sched_cpucount.c > >> @@ -22,31 +22,11 @@ int > >> __sched_cpucount (size_t setsize, const cpu_set_t *setp) > >> { > >> int s =3D 0; > >> + for (int i =3D 0; i < setsize / sizeof (__cpu_mask); i++) > >> { > >> + __cpu_mask si =3D setp->__bits[i]; > >> + /* Clear the least significant bit set. */ > >> + for (; si !=3D 0; si &=3D si - 1, s++); > >> } > >> - > >> return s; > >> } > > Why =E2=80=9Csi=E2=80=9D? It think si &=3D si - 1 clears the*most* si= gnificant bit in > > si. If you agree, please update the comment. > > Better yet, define a static function 'popcount' that uses Kernighan's > trick and call that function. As things stand it's not obvious what the > code is doing, regardless of which bit it's clearing. The function's > comment should explain why it's not using __builtin_popcount. It looks to me like GCC is still having a bit of trouble with the new implementation. With skylake as a target it seems to be throwing in a cmovcc in the outer loop: https://godbolt.org/z/ocn1KWGPx