riscv: Fix the run-time checking of the RVV availability

Signed-off-by: Cosmin Truta <ctruta@gmail.com>
This commit is contained in:
Filip Wasil 2025-05-08 15:39:32 +02:00 committed by Cosmin Truta
parent 2b0eb78656
commit 7108843467
4 changed files with 17 additions and 13 deletions

View File

@ -323,7 +323,7 @@ if(PNG_HARDWARE_OPTIMIZATIONS)
list(FIND PNG_RISCV_RVV_POSSIBLE_VALUES ${PNG_RISCV_RVV} index) list(FIND PNG_RISCV_RVV_POSSIBLE_VALUES ${PNG_RISCV_RVV} index)
if(index EQUAL -1) if(index EQUAL -1)
message(FATAL_ERROR "PNG_RISCV_RVV must be one of [${PNG_RISCV_RVV_POSSIBLE_VALUES}]") message(FATAL_ERROR "PNG_RISCV_RVV must be one of [${PNG_RISCV_RVV_POSSIBLE_VALUES}]")
elseif(NOT ${PNG_RISCV_RVV} STREQUAL "off") elseif(NOT PNG_RISCV_RVV STREQUAL "off")
check_c_compiler_flag("-march=rv64gv1p0" COMPILER_SUPPORTS_RVV) check_c_compiler_flag("-march=rv64gv1p0" COMPILER_SUPPORTS_RVV)
if(NOT COMPILER_SUPPORTS_RVV) if(NOT COMPILER_SUPPORTS_RVV)
message(FATAL_ERROR "Compiler does not support -march=rv64gv1p0 option") message(FATAL_ERROR "Compiler does not support -march=rv64gv1p0 option")
@ -331,9 +331,9 @@ if(PNG_HARDWARE_OPTIMIZATIONS)
set(libpng_riscv_sources set(libpng_riscv_sources
riscv/filter_rvv_intrinsics.c riscv/filter_rvv_intrinsics.c
riscv/riscv_init.c) riscv/riscv_init.c)
if(${PNG_RISCV_RVV} STREQUAL "on") if(PNG_RISCV_RVV STREQUAL "on")
add_definitions(-DPNG_RISCV_RVV_OPT=2) add_definitions(-DPNG_RISCV_RVV_OPT=2)
elseif(${PNG_RISCV_RVV} STREQUAL "check") elseif(PNG_RISCV_RVV STREQUAL "check")
add_definitions(-DPNG_RISCV_RVV_CHECK_SUPPORTED) add_definitions(-DPNG_RISCV_RVV_CHECK_SUPPORTED)
endif() endif()
else() else()

View File

@ -12,8 +12,8 @@
* STATUS: SUPPORTED * STATUS: SUPPORTED
* BUG REPORTS: png-mng-implement@sourceforge.net * BUG REPORTS: png-mng-implement@sourceforge.net
* *
* png_have_rvv implemented for Linux by reading the widely available * png_have_rvv implemented for Linux by looking for COMPAT_HWCAP_ISA_V
* pseudo-file /proc/cpuinfo. * via hardware capabilites API.
* *
* This code is strict ANSI-C and is probably moderately portable; it does * This code is strict ANSI-C and is probably moderately portable; it does
* however use <stdio.h> and it assumes that /proc/cpuinfo is never localized. * however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.

View File

@ -146,13 +146,19 @@
#ifndef PNG_RISCV_RVV_OPT #ifndef PNG_RISCV_RVV_OPT
/* RISCV_RVV optimizations are being controlled by the compiler settings, /* RISCV_RVV optimizations are being controlled by the compiler settings,
* typically the target compiler will define __riscv but the rvv extension * typically the target compiler will define __riscv but the rvv extension
* availability has to be explicitly stated * availability has to be explicitly stated. This is why if no
* PNG_RISCV_RVV_OPT was defined then a runtime check will be executed.
* *
* To enable RISCV_RVV optimizations, and compile the * To enable RISCV_RVV optimizations unconditionally, and compile the
* associated code, pass --enable-riscv-rvv=yes or --enable-riscv-rvv=on * associated code, pass --enable-riscv-rvv=yes or --enable-riscv-rvv=on
* to configure or put -DPNG_RISCV_RVV_OPT=2 in CPPFLAGS. * to configure or put -DPNG_RISCV_RVV_OPT=2 in CPPFLAGS.
*/ */
# if defined(__riscv) && defined(PNG_ALIGNED_MEMORY_SUPPORTED)
# define PNG_RISCV_RVV_OPT 1
# else
# define PNG_RISCV_RVV_OPT 0 # define PNG_RISCV_RVV_OPT 0
# endif
#endif #endif
#if PNG_ARM_NEON_OPT > 0 #if PNG_ARM_NEON_OPT > 0

View File

@ -16,24 +16,22 @@
#include <riscv_vector.h> #include <riscv_vector.h>
#ifdef PNG_RISCV_RVV_CHECK_SUPPORTED
#include <signal.h>
#endif
#ifdef PNG_RISCV_RVV_CHECK_SUPPORTED /* Do run-time checks */ #ifdef PNG_RISCV_RVV_CHECK_SUPPORTED /* Do run-time checks */
/* WARNING: it is strongly recommended that you do not build libpng with /* WARNING: it is strongly recommended that you do not build libpng with
* run-time checks for CPU features if at all possible. In the case of the * run-time checks for CPU features if at all possible. In the case of the
* RISC-V Vector instructions there is no processor-specific way of detecting * RISC-V Vector instructions there is no processor-specific way of detecting
* the presence of the required support, therefore run-time detection is * the presence of the required support, therefore run-time detection is
* extremely OS specific. * extremely OS specific.
* *
* You may set the macro PNG_RISCV_RVV_FILE to the file name of file containing * You may set the macro PNG_RISCV_RVV_FILE to the file name of file containing
* a fragment of C source code which defines the png_have_neon function. There * a fragment of C source code which defines the png_have_rvv function. There
* are a number of implementations in contrib/riscv-rvv, but the only one that * are a number of implementations in contrib/riscv-rvv, but the only one that
* has partial support is contrib/riscv-rvv/linux.c - a generic Linux * has partial support is contrib/riscv-rvv/linux.c - a generic Linux
* implementation which reads /proc/cpuinfo. * implementation which reads /proc/cpuinfo.
*/ */
#include <signal.h>
#ifndef PNG_RISCV_RVV_FILE #ifndef PNG_RISCV_RVV_FILE
# if defined(__linux__) # if defined(__linux__)
# define PNG_RISCV_RVV_FILE "contrib/riscv-rvv/linux.c" # define PNG_RISCV_RVV_FILE "contrib/riscv-rvv/linux.c"