public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Paul Eggert <eggert@cs.ucla.edu>,
	Florian Weimer <fweimer@redhat.com>,
	Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Cc: crrodriguez@opensuse.org
Subject: Re: [PATCH 1/4] Remove architecture specific sched_cpucount optimizations
Date: Thu, 6 May 2021 14:51:05 -0300	[thread overview]
Message-ID: <7db89187-ae74-5986-a2f0-7bda3c202787@linaro.org> (raw)
In-Reply-To: <f86128b4-14ea-3078-8c32-7a037193efe8@cs.ucla.edu>



On 06/05/2021 14:12, Paul Eggert wrote:
> On 5/6/21 6:33 AM, Adhemerval Zanella wrote:
>> +/* Counting bits set, Brian Kernighan's way  */
>> +static inline unsigned int
>> +countbits (__cpu_mask v)
>> +{
>> +  unsigned int s = 0;
>> +  for (; v != 0; s++)
>> +    v &= v - 1;
>> +  return s;
>> +}
> 
> Looks OK, except please use 'int' rather than 'unsigned int' (twice) as we should prefer signed to unsigned where either will do and the caller wants plain int anyway.

The unsigned int is more to avoid the cmovcc on x86_64
https://godbolt.org/z/4MrMq1zKb.  But I do prefer int
in this case as well.

> 
> More important, please add a comment saying why we're not using the GCC builtin (summarizing Florian's and your followup remarks) since it is a little odd to see code that simply replicates a compiler builtin (what's next, we'll forgo multiplication in favor of repeated addition? :-).

This popcount is trick, even gcc is not really sure what do do
on every architecture [1].

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92135

      reply	other threads:[~2021-05-06 17:51 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-29 18:25 Adhemerval Zanella
2021-03-29 18:25 ` [PATCH 2/4] linux: Use sched_getaffinity for __get_nprocs (BZ #27645) Adhemerval Zanella
2021-04-27 15:38   ` Florian Weimer
2021-03-29 18:25 ` [PATCH 3/4] linux: Use /sys/devices/system/cpu/possible on __get_nprocs_conf Adhemerval Zanella
2021-05-05 16:53   ` Adhemerval Zanella
2021-05-05 17:54   ` Florian Weimer
2021-05-05 18:06     ` Florian Weimer
2021-05-06 13:03       ` Adhemerval Zanella
2021-05-06 13:51         ` Florian Weimer
2021-05-06 20:07           ` Adhemerval Zanella
2021-05-07 11:07             ` Florian Weimer
2021-05-07 12:43               ` Adhemerval Zanella
2021-05-06 13:17     ` Adhemerval Zanella
2021-03-29 18:25 ` [PATCH 4/4] linux: Remove /proc/cpuinfo fallback on alpha and sparc Adhemerval Zanella
2021-05-05 16:53   ` Adhemerval Zanella
2021-05-05 16:52 ` [PATCH 1/4] Remove architecture specific sched_cpucount optimizations Adhemerval Zanella
2021-05-05 17:28 ` Florian Weimer
2021-05-05 18:25   ` Paul Eggert
2021-05-05 19:52     ` Noah Goldstein
2021-05-06 12:22       ` Adhemerval Zanella
2021-05-06 18:34         ` Noah Goldstein
2021-05-06 13:33     ` Adhemerval Zanella
2021-05-06 13:43       ` Florian Weimer
2021-05-06 16:16         ` Adhemerval Zanella
2021-05-06 16:42           ` Florian Weimer
2021-05-06 16:54             ` Adhemerval Zanella
2021-05-06 17:12       ` Paul Eggert
2021-05-06 17:51         ` Adhemerval Zanella [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7db89187-ae74-5986-a2f0-7bda3c202787@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=crrodriguez@opensuse.org \
    --cc=eggert@cs.ucla.edu \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).