1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-12-16 16:35:45 +00:00

Use popcount64 from libc when available (#152)

* Use popcount64 from libc when available

Without this, we get a compiler error on NetBSD because the one in
libc has a slightly different prototype.

libcpuid_util.c:78:12: error: conflicting types for 'popcount64'
   78 | static int popcount64(uint64_t mask)
      |            ^~~~~~~~~~
In file included from /nix/store/155rj8nqh3xd80vpa8hl35p3hk7pacys-include-netbsd-8.0/include/string.h:98,
                 from libcpuid_util.c:30:
/nix/store/155rj8nqh3xd80vpa8hl35p3hk7pacys-include-netbsd-8.0/include/strings.h:61:14: note: previous declaration of 'popcount64' was here
   61 | unsigned int popcount64(__uint64_t) __constfunc;
      |              ^~~~~~~~~~

* Return unsigned int from popcount64

Matches NetBSD libc, where popcount64 originates.
This commit is contained in:
Alyssa Ross 2021-07-15 22:55:36 +00:00 committed by GitHub
parent ae7b063c8a
commit 1acaf9980b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -43,6 +43,8 @@ LT_INIT
AM_CPPFLAGS="$CPPFLAGS" AM_CPPFLAGS="$CPPFLAGS"
AC_CHECK_HEADERS([stdint.h]) AC_CHECK_HEADERS([stdint.h])
AC_CHECK_FUNCS([popcount64])
AC_CHECK_PROGS([DOXYGEN], [doxygen]) AC_CHECK_PROGS([DOXYGEN], [doxygen])
AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"]) AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])

View file

@ -29,6 +29,9 @@
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "libcpuid.h" #include "libcpuid.h"
#include "libcpuid_util.h" #include "libcpuid_util.h"
@ -74,9 +77,10 @@ void debugf(int verboselevel, const char* format, ...)
_warn_fun(buff); _warn_fun(buff);
} }
static int popcount64(uint64_t mask) #ifndef HAVE_POPCOUNT64
static unsigned int popcount64(uint64_t mask)
{ {
int num_set_bits = 0; unsigned int num_set_bits = 0;
while (mask) { while (mask) {
mask &= mask - 1; mask &= mask - 1;
@ -85,6 +89,7 @@ static int popcount64(uint64_t mask)
return num_set_bits; return num_set_bits;
} }
#endif
static int score(const struct match_entry_t* entry, const struct cpu_id_t* data, static int score(const struct match_entry_t* entry, const struct cpu_id_t* data,
int brand_code, uint64_t bits, int model_code) int brand_code, uint64_t bits, int model_code)