diff --git a/configure b/configure index 63cd0cdb5..501afd2fe 100755 --- a/configure +++ b/configure @@ -1593,6 +1593,11 @@ Optional Features: no/off: disable the optimizations; yes/on: turn on unconditionally. If not specified: determined by the 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: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -15561,6 +15566,61 @@ else PNG_LOONGARCH_LSX_FALSE= 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: 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. Usually this means the macro was only invoked conditionally." "$LINENO" 5 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}" ac_write_fail=0 diff --git a/configure.ac b/configure.ac index 18abfcd9c..348a29042 100644 --- a/configure.ac +++ b/configure.ac @@ -682,7 +682,7 @@ AS_HELP_STRING([[[--enable-riscv-rvv]]], [If not specified: determined by the compiler.]), [case "$enableval" in no|off) - # disable the default enabling on __ppc64__ systems: + # disable the default enabling on __riscv systems: AC_DEFINE([PNG_RISCV_RVV_OPT], [0], [Disable RISC-V Vector optimizations]) # Prevent inclusion of the platform-specific files below: diff --git a/contrib/riscv-rvv/README b/contrib/riscv-rvv/README index 338e25f1a..9780d49ba 100644 --- a/contrib/riscv-rvv/README +++ b/contrib/riscv-rvv/README @@ -24,7 +24,7 @@ This is done in a 'configure' build by passing configure the argument: --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 basis and may be broken in any given minor release. diff --git a/png.h b/png.h index ca1ef08f1..7f9c0dcd0 100644 --- a/png.h +++ b/png.h @@ -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 */ #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 */ #define PNG_OPTION_UNSET 0 /* Unset - defaults to off */ diff --git a/pngpriv.h b/pngpriv.h index bfbc94d92..ad30e8d93 100644 --- a/pngpriv.h +++ b/pngpriv.h @@ -145,28 +145,14 @@ #ifndef PNG_RISCV_RVV_OPT /* RISCV_RVV optimizations are being controlled by the compiler settings, - * typically the target FPU then the compiler will define __RVV__ and we can rely - * unconditionally on NEON instructions not crashing, otherwise we must - * disable use of NEON instructions. + * typically the target compiler will define __riscv but the rvv extension + * availability has to be explicitly stated * - * NOTE: at present these optimizations depend on 'ALIGNED_MEMORY', so they - * can only be turned on automatically if that is supported too. If - * PNG_RISCV_RVV_OPT is set in CPPFLAGS (to >0) then riscv/riscv_init.c will fail - * 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. + * To enable RISCV_RVV optimizations, and compile the + * associated code, pass --enable-riscv-rvv=yes or --enable-riscv-rvv=on + * to configure or put -DPNG_RISCV_RVV_OPT=2 in CPPFLAGS. */ -# if defined(__RVV__) && defined(PNG_ALIGNED_MEMORY_SUPPORTED) -# define PNG_RISCV_RVV_OPT 2 -# else # define PNG_RISCV_RVV_OPT 0 -# endif #endif #if PNG_ARM_NEON_OPT > 0 diff --git a/riscv/riscv_init.c b/riscv/riscv_init.c index 869211a8d..aae57a709 100644 --- a/riscv/riscv_init.c +++ b/riscv/riscv_init.c @@ -16,6 +16,10 @@ #include +#ifdef PNG_RISCV_RVV_CHECK_SUPPORTED +#include +#endif + #ifdef PNG_RISCV_RVV_CHECK_SUPPORTED /* Do run-time checks */ /* 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 @@ -25,14 +29,14 @@ * * 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 - * are a number of implementations in contrib/riscv-vector, but the only one that - * has partial support is contrib/riscv-vector/linux.c - a generic Linux + * 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 * implementation which reads /proc/cpuinfo. */ #ifndef PNG_RISCV_RVV_FILE # if defined(__linux__) -# define PNG_RISCV_RVV_FILE "contrib/riscv-vector/linux.c" +# define PNG_RISCV_RVV_FILE "contrib/riscv-rvv/linux.c" # else # error "No support for run-time RISC-V Vector checking; use compile-time options" # endif