error: implicit declaration of function ‘_pdep_u64’; did you mean ‘_pdep_u3 ’? [-Werror=implicit-function-declaration]
3729 | const uint64_t packed_idx1 = _pdep_u64(*(const uint32_t *)qs, 0x00ff00ff00ff00ffULL) | _pdep_u64(qh[ib], 0x700070007000700ULL);
suggest ways to fix
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
This error occurs because _pdep_u64 is a 64-bit BMI2 instruction that's not available on 32-bit x86 systems. The _pdep_u64 function performs parallel bit deposit operations on 64-bit values, which requires 64-bit registers.
Here are several ways to fix this:
1. Use 32-bit equivalent operations
Replace the 64-bit PDEP operations with 32-bit versions if available:
Create a software implementation of PDEP for 32-bit systems:
c
#ifdef __i386__
static inline uint64_t pdep_u64_emulated(uint64_t src, uint64_t mask) {
uint64_t result = 0;
int k = 0;
for (int i = 0; i < 64; i++) {
if (mask & (1ULL << i)) {
if (src & (1ULL << k)) {
result |= (1ULL << i);
}
k++;
}
}
return result;
}
#define _pdep_u64 pdep_u64_emulated
#endif
3. Use conditional compilation to disable this code path
If this is part of an optimization that's not critical:
c
#ifdef __x86_64__
const uint64_t packed_idx1 = _pdep_u64(*(const uint32_t *)qs, 0x00ff00ff00ff00ffULL) | _pdep_u64(qh[ib], 0x700070007000700ULL);
#else
// Fallback implementation without PDEP
// Implement the bit manipulation manually
uint64_t packed_idx1 = 0;
// Manual bit manipulation code here
#endif
4. Check for BMI2 support at runtime
Use CPU feature detection:
c
#include <cpuid.h>
static int has_bmi2() {
unsigned int eax, ebx, ecx, edx;
if (__get_cpuid_max(0, NULL) >= 7) {
__cpuid_count(7, 0, eax, ebx, ecx, edx);
return (ebx & (1 << 8)) != 0; // BMI2 is bit 8 of EBX
}
return 0;
}
// Then use runtime dispatch
if (has_bmi2() && sizeof(void*) == 8) {
// Use _pdep_u64
} else {
// Use fallback
}
5. Modify build configuration
If you're building from source, you might need to adjust compiler flags:
bash
# Remove flags that assume 64-bit or BMI2 support
CFLAGS="-m32 -mno-bmi2"
# Or explicitly target i386
./configure --host=i386-linux-gnu
The best solution depends on your specific use case. If performance is critical and this is a hot path, option 1 (using 32-bit operations) might be best. If this is not performance-critical code, option 2 (software emulation) provides the simplest drop-in replacement.
User
build system is cmake
Assistant
For a CMake-based build system, here are several approaches to fix the _pdep_u64 issue on 32-bit systems:
1. Add architecture-specific compiler definitions in CMakeLists.txt
cmake
# Check if building for 32-bit
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
add_definitions(-D__i386__)
# Disable BMI2 instructions for 32-bit builds
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mno-bmi2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-bmi2")
endif()
# Or more specifically:
if(CMAKE_SYSTEM_PROCESSOR MATCHES "i[3-6]86")
add_definitions(-DNO_BMI2_SUPPORT)
endif()
2. Create a feature detection module
Create a file cmake/CheckBMI2.cmake:
cmake
include(CheckCSourceCompiles)
function(check_bmi2_support)
set(BMI2_TEST_SOURCE "
#include <immintrin.h>
int main() {
unsigned long long a = 0x1234567890ABCDEF;
unsigned long long mask = 0xFF00FF00FF00FF00;
unsigned long long result = _pdep_u64(a, mask);
return 0;
}
")
set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mbmi2")
check_c_source_compiles("${BMI2_TEST_SOURCE}" HAVE_BMI2)
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
if(HAVE_BMI2)
set(BMI2_SUPPORTED TRUE PARENT_SCOPE)
else()
set(BMI2_SUPPORTED FALSE PARENT_SCOPE)
endif()
endfunction()
Then in your main CMakeLists.txt:
cmake
include(cmake/CheckBMI2.cmake)
check_bmi2_support()
if(NOT BMI2_SUPPORTED OR CMAKE_SIZEOF_VOID_P EQUAL 4)
add_definitions(-DNO_BMI2_SUPPORT)
endif()
Looking at this code, the issue is that __BMI2__ is being defined on your 32-bit system, but _pdep_u64 isn't available. The code already has a fallback path for systems without BMI2 support.
Here are the best ways to fix this:
1. Simplest Fix: Force the non-BMI2 path
In your CMake configuration, explicitly undefine __BMI2__:
# Force 32-bit build
cmake -DCMAKE_C_FLAGS="-m32" -DCMAKE_CXX_FLAGS="-m32" ..
# Or use a toolchain file
cmake -DCMAKE_TOOLCHAIN_FILE=i386-toolchain.cmake ..
# Create a config header
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/config.h"
)
# Add the binary dir to include paths
include_directories(${CMAKE_CURRENT_BINARY_DIR})
#ifdef NO_PDEP_U64
#define _pdep_u64(src, mask) pdep_u64_fallback(src, mask)
static inline uint64_t pdep_u64_fallback(uint64_t src, uint64_t mask) {
// Simple implementation
uint64_t result = 0;
int j = 0;
for (int i = 0; i < 64; i++) {
if (mask & (1ULL << i)) {
if (src & (1ULL << j++)) {
result |= (1ULL << i);
}
}
}
return result;
}
#endif
The best approach depends on whether you're modifying the project's CMake files directly or just trying to build an existing project on your 32-bit system.
CFLAGS="-m32 -mno-bmi2" CXXFLAGS="-m32 -mno-bmi2" cmake ..
make
The issue is that your compiler is defining __BMI2__ even though the 64-bit BMI2 intrinsics aren't available on 32-bit systems. The code already has the right fallback logic - you just need to ensure the BMI2 path isn't taken on 32-bit builds.