On 2023-07-07 12:54, Brian Inglis wrote:
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);

Missed the difference in spelling, but clang supports the same builtin functions __builtin_popcount{,l,ll} et. al. or provides *optimized* inline functions if not directly available as an instruction on the architecture.

#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

Reply via email to