Skip to content

Commit

Permalink
Fix regression caused by 2fa631e
Browse files Browse the repository at this point in the history
* POWER8/9 feature checks were enabled even if the toolchain didn't support AT_HWCAP2
* Add detection if we need to include <linux/auxvec.h>
  • Loading branch information
mtl1979 authored and Dead2 committed Jan 30, 2024
1 parent c2cd8d4 commit 598128f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ if(HAVE_SYS_SDT_H)
endif()
check_include_file(unistd.h HAVE_UNISTD_H)

#
# Check for Linux includes
#
check_include_file(linux/auxvec.h HAVE_LINUX_AUXVEC_H)
if(HAVE_LINUX_AUXVEC_H)
add_definitions(-DHAVE_LINUX_AUXVEC_H)
endif()

#
# Check to see if we have large file support
#
Expand Down Expand Up @@ -685,8 +693,13 @@ if(WITH_OPTIM)
if(WITH_POWER9)
check_power9_intrinsics()
endif()
if(HAVE_VMX OR HAVE_POWER8_INTRIN OR HAVE_POWER9_INTRIN)
if(POWER8_NEED_AUXVEC_H OR POWER9_NEED_AUXVEC_H)
add_definitions(-DPOWER_NEED_AUXVEC_H)
endif()
if(HAVE_POWER8_INTRIN OR HAVE_POWER9_INTRIN)
add_definitions(-DPOWER_FEATURES)
endif()
if(HAVE_VMX OR HAVE_POWER8_INTRIN OR HAVE_POWER9_INTRIN)
list(APPEND ZLIB_ARCH_HDRS ${ARCHDIR}/power_features.h)
list(APPEND ZLIB_ARCH_SRCS ${ARCHDIR}/power_features.c)
endif()
Expand Down
5 changes: 4 additions & 1 deletion arch/power/power_features.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/* power_features.c - POWER feature check
* Copyright (C) 2020 Matheus Castanho <[email protected]>, IBM
* Copyright (C) 2021-2022 Mika T. Lindqvist <[email protected]>
* Copyright (C) 2021-2024 Mika T. Lindqvist <[email protected]>
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#ifdef HAVE_SYS_AUXV_H
# include <sys/auxv.h>
#endif
#ifdef POWER_NEED_AUXVEC_H
# include <linux/auxvec.h>
#endif
#ifdef __FreeBSD__
# include <machine/cpu.h>
#endif
Expand Down
30 changes: 30 additions & 0 deletions cmake/detect-intrinsics.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,21 @@ macro(check_power8_intrinsics)
}"
HAVE_POWER8_INTRIN
)
if(NOT HAVE_POWER8_INTRIN AND HAVE_LINUX_AUXVEC_H)
check_c_source_compiles(
"#include <sys/auxv.h>
#include <linux/auxvec.h>
int main() {
return (getauxval(AT_HWCAP2) & PPC_FEATURE2_ARCH_2_07);
}"
HAVE_POWER8_INTRIN2
)
if(HAVE_POWER8_INTRIN2)
set(POWER8_NEED_AUXVEC_H 1)
set(HAVE_POWER8_INTRIN ${HAVE_POWER8_INTRIN2} CACHE INTERNAL "Have POWER8 intrinsics" FORCE)
unset(HAVE_POWER8_INTRIN2 CACHE)
endif()
endif()
set(CMAKE_REQUIRED_FLAGS)
endmacro()

Expand Down Expand Up @@ -413,6 +428,21 @@ macro(check_power9_intrinsics)
}"
HAVE_POWER9_INTRIN
)
if(NOT HAVE_POWER9_INTRIN AND HAVE_LINUX_AUXVEC_H)
check_c_source_compiles(
"#include <sys/auxv.h>
#include <linux/auxvec.h>
int main() {
return (getauxval(AT_HWCAP2) & PPC_FEATURE2_ARCH_3_00);
}"
HAVE_POWER9_INTRIN2
)
if(HAVE_POWER9_INTRIN2)
set(POWER9_NEED_AUXVEC_H 1)
set(HAVE_POWER9_INTRIN ${HAVE_POWER9_INTRIN2} CACHE INTERNAL "Have POWER9 intrinsics" FORCE)
unset(HAVE_POWER9_INTRIN2 CACHE)
endif()
endif()
set(CMAKE_REQUIRED_FLAGS)
endmacro()

Expand Down

0 comments on commit 598128f

Please sign in to comment.