Add RVV Optimizations for RISC-V Architecture Platforms #1043

Merged
zijianli1234 merged 2 commits from dev into dev 2025-06-15 19:35:30 -05:00
zijianli1234 commented 2025-06-13 04:21:13 -05:00 (Migrated from github.com)

This Pull Request aims to build upon the previously closed PR (This Pull Request aims to build upon the previously closed PR (#898) by focusing on optimizing xxHash performance for platforms based on the RISC-V architecture through Vector Extension (RVV) optimizations. ) by focusing on optimizing xxHash performance for platforms based on the RISC-V architecture through Vector Extension (RVV) optimizations.And this PR has pass check on qemu with vlen=128,256,512.
For illustration, here are some benchmark numbers, on a Spacemit(R) X60 @1.6 Ghz
command line:CFLAGS="-march=rv64gcv -O2 -DXXH_FORCE_MEMORY_ACCESS=0" make check

OK. (passes 49948 tests)
5ffb01494ce73724  stdin
5ffb01494ce73724  xxhash.c
517f15e1d01f6dae  xxhash.h
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
Sample of 100 KB...
 1#XXH32                         :     102400 ->    10681 it/s ( 1043.1 MB/s)
 3#XXH64                         :     102400 ->    14610 it/s ( 1426.8 MB/s)
 5#XXH3_64b                      :     102400 ->     9376 it/s (  915.7 MB/s)
11#XXH128                        :     102400 ->     9370 it/s (  915.1 MB/s)
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
Sample of 100 KB...
 1#XXH32                         :     102400 ->    10726 it/s ( 1047.4 MB/s)
 2#XXH32 unaligned               :     102400 ->     5159 it/s (  503.8 MB/s)
 3#XXH64                         :     102400 ->    14595 it/s ( 1425.3 MB/s)
 4#XXH64 unaligned               :     102400 ->     8807 it/s (  860.1 MB/s)
 5#XXH3_64b                      :     102400 ->     9389 it/s (  916.9 MB/s)
 6#XXH3_64b unaligned            :     102400 ->     9304 it/s (  908.6 MB/s)
 7#XXH3_64b w/seed               :     102400 ->     9385 it/s (  916.5 MB/s)
 8#XXH3_64b w/seed unaligned     :     102400 ->     9306 it/s (  908.8 MB/s)
 9#XXH3_64b w/secret             :     102400 ->     8980 it/s (  876.9 MB/s)
10#XXH3_64b w/secret unaligned   :     102400 ->     8913 it/s (  870.4 MB/s)
11#XXH128                        :     102400 ->     9350 it/s (  913.1 MB/s)
12#XXH128 unaligned              :     102400 ->     9254 it/s (  903.7 MB/s)
13#XXH128 w/seed                 :     102400 ->     9341 it/s (  912.2 MB/s)
14#XXH128 w/seed unaligned       :     102400 ->     9257 it/s (  904.0 MB/s)
15#XXH128 w/secret               :     102400 ->     8925 it/s (  871.6 MB/s)
16#XXH128 w/secret unaligned     :     102400 ->     8844 it/s (  863.7 MB/s)
17#XXH32_stream                  :     102400 ->     2556 it/s (  249.6 MB/s)
18#XXH32_stream unaligned        :     102400 ->     2537 it/s (  247.8 MB/s)
19#XXH64_stream                  :     102400 ->     5110 it/s (  499.0 MB/s)
20#XXH64_stream unaligned        :     102400 ->     4960 it/s (  484.4 MB/s)
21#XXH3_stream                   :     102400 ->     9250 it/s (  903.3 MB/s)
22#XXH3_stream unaligned         :     102400 ->     9184 it/s (  896.9 MB/s)
23#XXH3_stream w/seed            :     102400 ->     9249 it/s (  903.3 MB/s)
24#XXH3_stream w/seed unaligned  :     102400 ->     9163 it/s (  894.8 MB/s)
25#XXH128_stream                 :     102400 ->     9236 it/s (  902.0 MB/s)
26#XXH128_stream unaligned       :     102400 ->     9150 it/s (  893.5 MB/s)
27#XXH128_stream w/seed          :     102400 ->     9215 it/s (  899.9 MB/s)
28#XXH128_stream w/seed unaligne :     102400 ->     9121 it/s (  890.7 MB/s)
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
Sample of 100 KB...
 1#XXH32                         :     102400 ->    10700 it/s ( 1044.9 MB/s)
 2#XXH32 unaligned               :     102400 ->     5164 it/s (  504.3 MB/s)
 3#XXH64                         :     102400 ->    14587 it/s ( 1424.5 MB/s)
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
 1#XXH32                         :       1855 ->   569155 it/s ( 1006.9 MB/s)
 3#XXH64                         :       1855 ->   717551 it/s ( 1269.4 MB/s)
 5#XXH3_64b                      :       1855 ->   494573 it/s (  874.9 MB/s)
11#XXH128                        :       1855 ->   464638 it/s (  822.0 MB/s)
623b23d3  xxhash.c
7615c59c2d746e27e873a692555aca2b  xxhash.c
XXH3_e873a692555aca2b  xxhash.c
Wrong parameters

command line:CFLAGS="-O2 -DXXH_FORCE_MEMORY_ACCESS=0" make check

OK. (passes 49948 tests)
5ffb01494ce73724  stdin
5ffb01494ce73724  xxhash.c
517f15e1d01f6dae  xxhash.h
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
Sample of 100 KB...
 1#XXH32                         :     102400 ->    10664 it/s ( 1041.4 MB/s)
 3#XXH64                         :     102400 ->    14958 it/s ( 1460.7 MB/s)
 5#XXH3_64b                      :     102400 ->     3326 it/s (  324.8 MB/s)
11#XXH128                        :     102400 ->     3353 it/s (  327.4 MB/s)
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
Sample of 100 KB...
 1#XXH32                         :     102400 ->    10733 it/s ( 1048.1 MB/s)
 2#XXH32 unaligned               :     102400 ->     4332 it/s (  423.0 MB/s)
 3#XXH64                         :     102400 ->    14954 it/s ( 1460.3 MB/s)
 4#XXH64 unaligned               :     102400 ->     5013 it/s (  489.6 MB/s)
 5#XXH3_64b                      :     102400 ->     3361 it/s (  328.2 MB/s)
 6#XXH3_64b unaligned            :     102400 ->     3317 it/s (  323.9 MB/s)
 7#XXH3_64b w/seed               :     102400 ->     3256 it/s (  317.9 MB/s)
 8#XXH3_64b w/seed unaligned     :     102400 ->     3270 it/s (  319.3 MB/s)
 9#XXH3_64b w/secret             :     102400 ->     2306 it/s (  225.2 MB/s)
10#XXH3_64b w/secret unaligned   :     102400 ->     2332 it/s (  227.7 MB/s)
11#XXH128                        :     102400 ->     3350 it/s (  327.2 MB/s)
12#XXH128 unaligned              :     102400 ->     3314 it/s (  323.6 MB/s)
13#XXH128 w/seed                 :     102400 ->     3397 it/s (  331.7 MB/s)
14#XXH128 w/seed unaligned       :     102400 ->     3362 it/s (  328.3 MB/s)
15#XXH128 w/secret               :     102400 ->     2306 it/s (  225.2 MB/s)
16#XXH128 w/secret unaligned     :     102400 ->     2331 it/s (  227.6 MB/s)
17#XXH32_stream                  :     102400 ->     2357 it/s (  230.2 MB/s)
18#XXH32_stream unaligned        :     102400 ->     2350 it/s (  229.5 MB/s)
19#XXH64_stream                  :     102400 ->     3421 it/s (  334.0 MB/s)
20#XXH64_stream unaligned        :     102400 ->     3360 it/s (  328.1 MB/s)
21#XXH3_stream                   :     102400 ->     2145 it/s (  209.4 MB/s)
22#XXH3_stream unaligned         :     102400 ->     2124 it/s (  207.4 MB/s)
23#XXH3_stream w/seed            :     102400 ->     2143 it/s (  209.3 MB/s)
24#XXH3_stream w/seed unaligned  :     102400 ->     2123 it/s (  207.4 MB/s)
25#XXH128_stream                 :     102400 ->     2144 it/s (  209.4 MB/s)
26#XXH128_stream unaligned       :     102400 ->     2122 it/s (  207.3 MB/s)
27#XXH128_stream w/seed          :     102400 ->     2131 it/s (  208.1 MB/s)
28#XXH128_stream w/seed unaligne :     102400 ->     2112 it/s (  206.2 MB/s)
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
Sample of 100 KB...
 1#XXH32                         :     102400 ->    10740 it/s ( 1048.9 MB/s)
 2#XXH32 unaligned               :     102400 ->     4339 it/s (  423.7 MB/s)
 3#XXH64                         :     102400 ->    14962 it/s ( 1461.2 MB/s)
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
 1#XXH32                         :       1855 ->   570131 it/s ( 1008.6 MB/s)
 3#XXH64                         :       1855 ->   719562 it/s ( 1273.0 MB/s)
 5#XXH3_64b                      :       1855 ->   171493 it/s (  303.4 MB/s)
11#XXH128                        :       1855 ->   166760 it/s (  295.0 MB/s)
623b23d3  xxhash.c
7615c59c2d746e27e873a692555aca2b  xxhash.c
XXH3_e873a692555aca2b  xxhash.c
Wrong parameters

by the way,when I use CFLAGS="-march=rv64gcv -O3 -DXXH_FORCE_MEMORY_ACCESS=0" make check, Performance with -O3 optimization is unexpectedly lower than with -O2.

OK. (passes 49948 tests)
5ffb01494ce73724  stdin
5ffb01494ce73724  xxhash.c
517f15e1d01f6dae  xxhash.h
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
Sample of 100 KB...
 1#XXH32                         :     102400 ->    10669 it/s ( 1041.9 MB/s)
 3#XXH64                         :     102400 ->    14569 it/s ( 1422.7 MB/s)
 5#XXH3_64b                      :     102400 ->     8255 it/s (  806.1 MB/s)
11#XXH128                        :     102400 ->     8347 it/s (  815.1 MB/s)
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
Sample of 100 KB...
 1#XXH32                         :     102400 ->    10715 it/s ( 1046.4 MB/s)
 2#XXH32 unaligned               :     102400 ->     5157 it/s (  503.7 MB/s)
 3#XXH64                         :     102400 ->    14530 it/s ( 1418.9 MB/s)
 4#XXH64 unaligned               :     102400 ->     8788 it/s (  858.2 MB/s)
 5#XXH3_64b                      :     102400 ->     8343 it/s (  814.7 MB/s)
 6#XXH3_64b unaligned            :     102400 ->     8270 it/s (  807.6 MB/s)
 7#XXH3_64b w/seed               :     102400 ->     8300 it/s (  810.5 MB/s)
 8#XXH3_64b w/seed unaligned     :     102400 ->     8231 it/s (  803.8 MB/s)
 9#XXH3_64b w/secret             :     102400 ->     7944 it/s (  775.8 MB/s)
10#XXH3_64b w/secret unaligned   :     102400 ->     7866 it/s (  768.1 MB/s)
11#XXH128                        :     102400 ->     8287 it/s (  809.3 MB/s)
12#XXH128 unaligned              :     102400 ->     8212 it/s (  802.0 MB/s)
13#XXH128 w/seed                 :     102400 ->     8240 it/s (  804.7 MB/s)
14#XXH128 w/seed unaligned       :     102400 ->     8187 it/s (  799.5 MB/s)
15#XXH128 w/secret               :     102400 ->     7884 it/s (  769.9 MB/s)
16#XXH128 w/secret unaligned     :     102400 ->     7820 it/s (  763.6 MB/s)
17#XXH32_stream                  :     102400 ->     2555 it/s (  249.5 MB/s)
18#XXH32_stream unaligned        :     102400 ->     2538 it/s (  247.9 MB/s)
19#XXH64_stream                  :     102400 ->     5106 it/s (  498.7 MB/s)
20#XXH64_stream unaligned        :     102400 ->     4963 it/s (  484.7 MB/s)
21#XXH3_stream                   :     102400 ->     8255 it/s (  806.2 MB/s)
22#XXH3_stream unaligned         :     102400 ->     8184 it/s (  799.2 MB/s)
23#XXH3_stream w/seed            :     102400 ->     8235 it/s (  804.2 MB/s)
24#XXH3_stream w/seed unaligned  :     102400 ->     8171 it/s (  797.9 MB/s)
25#XXH128_stream                 :     102400 ->     8264 it/s (  807.0 MB/s)
26#XXH128_stream unaligned       :     102400 ->     8192 it/s (  800.0 MB/s)
27#XXH128_stream w/seed          :     102400 ->     8249 it/s (  805.5 MB/s)
28#XXH128_stream w/seed unaligne :     102400 ->     8174 it/s (  798.2 MB/s)
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
Sample of 100 KB...
 1#XXH32                         :     102400 ->    10746 it/s ( 1049.4 MB/s)
 2#XXH32 unaligned               :     102400 ->     5157 it/s (  503.6 MB/s)
 3#XXH64                         :     102400 ->    14556 it/s ( 1421.5 MB/s)
xxhsum 0.8.3 by Yann Collet
compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1)
 1#XXH32                         :       1855 ->   573313 it/s ( 1014.2 MB/s)
 3#XXH64                         :       1855 ->   724917 it/s ( 1282.4 MB/s)
 5#XXH3_64b                      :       1855 ->   443729 it/s (  785.0 MB/s)
11#XXH128                        :       1855 ->   426737 it/s (  754.9 MB/s)
623b23d3  xxhash.c
7615c59c2d746e27e873a692555aca2b  xxhash.c
XXH3_e873a692555aca2b  xxhash.c
Wrong parameters

I still find reason about it

This Pull Request aims to build upon the previously closed PR (This Pull Request aims to build upon the previously closed PR (#898) by focusing on optimizing xxHash performance for platforms based on the RISC-V architecture through Vector Extension (RVV) optimizations. ) by focusing on optimizing xxHash performance for platforms based on the RISC-V architecture through Vector Extension (RVV) optimizations.And this PR has pass check on qemu with vlen=128,256,512. For illustration, here are some benchmark numbers, on a Spacemit(R) X60 @1.6 Ghz command line:`CFLAGS="-march=rv64gcv -O2 -DXXH_FORCE_MEMORY_ACCESS=0" make check` ``` OK. (passes 49948 tests) 5ffb01494ce73724 stdin 5ffb01494ce73724 xxhash.c 517f15e1d01f6dae xxhash.h xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) Sample of 100 KB... 1#XXH32 : 102400 -> 10681 it/s ( 1043.1 MB/s) 3#XXH64 : 102400 -> 14610 it/s ( 1426.8 MB/s) 5#XXH3_64b : 102400 -> 9376 it/s ( 915.7 MB/s) 11#XXH128 : 102400 -> 9370 it/s ( 915.1 MB/s) xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) Sample of 100 KB... 1#XXH32 : 102400 -> 10726 it/s ( 1047.4 MB/s) 2#XXH32 unaligned : 102400 -> 5159 it/s ( 503.8 MB/s) 3#XXH64 : 102400 -> 14595 it/s ( 1425.3 MB/s) 4#XXH64 unaligned : 102400 -> 8807 it/s ( 860.1 MB/s) 5#XXH3_64b : 102400 -> 9389 it/s ( 916.9 MB/s) 6#XXH3_64b unaligned : 102400 -> 9304 it/s ( 908.6 MB/s) 7#XXH3_64b w/seed : 102400 -> 9385 it/s ( 916.5 MB/s) 8#XXH3_64b w/seed unaligned : 102400 -> 9306 it/s ( 908.8 MB/s) 9#XXH3_64b w/secret : 102400 -> 8980 it/s ( 876.9 MB/s) 10#XXH3_64b w/secret unaligned : 102400 -> 8913 it/s ( 870.4 MB/s) 11#XXH128 : 102400 -> 9350 it/s ( 913.1 MB/s) 12#XXH128 unaligned : 102400 -> 9254 it/s ( 903.7 MB/s) 13#XXH128 w/seed : 102400 -> 9341 it/s ( 912.2 MB/s) 14#XXH128 w/seed unaligned : 102400 -> 9257 it/s ( 904.0 MB/s) 15#XXH128 w/secret : 102400 -> 8925 it/s ( 871.6 MB/s) 16#XXH128 w/secret unaligned : 102400 -> 8844 it/s ( 863.7 MB/s) 17#XXH32_stream : 102400 -> 2556 it/s ( 249.6 MB/s) 18#XXH32_stream unaligned : 102400 -> 2537 it/s ( 247.8 MB/s) 19#XXH64_stream : 102400 -> 5110 it/s ( 499.0 MB/s) 20#XXH64_stream unaligned : 102400 -> 4960 it/s ( 484.4 MB/s) 21#XXH3_stream : 102400 -> 9250 it/s ( 903.3 MB/s) 22#XXH3_stream unaligned : 102400 -> 9184 it/s ( 896.9 MB/s) 23#XXH3_stream w/seed : 102400 -> 9249 it/s ( 903.3 MB/s) 24#XXH3_stream w/seed unaligned : 102400 -> 9163 it/s ( 894.8 MB/s) 25#XXH128_stream : 102400 -> 9236 it/s ( 902.0 MB/s) 26#XXH128_stream unaligned : 102400 -> 9150 it/s ( 893.5 MB/s) 27#XXH128_stream w/seed : 102400 -> 9215 it/s ( 899.9 MB/s) 28#XXH128_stream w/seed unaligne : 102400 -> 9121 it/s ( 890.7 MB/s) xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) Sample of 100 KB... 1#XXH32 : 102400 -> 10700 it/s ( 1044.9 MB/s) 2#XXH32 unaligned : 102400 -> 5164 it/s ( 504.3 MB/s) 3#XXH64 : 102400 -> 14587 it/s ( 1424.5 MB/s) xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) 1#XXH32 : 1855 -> 569155 it/s ( 1006.9 MB/s) 3#XXH64 : 1855 -> 717551 it/s ( 1269.4 MB/s) 5#XXH3_64b : 1855 -> 494573 it/s ( 874.9 MB/s) 11#XXH128 : 1855 -> 464638 it/s ( 822.0 MB/s) 623b23d3 xxhash.c 7615c59c2d746e27e873a692555aca2b xxhash.c XXH3_e873a692555aca2b xxhash.c Wrong parameters ``` command line:`CFLAGS="-O2 -DXXH_FORCE_MEMORY_ACCESS=0" make check` ``` OK. (passes 49948 tests) 5ffb01494ce73724 stdin 5ffb01494ce73724 xxhash.c 517f15e1d01f6dae xxhash.h xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) Sample of 100 KB... 1#XXH32 : 102400 -> 10664 it/s ( 1041.4 MB/s) 3#XXH64 : 102400 -> 14958 it/s ( 1460.7 MB/s) 5#XXH3_64b : 102400 -> 3326 it/s ( 324.8 MB/s) 11#XXH128 : 102400 -> 3353 it/s ( 327.4 MB/s) xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) Sample of 100 KB... 1#XXH32 : 102400 -> 10733 it/s ( 1048.1 MB/s) 2#XXH32 unaligned : 102400 -> 4332 it/s ( 423.0 MB/s) 3#XXH64 : 102400 -> 14954 it/s ( 1460.3 MB/s) 4#XXH64 unaligned : 102400 -> 5013 it/s ( 489.6 MB/s) 5#XXH3_64b : 102400 -> 3361 it/s ( 328.2 MB/s) 6#XXH3_64b unaligned : 102400 -> 3317 it/s ( 323.9 MB/s) 7#XXH3_64b w/seed : 102400 -> 3256 it/s ( 317.9 MB/s) 8#XXH3_64b w/seed unaligned : 102400 -> 3270 it/s ( 319.3 MB/s) 9#XXH3_64b w/secret : 102400 -> 2306 it/s ( 225.2 MB/s) 10#XXH3_64b w/secret unaligned : 102400 -> 2332 it/s ( 227.7 MB/s) 11#XXH128 : 102400 -> 3350 it/s ( 327.2 MB/s) 12#XXH128 unaligned : 102400 -> 3314 it/s ( 323.6 MB/s) 13#XXH128 w/seed : 102400 -> 3397 it/s ( 331.7 MB/s) 14#XXH128 w/seed unaligned : 102400 -> 3362 it/s ( 328.3 MB/s) 15#XXH128 w/secret : 102400 -> 2306 it/s ( 225.2 MB/s) 16#XXH128 w/secret unaligned : 102400 -> 2331 it/s ( 227.6 MB/s) 17#XXH32_stream : 102400 -> 2357 it/s ( 230.2 MB/s) 18#XXH32_stream unaligned : 102400 -> 2350 it/s ( 229.5 MB/s) 19#XXH64_stream : 102400 -> 3421 it/s ( 334.0 MB/s) 20#XXH64_stream unaligned : 102400 -> 3360 it/s ( 328.1 MB/s) 21#XXH3_stream : 102400 -> 2145 it/s ( 209.4 MB/s) 22#XXH3_stream unaligned : 102400 -> 2124 it/s ( 207.4 MB/s) 23#XXH3_stream w/seed : 102400 -> 2143 it/s ( 209.3 MB/s) 24#XXH3_stream w/seed unaligned : 102400 -> 2123 it/s ( 207.4 MB/s) 25#XXH128_stream : 102400 -> 2144 it/s ( 209.4 MB/s) 26#XXH128_stream unaligned : 102400 -> 2122 it/s ( 207.3 MB/s) 27#XXH128_stream w/seed : 102400 -> 2131 it/s ( 208.1 MB/s) 28#XXH128_stream w/seed unaligne : 102400 -> 2112 it/s ( 206.2 MB/s) xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) Sample of 100 KB... 1#XXH32 : 102400 -> 10740 it/s ( 1048.9 MB/s) 2#XXH32 unaligned : 102400 -> 4339 it/s ( 423.7 MB/s) 3#XXH64 : 102400 -> 14962 it/s ( 1461.2 MB/s) xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) 1#XXH32 : 1855 -> 570131 it/s ( 1008.6 MB/s) 3#XXH64 : 1855 -> 719562 it/s ( 1273.0 MB/s) 5#XXH3_64b : 1855 -> 171493 it/s ( 303.4 MB/s) 11#XXH128 : 1855 -> 166760 it/s ( 295.0 MB/s) 623b23d3 xxhash.c 7615c59c2d746e27e873a692555aca2b xxhash.c XXH3_e873a692555aca2b xxhash.c Wrong parameters ``` by the way,when I use `CFLAGS="-march=rv64gcv -O3 -DXXH_FORCE_MEMORY_ACCESS=0" make check`, Performance with -O3 optimization is unexpectedly lower than with -O2. ``` OK. (passes 49948 tests) 5ffb01494ce73724 stdin 5ffb01494ce73724 xxhash.c 517f15e1d01f6dae xxhash.h xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) Sample of 100 KB... 1#XXH32 : 102400 -> 10669 it/s ( 1041.9 MB/s) 3#XXH64 : 102400 -> 14569 it/s ( 1422.7 MB/s) 5#XXH3_64b : 102400 -> 8255 it/s ( 806.1 MB/s) 11#XXH128 : 102400 -> 8347 it/s ( 815.1 MB/s) xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) Sample of 100 KB... 1#XXH32 : 102400 -> 10715 it/s ( 1046.4 MB/s) 2#XXH32 unaligned : 102400 -> 5157 it/s ( 503.7 MB/s) 3#XXH64 : 102400 -> 14530 it/s ( 1418.9 MB/s) 4#XXH64 unaligned : 102400 -> 8788 it/s ( 858.2 MB/s) 5#XXH3_64b : 102400 -> 8343 it/s ( 814.7 MB/s) 6#XXH3_64b unaligned : 102400 -> 8270 it/s ( 807.6 MB/s) 7#XXH3_64b w/seed : 102400 -> 8300 it/s ( 810.5 MB/s) 8#XXH3_64b w/seed unaligned : 102400 -> 8231 it/s ( 803.8 MB/s) 9#XXH3_64b w/secret : 102400 -> 7944 it/s ( 775.8 MB/s) 10#XXH3_64b w/secret unaligned : 102400 -> 7866 it/s ( 768.1 MB/s) 11#XXH128 : 102400 -> 8287 it/s ( 809.3 MB/s) 12#XXH128 unaligned : 102400 -> 8212 it/s ( 802.0 MB/s) 13#XXH128 w/seed : 102400 -> 8240 it/s ( 804.7 MB/s) 14#XXH128 w/seed unaligned : 102400 -> 8187 it/s ( 799.5 MB/s) 15#XXH128 w/secret : 102400 -> 7884 it/s ( 769.9 MB/s) 16#XXH128 w/secret unaligned : 102400 -> 7820 it/s ( 763.6 MB/s) 17#XXH32_stream : 102400 -> 2555 it/s ( 249.5 MB/s) 18#XXH32_stream unaligned : 102400 -> 2538 it/s ( 247.9 MB/s) 19#XXH64_stream : 102400 -> 5106 it/s ( 498.7 MB/s) 20#XXH64_stream unaligned : 102400 -> 4963 it/s ( 484.7 MB/s) 21#XXH3_stream : 102400 -> 8255 it/s ( 806.2 MB/s) 22#XXH3_stream unaligned : 102400 -> 8184 it/s ( 799.2 MB/s) 23#XXH3_stream w/seed : 102400 -> 8235 it/s ( 804.2 MB/s) 24#XXH3_stream w/seed unaligned : 102400 -> 8171 it/s ( 797.9 MB/s) 25#XXH128_stream : 102400 -> 8264 it/s ( 807.0 MB/s) 26#XXH128_stream unaligned : 102400 -> 8192 it/s ( 800.0 MB/s) 27#XXH128_stream w/seed : 102400 -> 8249 it/s ( 805.5 MB/s) 28#XXH128_stream w/seed unaligne : 102400 -> 8174 it/s ( 798.2 MB/s) xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) Sample of 100 KB... 1#XXH32 : 102400 -> 10746 it/s ( 1049.4 MB/s) 2#XXH32 unaligned : 102400 -> 5157 it/s ( 503.6 MB/s) 3#XXH64 : 102400 -> 14556 it/s ( 1421.5 MB/s) xxhsum 0.8.3 by Yann Collet compiled as 64-bit riscv little endian with GCC 14.2.1 20240801 (openEuler 14.2.1-6.oe2403sp1) 1#XXH32 : 1855 -> 573313 it/s ( 1014.2 MB/s) 3#XXH64 : 1855 -> 724917 it/s ( 1282.4 MB/s) 5#XXH3_64b : 1855 -> 443729 it/s ( 785.0 MB/s) 11#XXH128 : 1855 -> 426737 it/s ( 754.9 MB/s) 623b23d3 xxhash.c 7615c59c2d746e27e873a692555aca2b xxhash.c XXH3_e873a692555aca2b xxhash.c Wrong parameters ``` I still find reason about it
Cyan4973 (Migrated from github.com) approved these changes 2025-06-13 11:46:53 -05:00
Cyan4973 commented 2025-06-13 11:52:58 -05:00 (Migrated from github.com)

by the way,when I use CFLAGS="-march=rv64gcv -O3 -DXXH_FORCE_MEMORY_ACCESS=0" make check, Performance with -O3 optimization is unexpectedly lower than with -O2.

This can indeed happen.

Generally, the main reason is that -O3 tends to bloat the binary size, by generating too many specialized code paths. In a micro benchmark always hitting the same code paths, it's probably a win. But in a real world performance, other factors come in. Larger binary size also means instruction cache get filled more quickly. It can evict other tasks from there. Jumps are larger. etc. The impact on instruction cache, which is often quite small, is likely the main culprit.

If -O2 and -O3 give roughly the same performance, I would recommend -O2.

Problem is, it's difficult to reach this conclusion for all targets simultaneously. It's likely true for some, but not others, that still benefit from -O3. Hence why the default is generally -O3, because it's supposed to generate the fastest binaries, and this is generally true, just not always.

> by the way,when I use `CFLAGS="-march=rv64gcv -O3 -DXXH_FORCE_MEMORY_ACCESS=0" make check`, Performance with -O3 optimization is unexpectedly lower than with -O2. This can indeed happen. Generally, the main reason is that `-O3` tends to bloat the binary size, by generating too many specialized code paths. In a micro benchmark always hitting the same code paths, it's probably a win. But in a real world performance, other factors come in. Larger binary size also means instruction cache get filled more quickly. It can evict other tasks from there. Jumps are larger. etc. The impact on instruction cache, which is often quite small, is likely the main culprit. If `-O2` and `-O3` give roughly the same performance, I would recommend `-O2`. Problem is, it's difficult to reach this conclusion _for all targets simultaneously_. It's likely true for some, but not others, that still benefit from `-O3`. Hence why the default is generally `-O3`, because it's supposed to generate the fastest binaries, and this is generally true, just not always.
zijianli1234 commented 2025-06-14 03:27:25 -05:00 (Migrated from github.com)

I understand now, thank you so much.I noticed that in the AVX2-optimized code path, the optimization level is explicitly set to -O2 using GCC pragmas:

#if XXH_VECTOR == XXH_AVX2 /* AVX2 */ \
  && defined(__GNUC__) && !defined(__clang__) /* GCC, not Clang */ \
  && defined(__OPTIMIZE__) && XXH_SIZE_OPT <= 0 /* respect -O0 and -Os */
#  pragma GCC push_options
#  pragma GCC optimize("-O2")
#endif

Should I also use this approach in my code to resolve the problem?

I understand now, thank you so much.I noticed that in the AVX2-optimized code path, the optimization level is explicitly set to -O2 using GCC pragmas: ``` #if XXH_VECTOR == XXH_AVX2 /* AVX2 */ \ && defined(__GNUC__) && !defined(__clang__) /* GCC, not Clang */ \ && defined(__OPTIMIZE__) && XXH_SIZE_OPT <= 0 /* respect -O0 and -Os */ # pragma GCC push_options # pragma GCC optimize("-O2") #endif ``` Should I also use this approach in my code to resolve the problem?
Cyan4973 commented 2025-06-14 05:42:27 -05:00 (Migrated from github.com)

If you imply that -O2 is always better than -O3 for your RVV code path,
then yes.

This conclusion could be more difficult to reach for RISC-V architecture than for AVX2 ones, due to the wider variety of chip designs. I personally don't know the domain enough to tell if it's always true, or generally true, or just sometimes true.

If you imply that `-O2` is always better than `-O3` for your `RVV` code path, then yes. This conclusion could be more difficult to reach for RISC-V architecture than for `AVX2` ones, due to the wider variety of chip designs. I personally don't know the domain enough to tell if it's always true, or generally true, or just sometimes true.
zijianli1234 commented 2025-06-14 20:30:07 -05:00 (Migrated from github.com)

OK, I understand. I currently only have one RISC-V computer, and the -O2 optimization is better than -O3 on this machine. I think we should only consider whether to set the optimization level to -O2 in the code if more machines show this situation.Therefore, it's best to keep the current code as it is for now.

OK, I understand. I currently only have one RISC-V computer, and the -O2 optimization is better than -O3 on this machine. I think we should only consider whether to set the optimization level to -O2 in the code if more machines show this situation.Therefore, it's best to keep the current code as it is for now.
Cyan4973 (Migrated from github.com) approved these changes 2025-06-14 20:32:06 -05:00
Sign in to join this conversation.
No description provided.