From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from zimbra.cs.ucla.edu (zimbra.cs.ucla.edu [131.179.128.68]) by sourceware.org (Postfix) with ESMTPS id 2AA43385740C for ; Wed, 5 May 2021 18:25:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2AA43385740C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eggert@cs.ucla.edu Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 6753F160098; Wed, 5 May 2021 11:25:14 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id mgpc5ADQaXgJ; Wed, 5 May 2021 11:25:13 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id B900D1600AD; Wed, 5 May 2021 11:25:13 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Uod3_yN0YhtV; Wed, 5 May 2021 11:25:13 -0700 (PDT) Received: from [192.168.1.9] (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 927E1160098; Wed, 5 May 2021 11:25:13 -0700 (PDT) To: Florian Weimer , Adhemerval Zanella via Libc-alpha Cc: crrodriguez@opensuse.org References: <20210329182520.323665-1-adhemerval.zanella@linaro.org> <87a6p9dr9n.fsf@oldenburg.str.redhat.com> From: Paul Eggert Organization: UCLA Computer Science Department Subject: Re: [PATCH 1/4] Remove architecture specific sched_cpucount optimizations Message-ID: <61040ff8-caac-a3d9-91cc-9b445c4e98fd@cs.ucla.edu> Date: Wed, 5 May 2021 11:25:13 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <87a6p9dr9n.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, 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 18:25:16 -0000 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=20 trick and call that function. As things stand it's not obvious what the=20 code is doing, regardless of which bit it's clearing. The function's=20 comment should explain why it's not using __builtin_popcount.