From 0045a2bdc75c643002c1806cf73a53ec1c8eea06 Mon Sep 17 00:00:00 2001 From: "G.E." Date: Tue, 12 Mar 2024 14:22:39 +0200 Subject: [PATCH] moved HAVE_BUILTIN_POPCOUNT def to cmake --- README.md | 8 +++++++- cmake/cflags-generic.cmake | 5 +++++ src/util/arch.h | 1 - src/util/popcount.h | 8 ++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5dafd0ea..2ecc0961 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,8 @@ Assuming an existing HomeBrew installation: ### *BSD In NetBSD you will almost certainly need to have a newer compiler installed. +This will not replace the one in the standard base distribution, and +cmake will probably find the wrong compiler when it checks automatically. Using the example of gcc12 from pkgsrc, one will need to set two environment variables before starting: ``` @@ -123,7 +125,11 @@ export CXX="/usr/pkg/gcc12/bin/g++" ``` -In FreeBSD similarly, using gcc12 from pkg +In FreeBSD similarly, if you install another compiler, cmake might not +find the right one. Worse is if it finds, say, g++ and configures it for +C++ but leaves cc for C - FreeBSD's default cc is clang, and the binaries +generated between g++ and clang will not play nicely together. +Using the example of gcc12 from pkg: ``` export CC="/usr/local/bin/gcc" export CXX="/usr/local/bin/g++" diff --git a/cmake/cflags-generic.cmake b/cmake/cflags-generic.cmake index 93fa789d..35bbe9f4 100644 --- a/cmake/cflags-generic.cmake +++ b/cmake/cflags-generic.cmake @@ -31,6 +31,11 @@ if(FREEBSD OR NETBSD) set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -gdwarf-4") endif() +if(NETBSD) + set(EXTRA_C_FLAGS "${EXTRA_CXX_FLAGS} -DHAVE_BUILTIN_POPCOUNT") + set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -DHAVE_BUILTIN_POPCOUNT") +endif() + # these end up in the config file CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAS_C_HIDDEN) CHECK_CXX_COMPILER_FLAG(-fvisibility=hidden HAS_CXX_HIDDEN) diff --git a/src/util/arch.h b/src/util/arch.h index 9a9dde1b..1963b405 100644 --- a/src/util/arch.h +++ b/src/util/arch.h @@ -44,7 +44,6 @@ #endif #ifdef __NetBSD__ #include -#define HAVE_LOCAL_POPCOUNT #endif #endif // UTIL_ARCH_X86_H_ diff --git a/src/util/popcount.h b/src/util/popcount.h index a02e3bc5..34f386b7 100644 --- a/src/util/popcount.h +++ b/src/util/popcount.h @@ -37,7 +37,7 @@ #include "ue2common.h" #include "util/arch.h" -#ifndef HAVE_LOCAL_POPCOUNT +#ifndef HAVE_BUILTIN_POPCOUNT static really_inline u32 popcount32(u32 x) { return __builtin_popcount(x); @@ -52,7 +52,7 @@ u32 popcount32(u32 x) { // return (((x + (x >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; // #endif } -#endif /* HAVE_LOCAL_POPCOUNT */ +#endif /* HAVE_BUILTIN_POPCOUNT */ static really_inline u32 popcount32x4(u32 const *x) { @@ -63,7 +63,7 @@ u32 popcount32x4(u32 const *x) { return sum; } -#ifndef HAVE_LOCAL_POPCOUNT +#ifndef HAVE_BUILTIN_POPCOUNT static really_inline u32 popcount64(u64a x) { return __builtin_popcountll(x); @@ -84,7 +84,7 @@ u32 popcount64(u64a x) { // return popcount32(x >> 32) + popcount32(x); // #endif } -#endif /* HAVE_LOCAL_POPCOUNT */ +#endif /* HAVE_BUILTIN_POPCOUNT */ static really_inline u32 popcount64x4(u64a const *x) {