riscv: Fix autotools definitions and comments

Signed-off-by: Cosmin Truta <ctruta@gmail.com>
This commit is contained in:
Filip Wasil 2025-05-05 15:47:38 +02:00 committed by Cosmin Truta
parent ffb8e8b26f
commit 2b0eb78656
6 changed files with 83 additions and 25 deletions

64
configure vendored
View File

@ -1593,6 +1593,11 @@ Optional Features:
no/off: disable the optimizations; yes/on: turn on no/off: disable the optimizations; yes/on: turn on
unconditionally. If not specified: determined by the unconditionally. If not specified: determined by the
compiler. compiler.
--enable-riscv-rvv
Enable RISC-V Vector optimizations: =no/off, yes/on:
no/off: disable the optimizations; yes/on: turn on
unconditionally. If not specified: determined by the
compiler.
Optional Packages: Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@ -15561,6 +15566,61 @@ else
PNG_LOONGARCH_LSX_FALSE= PNG_LOONGARCH_LSX_FALSE=
fi fi
# RISC-V RVV
# =============
# Check whether --enable-riscv-rvv was given.
if test ${enable_riscv_rvv+y}
then :
enableval=$enable_riscv_rvv; case "$enableval" in
no|off)
# disable the default enabling on __RVV__ systems:
printf "%s\n" "#define PNG_RISCV_RVV_OPT 0" >>confdefs.h
# Prevent inclusion of the assembler files below:
enable_riscv_rvv=no ;;
check)
printf "%s\n" "#define PNG_RISCV_RVV_CHECK_SUPPORTED /**/" >>confdefs.h
;;
api)
printf "%s\n" "#define PNG_RISCV_RVV_API_SUPPORTED /**/" >>confdefs.h
;;
yes|on)
printf "%s\n" "#define PNG_RISCV_RVV_OPT 2" >>confdefs.h
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: --enable-riscv-rvv: please specify 'check' or 'api';
if you want the optimizations unconditionally,
pass '-march=rv64gv1p0' or '-march=rv64gcv1p0' to the compiler." >&5
printf "%s\n" "$as_me: WARNING: --enable-riscv-rvv: please specify 'check' or 'api';
if you want the optimizations unconditionally,
pass '-march=rv64gv1p0' or '-march=rv64gcv1p0' to the compiler." >&2;};;
*)
as_fn_error $? "--enable-riscv-rvv=${enable_riscv_rvv}:
invalid argument" "$LINENO" 5
esac
fi
# Add RISCV-specific files to all builds where $host_cpu is arm ('riscv64*') or
# where RISCV optimizations were explicitly requested. (This allows a fallback
# if a future host CPU does not match 'riscv64*'.)
if test "$enable_riscv_rvv" != 'no' &&
case "$host_cpu" in
riscv64) : ;;
*) test "$enable_riscv_rvv" != '' ;;
esac; then
PNG_RISCV_RVV_TRUE=
PNG_RISCV_RVV_FALSE='#'
else
PNG_RISCV_RVV_TRUE='#'
PNG_RISCV_RVV_FALSE=
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: Extra options for compiler: $PNG_COPTS" >&5 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: Extra options for compiler: $PNG_COPTS" >&5
printf "%s\n" "$as_me: Extra options for compiler: $PNG_COPTS" >&6;} printf "%s\n" "$as_me: Extra options for compiler: $PNG_COPTS" >&6;}
@ -15784,6 +15844,10 @@ if test -z "${PNG_LOONGARCH_LSX_TRUE}" && test -z "${PNG_LOONGARCH_LSX_FALSE}";
as_fn_error $? "conditional \"PNG_LOONGARCH_LSX\" was never defined. as_fn_error $? "conditional \"PNG_LOONGARCH_LSX\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5 Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi fi
if test -z "${PNG_RISCV_RVV_TRUE}" && test -z "${PNG_RISCV_RVV_FALSE}"; then
as_fn_error $? "conditional \"PNG_RISCV_RVV\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
: "${CONFIG_STATUS=./config.status}" : "${CONFIG_STATUS=./config.status}"
ac_write_fail=0 ac_write_fail=0

View File

@ -682,7 +682,7 @@ AS_HELP_STRING([[[--enable-riscv-rvv]]],
[If not specified: determined by the compiler.]), [If not specified: determined by the compiler.]),
[case "$enableval" in [case "$enableval" in
no|off) no|off)
# disable the default enabling on __ppc64__ systems: # disable the default enabling on __riscv systems:
AC_DEFINE([PNG_RISCV_RVV_OPT], [0], AC_DEFINE([PNG_RISCV_RVV_OPT], [0],
[Disable RISC-V Vector optimizations]) [Disable RISC-V Vector optimizations])
# Prevent inclusion of the platform-specific files below: # Prevent inclusion of the platform-specific files below:

View File

@ -24,7 +24,7 @@ This is done in a 'configure' build by passing configure the argument:
--enable-riscv-rvv=check --enable-riscv-rvv=check
Apart from the basic Linux implementation in contrib/riscv-vector/linux.c this Apart from the basic Linux implementation in contrib/riscv-rvv/linux.c this
code is unsupported. That means that it is not even compiled on a regular code is unsupported. That means that it is not even compiled on a regular
basis and may be broken in any given minor release. basis and may be broken in any given minor release.

6
png.h
View File

@ -3322,7 +3322,11 @@ PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory,
# define PNG_MIPS_MMI 12 /* HARDWARE: MIPS MMI SIMD instructions supported */ # define PNG_MIPS_MMI 12 /* HARDWARE: MIPS MMI SIMD instructions supported */
#endif #endif
#define PNG_OPTION_NEXT 14 /* Next option - numbers must be even */ #ifdef PNG_RISCV_RVV_API_SUPPORTED
# define PNG_RISCV_RVV 14 /* HARDWARE: RISC-V RVV SIMD instructions supported */
#endif
#define PNG_OPTION_NEXT 16 /* Next option - numbers must be even */
/* Return values: NOTE: there are four values and 'off' is *not* zero */ /* Return values: NOTE: there are four values and 'off' is *not* zero */
#define PNG_OPTION_UNSET 0 /* Unset - defaults to off */ #define PNG_OPTION_UNSET 0 /* Unset - defaults to off */

View File

@ -145,28 +145,14 @@
#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 FPU then the compiler will define __RVV__ and we can rely * typically the target compiler will define __riscv but the rvv extension
* unconditionally on NEON instructions not crashing, otherwise we must * availability has to be explicitly stated
* disable use of NEON instructions.
* *
* NOTE: at present these optimizations depend on 'ALIGNED_MEMORY', so they * To enable RISCV_RVV optimizations, and compile the
* can only be turned on automatically if that is supported too. If * associated code, pass --enable-riscv-rvv=yes or --enable-riscv-rvv=on
* PNG_RISCV_RVV_OPT is set in CPPFLAGS (to >0) then riscv/riscv_init.c will fail * to configure or put -DPNG_RISCV_RVV_OPT=2 in CPPFLAGS.
* to compile with an appropriate #error if ALIGNED_MEMORY has been turned
* off.
*
* Note that gcc and clang use the same __RVV__ flag. No known variations
* of this name is know as writing this code.
*
* To disable RISCV_RVV optimizations entirely, and skip compiling the
* associated assembler code, pass --enable-riscv-rvv=no to configure
* or put -DPNG_RISCV_RVV_OPT=0 in CPPFLAGS.
*/ */
# if defined(__RVV__) && defined(PNG_ALIGNED_MEMORY_SUPPORTED)
# define PNG_RISCV_RVV_OPT 2
# 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,6 +16,10 @@
#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
@ -25,14 +29,14 @@
* *
* 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_neon function. There
* are a number of implementations in contrib/riscv-vector, 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-vector/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.
*/ */
#ifndef PNG_RISCV_RVV_FILE #ifndef PNG_RISCV_RVV_FILE
# if defined(__linux__) # if defined(__linux__)
# define PNG_RISCV_RVV_FILE "contrib/riscv-vector/linux.c" # define PNG_RISCV_RVV_FILE "contrib/riscv-rvv/linux.c"
# else # else
# error "No support for run-time RISC-V Vector checking; use compile-time options" # error "No support for run-time RISC-V Vector checking; use compile-time options"
# endif # endif