Skip to content

Conversation

@filipwasil
Copy link
Contributor

Updating and testing autotools build and CMake build
Renaming riscv-vector to riscv-rvv
Changes implementation of few functions because they do not compile for RVV 1.0 via gcc 14.0.1 20240412
Corrected and added few flag names and definitions
Solved merge conflicts

@filipwasil
Copy link
Contributor Author

filipwasil commented Mar 7, 2025

Rebased on top of the 1.68 release taking a commit from source forge branch:
https://sourceforge.net/u/dragostis/libpng/ci/riscv-vector/tree/

@dragoș Tiselice
@jbowler
@ctruta

Tested via:

CMake build:

mkdir build && cd build
CC=gcc-14 CXX=g++-14 CFLAGS="-march=rv64gcv1p0" cmake .. -DPNG_RISCV_RVV=on
cmake --build .

Autotools build:

./configure --enable-riscv-rvv
make

Notes:

  1. Tests
    1a) tested via running the pngtest, it covered most of the functions added some bugs found. ("images not the same" logs)
    1b) Tests did not cover the following functions:
    png_read_filter_row_sub3_rvv_128
    png_read_filter_row_avg3_rvv
    prefix_sum
    png_read_filter_row_sub3_rvv_256
    png_read_filter_row_paeth3_rvv

  2. As default the support is off, You have to pass flags to include the code to compilation mechanism.

  3. I did not create a new ticket in regard to RVV. Sticking to this one:
    Support for RISC-V Vector Extension #405

  4. I did not look at mschlaegl changes due to the fact the other changes were considered the ones to be processed further. If this is not the case of if id I - by any means - misinterpreted the @jbowler intention, please let me know.

The way i would like to proceed with this is to make some tests for the functions not covered by the pngtest and then remove the "draft" prefix. My intention is bringing this support to the state it can be safely merged to upstream.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way of checking for extension support doesn't work. It would e.g. parse the following ISA strings as supporting RVV, while they don't: "rv64gc_xtheadvector", "rv64gcb_xventanacondops"
I would recommend using the hwprobe interface: https://docs.kernel.org/arch/riscv/hwprobe.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed the issue making this check a one liner.

@@ -0,0 +1,275 @@
/* filter_neon_intrinsics.c - RISC-V Vector optimized filter functions

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong file name in comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

__riscv_vsseg4e8_v_u8m1x4(
riffled_palette,
__riscv_vcreate_v_u8m1x4(
__riscv_vget_v_u8m1x3_u8m1(rgb, 0),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect a LMUL=2 vrgather to be faster on most hardware. A widen+merge+compress could also be interesting to look at.

@jbowler
Copy link
Contributor

jbowler commented Mar 9, 2025

@ctruta, @svgeesus Your call of course by I wouldn't touch this with a barge pole.

The problem is that the reference to the specification, not here but in @mschlaegl original PR #405 in fact refers to a marketing document which does not contain a spec.

I continued searching (dumb fool that I am) and I found this apparently genuine web site:

https://riscv.org/specifications/ratified/

Well, it's not there but one or other of the links leads to a page on "atlassian.net" which leads to this page:

https://lf-riscv.atlassian.net/wiki/spaces/HOME/pages/16154899/RISC-V+Technical+Specifications+Archive

(NOTE for those who aren't used to doing this, it's a wiki). That, you will note, uses the suffix "+Archive" and leads to a specification on someone's Google Drive someone unidentifiable. The entry on the web site comes from the, "Unprivileged Horizontal Committee". Sounds like me, after I'd finish ROTL I checked them out:

Posts to this group do not require approval from the moderators.
Subscriptions to this group do not require approval from the moderators.

This is the same mess as the MIPS instruction set. Not my problem.

@camel-cdr
Copy link

The latest RISC-V spec can be found on the riscv-isa-manual github, here is fhe file with the ratified RVV spec: https://github.com/riscv/riscv-isa-manual/blob/main/src/v-st-ext.adoc
It's ratified and the only gets small formatting changes or wording clarifications.
You can also download the full manual from the releases.

@filipwasil
Copy link
Contributor Author

filipwasil commented Mar 10, 2025

@filipwasil filipwasil force-pushed the riscv-vector-updated-16 branch 2 times, most recently from 566b408 to 5438353 Compare March 11, 2025 12:29
@filipwasil
Copy link
Contributor Author

Thank You for all the comments

As I see it now, the implementation I assumed I will rely on looks like a work in progress. Tests do not pass.
I decided to utilize the already existing @msc implementation which has this great property that it is well "comment documented". I refactored the code to simplify it just a bit reducing the string literals macros as we stick to RVV 1.0+ anyways.

At this point I propose such a roadmap:

  1. I will rewrite what has been done in assembly to match the overall convention of writing c instrinsics not asm.
  2. I will create a PR to upstream basing only on what is done and tested (the filtering functions) and build configuration
  3. I will let the palette rvv intrinsics to be a separate MR after I do all the related tests and probably make some small/big modificatios on my own.

Does this sound like a plan ?

@filipwasil
Copy link
Contributor Author

filipwasil commented Mar 11, 2025

TLDR:

  • filtering functions are tested and correct (proved via pngtest test)
  • palette intrinsic included in this MR (tested via ./build_rv/pngimage --exhaustive --list-combos --log "${PWD}/contrib/pngsuite/"*.png)
  • Question: Should I leave the assembly here as the original author proposed, or rewrite with c instrinsics ?

@ctruta, @svgeesus

@filipwasil filipwasil force-pushed the riscv-vector-updated-16 branch from 5438353 to 638dfdb Compare March 11, 2025 13:31
@@ -0,0 +1,85 @@
OPERATING SYSTEM SPECIFIC ARM NEON DETECTION
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ARM NEON"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks

@filipwasil filipwasil force-pushed the riscv-vector-updated-16 branch from 103547c to 21606ec Compare March 14, 2025 09:07
@filipwasil
Copy link
Contributor Author

EDIT:
Merged the palette functions: Now the tests pass.

@filipwasil filipwasil force-pushed the riscv-vector-updated-16 branch from 21606ec to 5c7cd57 Compare March 14, 2025 11:19
@filipwasil filipwasil changed the title RISC-V RVV extension (draft) RISC-V RVV extension Mar 14, 2025
@filipwasil filipwasil force-pushed the riscv-vector-updated-16 branch from 5c7cd57 to f732c87 Compare March 14, 2025 12:45
@filipwasil
Copy link
Contributor Author

filipwasil commented Mar 14, 2025

@ctruta, @svgeesus

Before I start to rewrite the ASM part into c intrinsics, please let me know: are there any concerns which I should address and specifically - is there a need to rewrite it at all ? When it comes to the spec: The specification rev 1.0 is already ratified. Are there any specific documents we need to proceed with these changes ?

We have recently pushed docker based CI configuration to https://gitlab.freedesktop.org/pixman/pixman to be able to automate SIMD vectorization testing for RISC-V RVV. Is this a factor for this particular PR ? Having this specific code tested within CI ?

As for these changes:
I tested these functions with native Banana PiF3 (256b VLEN)
Compiler GCC 14.0.1

Build cmake

CC=gcc-14 CXX=g++-14 CFLAGS="-march=rv64gcv1p0" cmake .. -DPNG_RISCV_RVV=on
cmake --build ./build_rv

Build autotools

./configure --enable-riscv-rvv
make

tests:

root@bpif3:~/Projects/libpng# pngimage --exhaustive --list-combos --log "${PWD}/contrib/pngsuite/"*.png

PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn0g01.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn0g02.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn0g04.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn0g08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn0g16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn2c08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn2c16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn3p01.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn3p02.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn3p04.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn4a08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn4a16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn6a08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/basn6a16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftbbn0g01.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftbbn0g02.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftbbn0g04.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftbbn2c16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftbbn3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftbgn2c16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftbgn3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftbrn2c08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftbwn0g16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftbwn3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftbyn3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftp0n0g08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftp0n2c08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftp0n3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ftp1n3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ibasn0g08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ibasn0g16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ibasn2c08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ibasn2c16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ibasn3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ibasn4a08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ibasn4a16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ibasn6a08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/ibasn6a16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftbbn2c16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftbbn3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftbgn2c16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftbgn3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftbrn2c08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftbwn0g16.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftbwn3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftbyn3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftp0n0g08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftp0n2c08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftp0n3p08.png
PASS: pngimage --exhaustive --list-combos /root/Projects/libpng/contrib/pngsuite/iftp1n3p08.png
root@bpif3:~/Projects/libpng# ./build_rv/pngtest

 Testing libpng version 1.6.48.git
   with zlib   version 1.3

libpng version 1.6.48.git
Copyright (c) 2018-2025 Cosmin Truta
Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
Copyright (c) 1996-1997 Andreas Dilger
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
 library (10648): libpng version 1.6.48.git

 pngtest (10648): libpng version 1.6.48.git

 Testing pngtest.png: eXIf type MM, 52 bytes

 Pass 0: rwrwrwrwrwrwrwrwrw
 Pass 1: rwrwrwrwrwrwrwrwrw
 Pass 2: rwrwrwrwrwrwrwrw
 Pass 3: rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
 Pass 4: rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
 Pass 5: rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
         rwrwrwrw
 Pass 6: rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
         rwrwrwrwrw eXIf type MM, 52 bytes
 eXIf type MM, 52 bytes

 PASS (9782 zero samples)
 tIME = 7 Jun 1996 17:58:08 +0000
 libpng passes test
 Default limits:
  width_max  = 1000000
  height_max = 1000000
  cache_max  = 1000
  malloc_max = 8000000

@svgeesus
Copy link
Collaborator

I defer to @ctruta on this one, I have nothing to contribute here

@ctruta
Copy link
Member

ctruta commented Mar 14, 2025

Thank you for your extraordinary patience. I'm back again at this project, giving your PR a look, and a spin.

@filipwasil filipwasil force-pushed the riscv-vector-updated-16 branch from 6449a96 to 638dfdb Compare April 28, 2025 19:36
@filipwasil
Copy link
Contributor Author

I updated the branch because of few reasons:

  • Doing further tests I discovered that pngvalidate detected errors in palette related functionalities - removed it.
  • I did not get any feedback on the fact of mixing c intrinsics and asm in the riscv implementation, so I sticked to the asm only.
  • Rebasing over recent upstream
  • Removing all RVV < 1.0 API code as the 1.0 is considered a mature and well supported at this point. Its testable in gitlab QEMU based CI setup (like for pixman) and well supported by hardware (Banana pi f3).

At this point this commit contains only changes proven to pass all tests and to provide the whole build system related boilerplate code, only supporting the RVV 1.0+ spec as it is and will be the mature revision having more and more extensions and proven

By all tests I mean:

pngvalidate
pngtest
pngimage --exhaustive --list-combos --log "${PWD}/contrib/pngsuite/"*.png

Have this merged to upstream probably would be a good base for any further optimizations for RISC-V Vector extension which I have to work on, if the help is appreciated.

In pixman CI setup we are able to test against future revisions of RISC-V hardware supporting 512b and even 1024b VLEN already, as the existing hardware (like BPi F3) have only 256b.

@ctruta
Copy link
Member

ctruta commented Apr 28, 2025

I pushed one last change for the upcoming v1.6.48 which I want to release tomorrow. It's for helping me with the testing of CMake-based cross-platform builds, because I had quite a few headaches as I was working on putting these onto the CI bots.

(For context: we never tested cross-platform builds on the CI bots before, but I want to change that.)

Just so you know: in my local workflow, I'm running Ubuntu under QEMU, and I want to set up FreeBSD as well.

@ctruta
Copy link
Member

ctruta commented Apr 28, 2025

(For context: we never tested cross-platform builds on the CI bots before, but I want to change that.)

About that: any tips, links, do's, dont's that you happen to know and you think I might want to know -- I will greatly appreciate.

@jbowler
Copy link
Contributor

jbowler commented Apr 29, 2025

@ctruta : the lines of the form:

#if PNG_RISCV_RVV_OPT > 0

have not been permitted before. This is because the maintainer regards (regarded?) things that failed with -Wundef as inadmissible; this is a large cause of massive # directive nesting (and a major annoyance to me.)

While it is stated that the changes were copied from the ARM ones the ARM tests have the required checks that the macros being tested are defined.

It would vastly, vastly simplify the #if mess were the ANSI-C rules (not-defined := 0) followed but I suggest that this might be a 1.8 thing. -Werror=undef

It's an easy fix @filipwasil PITA but easy.

@ctruta
Copy link
Member

ctruta commented Apr 29, 2025

This is because the maintainer regards (regarded?) things that failed with -Wundef as inadmissible; this is a large cause of massive # directive nesting (and a major annoyance to me.)

@jbowler I hereby give it to you in writing that, if you want to blame it on my inability to tell the difference between an unintentionally-uninitialized macro which is obviously a bug -- versus -- an intentionally-uninitialized macro which is obviously a feature, I promise not to take it personally 🤪

The people who understand my statement "I wouldn't touch Perl code without use strict and use warnings even with a three-meter pole" will know exactly what I mean.

It would vastly, vastly simplify the #if mess were the ANSI-C rules (not-defined := 0) followed but I suggest that this might be a 1.8 thing. -Werror=undef

Speaking about the aforementioned PITA: let me please not get myself started on -Wextra. (Remember what happened, just recently, in pncheck's makefile?)

As a general observation: every single macro in libpng is there for a reason. And yet, all of those macros, combined, are an over-engineered mess which accreted over the decades, black-hole-style. If we need to keep doing anything in v1.8 is to keep cleaning as much of that as possible. I firmly believe that any soul who somehow ended up entrapped in a room with the libpng code (that they must read, and not only that, but also comprehend) will thank us later.

It can be done. (Trust Me™️)

@filipwasil
Copy link
Contributor Author

filipwasil commented Apr 30, 2025

Building

Hardware Build flags Build passed RVV included Notes
RISC-V CC=gcc-14 cmake .. -DPNG_RISCV_RVV=off Yes No -
RISC-V CC=gcc-14 CFLAGS="-march=rv64gcv1p0 -Werror=undef" cmake .. -DPNG_RISCV_RVV=on Yes Yes -
RISC-V CC=gcc-14 CFLAGS="-march=rv64gcv1p0 -Werror=undef" cmake .. -DPNG_RISCV_RVV=check Yes Yes -
RISC-V CC=gcc-14 CFLAGS="-march=rv64gcv1p0 -Werror=undef" cmake .. -DPNG_RISCV_RVV=api No No Unsupported option
RISC-V CC=gcc-14 CFLAGS="-march=rv64gcv1p0 -Werror=undef" cmake .. -DPNG_RISCV_RVV=off Yes No -
RISC-V CC=gcc-14 cmake .. CFLAGS="-Werror=undef" ? Yes -
RISC-V CC=gcc-14 cmake .. -DPNG_RISCV_RVV=on No No Missing -march definition, missing headers
RISC-V ./configure --enable-riscv-rvv=on Yes Yes -
RISC-V ./configure --enable-riscv-rvv=yes Yes Yes -
RISC-V ./configure --enable-riscv-rvv=check Yes Yes -
RISC-V ./configure --enable-riscv-rvv=api Yes No Unsupported option
RISC-V ./configure --enable-riscv-rvv=no Yes No -
RISC-V ./configure Yes No -
x64 CC=gcc-14 CFLAGS="-Werror=undef" cmake .. -DPNG_RISCV_RVV=off Yes No Warning. PNG_RISCV_RVV not specified by the project
x64 CC=gcc-14 CFLAGS="-Werror=undef" cmake .. -DPNG_RISCV_RVV=on Yes No Warning. PNG_RISCV_RVV not specified by the project
x64 ./configure --enable-arm-neon=yes No No pngrtran.c:26:16: fatal error: arm_neon.h: No such file or directory 26
x64 ./configure --enable-arm-neon=check No No pngrtran.c:26:16: fatal error: arm_neon.h: No such file or directory 26
x64 ./configure --enable-arm-neon=api No No pngrtran.c:26:16: fatal error: arm_neon.h: No such file or directory 26
x64 ./configure --enable-riscv-rvv=yes No No riscv/filter_rvv_intrinsics.c:19:10: fatal error: riscv_vector.h: No such file or directory 19
x64 ./configure --enable-riscv-rvv=check No No -
x64 ./configure --enable-riscv-rvv=api No No Unsupported option

Few notes:

  • no errors when -Werror=undef regardless if its x64 or RISC-V
  • When passing -DPNG_RISCV_RVV=on with RVV it succeeds only when appropriate microarchitecture is defined as well as a compiler flag (Ex. -march=rv64gcv1p0, -march=rv64gcv, -march=rv64gv1p0, -march=rv64gv for compressed and uncompressed instructions).

@filipwasil filipwasil changed the title RISC-V RVV extension draft: RISC-V RVV extension Apr 30, 2025
@filipwasil
Copy link
Contributor Author

I will improve the detection mechanism for autotools and remove the "draft" prefix when its all tested

@ctruta
Copy link
Member

ctruta commented Apr 30, 2025

FYI, I acknowledge your very long wait and I appreciate your very long patience. I will apply the finishing touches to the v1.6.48 release, then I will then I will initiate v1.6.49, then I will apply your submission, in this particular order.

@ctruta
Copy link
Member

ctruta commented May 1, 2025

Aaand..... we're in! 🚀 ✨

I must admit that I have yet to test this in my own RVV VM. Last time I did run tests, it was when I put in the files ci/targets/linux/ci_env.riscv64-linux-gnu.sh and ci/targets/freebsd/ci_env.riscv64-unknown-freebsd.sh -- so, they're in there, and fortunately, it's far easier to run cross-platform tests nowadays.

Let's let this brew for a couple of weeks, and I'll run my own tests properly in the meantime.

@ctruta
Copy link
Member

ctruta commented May 1, 2025

@filipwasil could you please fix (or rewrite) the paragraphs in this comment:

* unconditionally on NEON instructions not crashing, otherwise we must

I integrated them no problem, but they're still bad copy-pasta. I don't suppose you guys actually intended to write /*[...] the compiler will define __RVV__ and we can rely unconditionally on NEON instructions not crashing [...]*/

I think if you just force-push away the commits that I just integrated (with tiny stylistic changes differences that appear to irreconcilable to GitHub's rebase bot, as you can see), and then you add in a new commit which contains with those fixes -- that should work just fine in this workflow.

@filipwasil
Copy link
Contributor Author

filipwasil commented May 1, 2025 via email

@filipwasil filipwasil force-pushed the riscv-vector-updated-16 branch 3 times, most recently from 394bb02 to 546fe8e Compare May 6, 2025 08:33
@filipwasil
Copy link
Contributor Author

filipwasil commented May 6, 2025

After tests i updated comments and some definitions as well as this table:
#666 (comment)

Now all should be more complete and according to my tests : correct
The RVV is off by default, as described

for autotools and for CMAKE -> on x86 we can explicitly try to compile the risc-v or ARM but then the compilation fails because of missing headers. I assumed that this is considered correct.

@filipwasil filipwasil changed the title draft: RISC-V RVV extension RISC-V RVV extension May 6, 2025
@jbowler
Copy link
Contributor

jbowler commented May 7, 2025

for autotools and for CMAKE -> on x86 we can explicitly try to compile the risc-v or ARM but then the compilation fails because of missing headers. I assumed that this is considered correct.

No; there is a longstanding bug with cmake builds of ARM but they fail at the link step; no missing headers. Both RISC-V and ARM (i.e. 32-bit) currently build just fine with configure on AMD64 (i.e. x86) with the current libpng16:HEAD

In the RISCV build the RISCV objects (riscv/*.o) do not define any of the expected symbols (this is with -march=rv64g_v) and object modules are being build for riscv, mips and powerpc (i.e. all three architectures are built), whereas they are not built for arm, intel or loongarch. This is in 1.6.48 too so is a separate issue. It's a non-issue since the modules are empty and this is the way libpng 1.8 does things (all the hardware stuff is built on all architectures).

The fact that RISCV builds do not build anything however is perhaps unintended.

@filipwasil
Copy link
Contributor Author

filipwasil commented May 8, 2025

Thanks for the explanation @jbowler . Just one note in regard to:

rv64g_v

-march=rv64gv
• rv64: 64-bit base ISA.
• g: A shorthand for the standard set of general-purpose extensions, which is equivalent to imafd (Integer, Multiply/Divide, Atomic, Single-Precision FP, Double-Precision FP)2.
• v: The RISC-V Vector extension.
So, -march=rv64gv means:
• 64-bit base integer ISA
• General-purpose extensions (imafd)
• Vector extension (v)
This is a valid and canonical GCC ISA string.

The underscore is used to separate multi-letter or non-standard extensions, but in the case of the vector extension, the standard GCC and RISC-V convention is to append v directly after the other extensions, without an underscore2.
So, -march=rv64g_v is not the canonical or correct way to specify the vector extension in GCC. The correct form is -march=rv64gv.

@filipwasil
Copy link
Contributor Author

I did an update to support the runtime check build for both build systems and updated the table once more

@ctruta
Copy link
Member

ctruta commented May 14, 2025

Please don't mind my use of GitHub through the command line, which sometimes confuses the web interface. I'll close this PR as "not merged", even though all submissions sent to us so far are already in.

I'll let this brew for a few more days, and then I'll publish libpng-1.6.49 with RISC-V support.

Thank you very much @filipwasil @dragostis @mschlaegl for your great work on this submission, and thank you everybody who contributed comments and reviews.

@ctruta ctruta closed this May 14, 2025
@kmilos
Copy link

kmilos commented May 14, 2025

There's maybe a few typos to sort out before releasing:

libpng/configure

Line 15608 in 7108843

# Add RISCV-specific files to all builds where $host_cpu is arm ('riscv64*') or

OPERATING SYSTEM SPECIFIC ARM NEON DETECTION

/* arm_init.c - RISC-V Vector optimized filter functions

* If the CHECK is not compiled in and the option is UNSET the behavior prior
* to 1.6.7 was to use the NEON code - this was a bug caused by having the
* wrong order of the 'ON' and 'default' cases. UNSET now defaults to OFF,
* as documented in png.h

@ctruta
Copy link
Member

ctruta commented May 14, 2025

There's maybe a few typos to sort out before releasing [...]

A-ha!

@ctruta ctruta reopened this May 14, 2025
@ctruta
Copy link
Member

ctruta commented May 14, 2025

I wrote:

I integrated them no problem, but they're still bad copy-pasta. I don't suppose you guys actually intended to write /[...] the compiler will define __RVV__ and we can rely unconditionally on NEON instructions not crashing [...]/

So, yeah, I did spot the copy-pasta two weeks ago, but not earlier today, apparently. Thanks for the catch, @kmilos.

If the tests are passing, that's great. But then, there's this:
"If the comment says one thing and the code does another, they're both incorrect."

Fix wanted, please :-)

@filipwasil filipwasil force-pushed the riscv-vector-updated-16 branch from 94cd171 to 9ff6e6f Compare May 14, 2025 17:37
@filipwasil
Copy link
Contributor Author

Thanks for Your time reviewing the PR. I went through the comments. found two more things. fixed.

@ctruta ctruta merged commit 009b90d into pnggroup:libpng16 May 14, 2025
1 check passed
@ctruta
Copy link
Member

ctruta commented May 14, 2025

Ok, so, we're almost finished, but still not entirely finished.

@filipwasil if run locally the command

./autogen.sh --maintainer

you will see a bunch of changes. Everything except for "ltmain.sh" will need to be updated, eventually. I will run this command, so you don't have to, but... could you please run it as well, at least locally, to make sure that things don't break?

The autogen command (which runs autoreconf underneath) will apply changes not only to script code but also to script comments, so please review those ones also.

In case you might be unfamiliar with the autotools, here's how to get them, e.g., with Homebrew:

brew install autoconf automake libtool m4 gettext gperf texinfo pkg-config

No, seriously, we're getting there... we're getting there... :-)

@filipwasil filipwasil deleted the riscv-vector-updated-16 branch May 19, 2025 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants