From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by sourceware.org (Postfix) with ESMTPS id 630D63AAA0F9 for ; Thu, 6 May 2021 17:51:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 630D63AAA0F9 Received: by mail-qv1-xf33.google.com with SMTP id q5so3505674qvv.6 for ; Thu, 06 May 2021 10:51:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=MvfLUfWdrKVEyTukL+5FdHKEoydQuBFCrd00y5ZWR5Y=; b=g6neRJM08evH3ch5PVoyrgkjhXZhH0qXhuLR8jW137ceNyCHjOcDPTWMyPYx/QnlGB Xa/xkzi8cfPtb/Yq8IWA4x/7SVffwyS/9MK7bO/DCaofs0ftIGELn7C2+iF5JLlzmjV/ xXWaeSD433ot85bCeTOz6fk7DPlc0WlaT7CGhIXM3Je2/HOfkTOEk+PAzLJKgLK7cOJV U+wMYjDu+JYRF3YOS1qVpWykkWf53cIUEStBoPVqJuBUtGJbKUphnmzv4VZ8maiWojTW XMHUI03ca+6j+5kKSopy1GsAvJf7zEam+9BXFV/yOnOCOEEsu+y5h3cmLz2AVsIX7ZXd LkiQ== X-Gm-Message-State: AOAM533EM8TqkNsGYoPj46Q3HFCKRm2CDIm/IzeVriWgPcNVmJ72J3VB 36AMuxYxMMR0pONeGEozVOGozw== X-Google-Smtp-Source: ABdhPJxUtxkh70en8ALNgrqDni0ipHLoc2MmGRx3jHTU4FquRUcOOFskl4SbTV7jUM4M6PAFhHvAlA== X-Received: by 2002:a05:6214:14ab:: with SMTP id bo11mr5668838qvb.39.1620323467973; Thu, 06 May 2021 10:51:07 -0700 (PDT) Received: from [192.168.1.4] ([177.194.37.86]) by smtp.gmail.com with ESMTPSA id w196sm2458330qkb.90.2021.05.06.10.51.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 May 2021 10:51:07 -0700 (PDT) Subject: Re: [PATCH 1/4] Remove architecture specific sched_cpucount optimizations To: Paul Eggert , 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> <61040ff8-caac-a3d9-91cc-9b445c4e98fd@cs.ucla.edu> From: Adhemerval Zanella Message-ID: <7db89187-ae74-5986-a2f0-7bda3c202787@linaro.org> Date: Thu, 6 May 2021 14:51:05 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, NICE_REPLY_A, 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: Thu, 06 May 2021 17:51:10 -0000 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