public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Brian Inglis <Brian.Inglis@Shaw.ca>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH] Cygwin: Make gcc-specific code in <sys/cpuset.h> compiler-agnostic
Date: Fri, 7 Jul 2023 12:54:34 -0600	[thread overview]
Message-ID: <073cd700-c727-ee29-017e-df8d86a1db59@Shaw.ca> (raw)
In-Reply-To: <ZKfeaMftPy8HmXyy@calimero.vinschen.de>

On 2023-07-07 03:44, Corinna Vinschen wrote:
> Hi Mark,
> 
> On Jul  7 00:41, Mark Geisert wrote:
>> The current version of <sys/cpuset.h> cannot be compiled by Clang due to
>> the use of __builtin* functions.  Their presence here was a dubious
>> optimization anyway, so their usage has been converted to standard
>> library functions.  A popcnt (population count of 1 bits in a word)
>> function is provided here because there isn't one in the standard library
>> or elsewhere in the Cygwin DLL.
> 
> And clang really doesn't provide it?  That's unfortunate.
> 
> Do you really think it's not worth to use it if it's available?
> 
> You could workaround it like this:
> 
>> +/* Modern CPUs have popcnt* instructions but the need here is not worth
>> + * worrying about builtins or inline assembler for different compilers. */
>> +static inline int
>> +__maskpopcnt (__cpu_mask mask)
>> +{
> #if (__GNUC__ >= 4)
>       return __builtin_popcountl (mask);
> #else
>> +  int res = 0;
>> +  unsigned long ulmask = (unsigned long) mask;
>> +
>> +  while (ulmask != 0)
>> +    {
>> +      if (ulmask & 1)
>> +        ++res;
>> +      ulmask >>= 1;
>> +    }
>> +  return res;
> #endif
>> +}
>> +
> 
> But, if you think that's not worth it, I'll push your patch as is.

In the cygwin list clang iostream discussion, I pointed out the clang 
configuration using gcc default paths and skipping the provided equivalent clang 
libraries including package libclang8 for clang intrinsics and builtins in:

	/usr/lib/clang/8.0.1/include/

which appear very similar to those provided by gcc-core in:

	/usr/lib/gcc/x86_64-pc-cygwin/11/include/

e.g.

$ l /usr/lib/{gcc/x86_64-pc-cygwin/11,clang/8.0.1}/include/*popcnt*
/usr/lib/clang/8.0.1/include/avx512vpopcntdqintrin.h
/usr/lib/clang/8.0.1/include/avx512vpopcntdqvlintrin.h
/usr/lib/clang/8.0.1/include/popcntintrin.h
/usr/lib/gcc/x86_64-pc-cygwin/11/include/avx512vpopcntdqintrin.h
/usr/lib/gcc/x86_64-pc-cygwin/11/include/avx512vpopcntdqvlintrin.h
/usr/lib/gcc/x86_64-pc-cygwin/11/include/popcntintrin.h

and from comparing features, the gcc test will work just fine with the clang 
compiler builtins or the clang intrinsics:

$ grep 'popc\(ou\)\?nt' 
/usr/lib/{gcc/x86_64-pc-cygwin/11,clang/8.0.1}/include/popcnt*
/usr/lib/gcc/x86_64-pc-cygwin/11/include/popcntintrin.h:#pragma GCC target("popcnt")
/usr/lib/gcc/x86_64-pc-cygwin/11/include/popcntintrin.h:_mm_popcnt_u32 (unsigned 
int __X)
/usr/lib/gcc/x86_64-pc-cygwin/11/include/popcntintrin.h:  return 
__builtin_popcount (__X);
/usr/lib/gcc/x86_64-pc-cygwin/11/include/popcntintrin.h:_mm_popcnt_u64 (unsigned 
long long __X)
/usr/lib/gcc/x86_64-pc-cygwin/11/include/popcntintrin.h:  return 
__builtin_popcountll (__X);
/usr/lib/clang/8.0.1/include/popcntintrin.h:/*===---- popcntintrin.h - POPCNT 
intrinsics -------------------------------===
/usr/lib/clang/8.0.1/include/popcntintrin.h:#define __DEFAULT_FN_ATTRS 
__attribute__((__always_inline__, __nodebug__, __target__("popcnt")))
/usr/lib/clang/8.0.1/include/popcntintrin.h:_mm_popcnt_u32(unsigned int __A)
/usr/lib/clang/8.0.1/include/popcntintrin.h:  return __builtin_popcount(__A);
/usr/lib/clang/8.0.1/include/popcntintrin.h:_popcnt32(int __A)
/usr/lib/clang/8.0.1/include/popcntintrin.h:  return __builtin_popcount(__A);
/usr/lib/clang/8.0.1/include/popcntintrin.h:_mm_popcnt_u64(unsigned long long __A)
/usr/lib/clang/8.0.1/include/popcntintrin.h:  return __builtin_popcountll(__A);
/usr/lib/clang/8.0.1/include/popcntintrin.h:_popcnt64(long long __A)
/usr/lib/clang/8.0.1/include/popcntintrin.h:  return __builtin_popcountll(__A);

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer     but when there is no more to cut
                                 -- Antoine de Saint-Exupéry

  parent reply	other threads:[~2023-07-07 18:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07  7:41 Mark Geisert
2023-07-07  9:44 ` Corinna Vinschen
2023-07-07 10:13   ` Mark Geisert
2023-07-07 10:45     ` Corinna Vinschen
2023-07-07 15:46   ` Jon Turney
2023-07-07 15:49     ` Corinna Vinschen
2023-07-07 18:54   ` Brian Inglis [this message]
2023-07-08 19:22     ` Brian Inglis
2023-07-08 20:59       ` Mark Geisert
2023-07-08 21:53         ` Mark Geisert
2023-07-09  4:27           ` Brian Inglis
2023-07-09  7:58             ` Mark Geisert

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=073cd700-c727-ee29-017e-df8d86a1db59@Shaw.ca \
    --to=brian.inglis@shaw.ca \
    --cc=cygwin-patches@cygwin.com \
    /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).