Correctly detect riscv_vector.h using "-march=rv64gcv"

When detecting "riscv_vector.h" using autotools and cmake,
invoke the toolchain with -march=rv64gcv.
This commit is contained in:
Gurjant Kalsi 2023-08-17 01:12:25 +00:00
parent 3f70de0cb7
commit b9e0a83863
8 changed files with 23 additions and 7 deletions

View File

@ -113,7 +113,13 @@ check_include_file("inttypes.h" HAVE_INTTYPES_H)
check_include_file("stdint.h" HAVE_STDINT_H)
check_include_file("stdbool.h" HAVE_STDBOOL_H)
check_include_file("arm_neon.h" FLAC__HAS_NEONINTRIN)
check_include_file("riscv_vector.h" FLAC__HAS_RISCVINTRIN)
# Toolchains won't allow riscv_vector.h to be included unless the
# vector extensions are enabled.
set(SAVED_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "-march=rv64gcv")
check_include_file("riscv_vector.h" HAVE_RISCV_VECTOR_H)
set(CMAKE_REQUIRED_FLAGS "${SAVED_CMAKE_REQUIRED_FLAGS}")
if(NOT HAVE_STDINT_H OR NOT HAVE_STDBOOL_H)
message(SEND_ERROR "Header stdint.h and/or stdbool.h not found")

View File

@ -3,7 +3,7 @@ macro(CHECK_RV64VECTOR VARIABLE)
message(STATUS "Check whether RV64 Vector can be used")
configure_file(${PROJECT_SOURCE_DIR}/cmake/CheckRV64Vector.c.in ${PROJECT_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckRV64Vector.c @ONLY)
try_compile(HAVE_${VARIABLE} "${PROJECT_BINARY_DIR}"
"${PROJECT_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckRV64Vector.c")
"${PROJECT_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckRV64Vector.c" COMPILE_DEFINITIONS "-march=rv64gcv")
if(HAVE_${VARIABLE})
message(STATUS "Check whether RV64 Vector can be used - yes")
set(${VARIABLE} 1 CACHE INTERNAL "Result of CHECK_RV64VECTOR" FORCE)

View File

@ -121,6 +121,9 @@
/* Define to 1 if you have the <termios.h> header file. */
#cmakedefine HAVE_TERMIOS_H
/* Define to 1 if you have the <riscv_vector.h> header file. */
#cmakedefine HAVE_RISCV_VECTOR_H
/* Define to 1 if typeof works with your compiler. */
#cmakedefine HAVE_TYPEOF

View File

@ -53,7 +53,7 @@ AM_PROG_CC_C_O
AC_C_INLINE
AC_C_TYPEOF
AC_CHECK_HEADERS([stdint.h stdbool.h inttypes.h byteswap.h sys/auxv.h sys/param.h sys/ioctl.h termios.h x86intrin.h cpuid.h arm_neon.h riscv_vector.h])
AC_CHECK_HEADERS([stdint.h stdbool.h inttypes.h byteswap.h sys/auxv.h sys/param.h sys/ioctl.h termios.h x86intrin.h cpuid.h arm_neon.h])
if test "x$ac_cv_header_stdint_h" != xyes -o "x$ac_cv_header_stdbool_h" != xyes; then
AC_MSG_ERROR("Header stdint.h and/or stdbool.h not found")
@ -89,6 +89,8 @@ fi
AC_ARG_ENABLE(riscv-vector-optimizations, AS_HELP_STRING([--enable-riscv-vector-optimizations],[Enable RiscV Vector Optimization Routines]), riscv_vector_opt=yes, riscv_vector_opt=no)
AM_CONDITIONAL(FLAC__RISCV_VECTOR, test "x$riscv_vector_opt" = xyes)
if test "x$riscv_vector_opt" = xyes ; then
CFLAGS="-march=rv64gcv $CFLAGS"
AC_CHECK_HEADERS([riscv_vector.h])
AC_DEFINE(FLAC__RISCV_VECTOR)
AH_TEMPLATE(FLAC__RISCV_VECTOR, [define to enable use riscv vector extensions])
fi

View File

@ -33,6 +33,9 @@ else()
check_cpu_arch_riscv64(FLAC__CPU_RISCV64)
if(FLAC__CPU_RISCV64)
check_rv64vector(FLAC__HAS_RISCVINTRIN)
if (RISCV_VECTOR AND FLAC__HAS_RISCVINTRIN)
set_property(SOURCE lpc_intrin_riscv.c cpu.c APPEND_STRING PROPERTY COMPILE_FLAGS " -march=rv64gcv ")
endif()
endif()
endif()

View File

@ -57,7 +57,7 @@
#include <sys/auxv.h>
#endif
#if defined(FLAC__RISCV_VECTOR) && defined(FLAC__HAS_RISCVINTRIN)
#if defined(HAVE_RISCV_VECTOR_H) && defined(FLAC__RISCV_VECTOR) && defined(FLAC__HAS_RISCVINTRIN)
#include <riscv_vector.h>
#endif
@ -238,7 +238,7 @@ x86_cpu_info (FLAC__CPUInfo *info)
static void
rv64_cpu_info(FLAC__CPUInfo *info)
{
#if defined(FLAC__CPU_RISCV64) && defined(FLAC__HAS_RISCVINTRIN) && defined(FLAC__HAS_RISCVINTRIN) && !defined(FLAC__NO_ASM) && defined(HAVE_SYS_AUXV_H) && defined(FLAC__RISCV_VECTOR)
#if defined(FLAC__CPU_RISCV64) && defined(FLAC__HAS_RISCVINTRIN) && !defined(FLAC__NO_ASM) && defined(HAVE_SYS_AUXV_H) && defined(FLAC__RISCV_VECTOR) && defined(HAVE_RISCV_VECTOR_H)
#define ISA_V_HWCAP (1 << ('v' - 'a'))
// Check that the kernel and the hardware support RiscV Vector.
unsigned long hw_cap = getauxval(AT_HWCAP);

View File

@ -35,6 +35,7 @@
#ifndef FLAC__INTEGER_ONLY_LIBRARY
#ifndef FLAC__NO_ASM
#ifdef FLAC__RISCV_VECTOR
#ifdef HAVE_RISCV_VECTOR_H
#if defined FLAC__CPU_RISCV64 && FLAC__HAS_RISCVINTRIN
#include "private/lpc.h"
#include "FLAC/assert.h"
@ -627,6 +628,7 @@ void FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_riscv(const FLAC__i
}
#endif /* FLAC__CPU_ARM64 && FLAC__HAS_ARCH64INTRIN */
#endif /* HAVE_RISCV_VECTOR_H */
#endif /* FLAC__RISCV_VECTOR */
#endif /* FLAC__NO_ASM */
#endif /* FLAC__INTEGER_ONLY_LIBRARY */

View File

@ -959,7 +959,7 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide_intrin_neon;
#endif /* defined FLAC__CPU_ARM64 && FLAC__HAS_NEONINTRIN */
#if defined FLAC__CPU_RISCV64 && FLAC__HAS_RISCVINTRIN
#if defined FLAC__CPU_RISCV64 && defined FLAC__HAS_RISCVINTRIN && defined HAVE_RISCV_VECTOR_H
#ifdef FLAC__RISCV_VECTOR
if(encoder->private_->cpuinfo.rv64.has_vector) {
if(encoder->protected_->max_lpc_order <= encoder->private_->cpuinfo.rv64.vlenb) {
@ -968,7 +968,7 @@ static FLAC__StreamEncoderInitStatus init_stream_internal_(
encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_intrin_riscv;
}
#endif /* FLAC__RISCV_VECTOR */
#endif /* defined FLAC__CPU_RISCV64 && FLAC__HAS_RISCVINTRIN */
#endif /* defined FLAC__CPU_RISCV64 && FLAC__HAS_RISCVINTRIN && HAVE_RISCV_VECTOR_H */
if(encoder->private_->cpuinfo.use_asm) {
# ifdef FLAC__CPU_IA32