Les membres ayant 30 points peuvent parler sur les canaux annonces, projets et hs du chat.
La shoutbox n'est pas chargée par défaut pour des raisons de performances. Cliquez pour charger.

Forum Casio - Discussions


Index du Forum » Discussions » GCC vs Renesas SHC compiler
Calcloverhk Hors ligne Membre Points: 352 Défis: 10 Message

GCC vs Renesas SHC compiler

Posté le 02/07/2024 22:04

This topic was first mentioned during a discussion between me and Sentaro21 on e-Gadget. From him, the main reason C.Basic is still built under fx-9860G SDK and fxCG miniSDK is that they use Renesas SHC compiler which has better floating-point arithmetic performance than GCC, and he would like to know how the current GCC's emulated FPU library performs to see if it is worth switching.

So months later, after opening a megathread on transition to fxSDK/gint in C.Basic Git reopsitory, I began to work on benchmarks for SH-based calculators, in which Whetstone (floating-point) and Dhrystone (integer) are considered. As such, I requested Sentaro21 for his Dhrystone add-in that was used for Ftune/Ptune and he kindly provided not only this benchmark, but also the Whetstone and 8-queen one.

The adapted Whetstone benchmark was conducted on my fx-9860GII SD SH4 without overclocking, and compiled under fx-9860G SDK+Renesas SHC compiler and fxSDK/gint@dev+GCC 11.1. The results are as follows:

Renesas: 523.83 KWIPS
GCC (-Os, 56504 bytes): 321.95 KWIPS (-38.54%)
GCC (-O3, 57544 bytes): 455.86 KWIPS* (-12.98%)
GCC (-Ofast, 57704 bytes): 456.38 KWIPS* (-12.88%)

Well, the performance of -Os build lags considerably behind that of Renesas . While -O3 and -Ofast builds' results are much closer to the original, their results are invalid as Lephe found they skipped the module 8 of Whetstone test.

Lephenixnoir a écrit :
The -O3 figure (452 Kwhet/s) is probably invalid since its optimization removes module 8 entirely (which is 0.7 second)
One possible cause is that GCC has IEEE 754-compliant fp arithmetic and maybe SDK doesn't. And as far as library functions are concerned different compromises will lead to different speeds, maybe OpenLibm tries harder to be precise and so has slower functions


Benchmark source:
fxSDK/gint project: attached to this post
fx-9860G SDK project: https://pm.matrix.jp/fx-bench2.zip

Fichier joint


Lephenixnoir Hors ligne Administrateur Points: 24432 Défis: 170 Message

Citer : Posté le 02/07/2024 22:11 | #


For extra clarification, there are 3 contributors to performance in each build:

  • The compiler as usual handles optimization, efficient register allocation, instruction selection, etc.
  • The soft-fp library (libgcc in the case of GCC) does basic operations on floating-points numbers (multiplication, comparaison, etc).
  • The math library (OpenLibm in the fxSDK toolchain) does actual math functions from the standard library.

It's highly unlikely that SHC generates better code than GCC. It'd be like throwing away a few decades of compiler research. I've started looking into individual Whetstone modules and the SDK add-in outperforms the GCC add-in consistently, so it doesn't appear to be a case of one outlier operation being extremely bad.

My main suspicion right now is precision—the soft-fp library could be less than perfectly IEEE-754-precise (which libgcc is), and the math library could be less precise than OpenLibm, which is overall quite good.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Lephenixnoir Hors ligne Administrateur Points: 24432 Défis: 170 Message

Citer : Posté le 03/07/2024 09:40 | #


To my surprise, the SuperH build of libgcc still uses a quite old soft-fp library called fp-bit ; it is documented to be rather slow and many targets have been moved to a more recent implementation tersely called "soft-fp" which is from the glibc project (and purported to give speedups in the 15-30% range). These efforts have been ongoing for at least 10 years now.

I think it would be a good idea to try and build the "soft-fp" library in libgcc to see if we can make it work and how much that improves performance. The starting point is the sh case of libgcc/config.host using the t-make file t-fdpbit.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Lephenixnoir Hors ligne Administrateur Points: 24432 Défis: 170 Message

Citer : Posté le 03/07/2024 10:53 | #


I was able to make a build of libgcc that uses the "soft-fp" library. For context, this is something that, if we validate works, will be changed in the fxSDK and distributed automatically to everyone with the next GCC update in the fxSDK.

I haven't really tested whether the computations work yet apart from a single test I added that squaring √2 gives the expected result.

With this version (development GCC 15.0 with "soft-fp" in libgcc), the benchmark finishes in 0.950s (1052 Kwhet/s) at -O2.

Now that's more like it. x)
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Calcloverhk Hors ligne Membre Points: 352 Défis: 10 Message

Citer : Posté le 03/07/2024 16:08 | #


Can confirm the results with soft-fp library: the time needed is now reduced to 1.24s (806 KWIPS) for -Os and 0.929s (1076 KWIPS) for -O2 👍
C.Basic Wiki Project progress as of 2024/2/12
   30%


Lephenixnoir Hors ligne Administrateur Points: 24432 Défis: 170 Message

Citer : Posté le 03/07/2024 19:53 | #


I also tested by graphing some trigo curves and it seems to be working as intended.

I will check a game or two that uses floating-point and then add this change to a GCC 14 build for the next version of the fxSDK.

I assume these performance results are satisfactory for a potential port of C.Basic? :3
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Calcloverhk Hors ligne Membre Points: 352 Défis: 10 Message

Citer : Posté le 03/07/2024 20:08 | #


Most likely

Sentaro21 a écrit :
GCC's integer mode performance has been high for some time, but if the latest version of the floating-point emulator library is better than Renesas' library, it is worth switching.

C.Basic Wiki Project progress as of 2024/2/12
   30%


Lephenixnoir Hors ligne Administrateur Points: 24432 Défis: 170 Message

Citer : Posté le 03/07/2024 20:10 | #


I forgot to mention but you can build SDK-like add-ins (with no gint) using GCC, you should probably start there
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Calcloverhk Hors ligne Membre Points: 352 Défis: 10 Message

Citer : Posté le 03/07/2024 20:23 | #


Ah, then the build test could be much easier, but what else should I add to let GCC compile it?
C.Basic Wiki Project progress as of 2024/2/12
   30%


Lephenixnoir Hors ligne Administrateur Points: 24432 Défis: 170 Message

Citer : Posté le 03/07/2024 20:26 | #


This file: https://www.planet-casio.com/storage/forums/bin-12970.zip
Contains crt0.s, which is the initialization code (replaces the init code in your main file ; you should also rename AddIn_main() into main()), the fxlib, and a linker script.

You can compile your project with a Makefile of your own. Since you'll be linking with fxlib you should compile with -mrenesas otherwise variadic-argument functions like printf() will break down. You can use the linker script with -T addin.ld when linking.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Calcloverhk Hors ligne Membre Points: 352 Défis: 10 Message

Citer : Posté le 03/07/2024 21:34 | # | Fichier joint


Ported the Dhrystone benchmark. Here's the results:

Format: <x1 score>,<x80 score>
Renesas: 32320 Dhry/s, 2820 Dhry/s
GCC -Os: 35080 Dhry/s, 29263 Dhry/s
GCC -O2: 37758 Dhry/s, 37187 Dhry/s
GCC -O3: 38139 Dhry/s, 37578 Dhry/s

Sentaro21 a écrit :
The two Dhrystones are tests with and without the cache enabled.
(The second one takes a little time)


I'm kind of surprised about the GCC's x80 scores, which far outperform Renesas' compiler under every optimization flag.
Uploaded my updated gint benchmark
C.Basic Wiki Project progress as of 2024/2/12
   30%


Calcloverhk Hors ligne Membre Points: 352 Défis: 10 Message

Citer : Posté le 04/07/2024 07:28 | # | Fichier joint


The 8-queen benchmark results are out:

Format: <8q>, <8q_un>, <8q_asm>
Renesas: 3193ms, 2712ms, 1355ms
GCC -Os: 3321ms, 2839ms, X
GCC -O2: 2987ms, 2656ms, X
GCC -O3: 2839ms, 2702ms, X

8q_asm test is unavailable in GCC as the original asm file is only for fx-9860G SDK, and its ported .s counterpart caused the add-in to crash.

Also, I noticed performance drop on Dhrystone test after including the 8-queen benchmark:
(Edit: Updated x80 score)
GCC -Os: 32512 Dhry/s, 4838 Dhry/s
GCC -O2: 34822 Dhry/s, 4505 Dhry/s
GCC -O3: 35118 Dhry/s, 4487 Dhry/s

So I seperated 8-queen benchmark and the results indicate increase in performance for -Os:
GCC -Os: 2991ms, 2784ms, X
GCC -O2: 3003ms, 2667ms, X
GCC -O3: 2882ms, 2785ms, X

I also did the Dhrystone test alone but the results were consistent with the ones in the last reply. Not too sure why the 8-queen source affects the previous benchmarks.
C.Basic Wiki Project progress as of 2024/2/12
   30%


Calcloverhk Hors ligne Membre Points: 352 Défis: 10 Message

Citer : Posté le 04/07/2024 07:59 | # | Fichier joint


A quick update from Sentaro21:
Sentaro21 a écrit :
@CalcLoverHK
Thanks for the quick work.()

I didn't know GCC's FPU emulator was that old.
Now I see nothing wrong with moving the development environment to GCC based.

GCC's integer arithmetic performance remains very impressive.

As for the x80 code, it is simply connecting 80 times the source, so you need to make sure that the second and subsequent sources are not removed by the optimization.
SHC did not optimize that much, but we will need to do some work to prevent GCC optimization.


The code to prevent GCC optimization would be:
#pragma GCC push_options
#pragma GCC optimize ("O0")
...
#pragma GCC pop_options


Updated the above Dhrystone test results and benchmark add-in.
C.Basic Wiki Project progress as of 2024/2/12
   30%


Lephenixnoir Hors ligne Administrateur Points: 24432 Défis: 170 Message

Citer : Posté le 04/07/2024 08:33 | #


Setting -O0 via a pragma is way too much, it will inhibit all optimizations. -O0 code is just plain garbage, that's not something you'd ever consider performance measurements for. It is sufficient instead to sink an output of the test into a volatile variable so that GCC keeps all the iterations.

I am interested in maintaining these benchmarks as part of gintctl so I can keep an eye on them over time. Is there a specific license attached to libbench?
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Calcloverhk Hors ligne Membre Points: 352 Défis: 10 Message

Citer : Posté le 04/07/2024 09:15 | #


Lephenixnoir a écrit :
I am interested in maintaining these benchmarks as part of gintctl so I can keep an eye on them over time. Is there a specific license attached to libbench?


Oh, I forgot about this one. libbench is licensed under GPLv2 or later as of now, though I have to confirm the license of fxbench2 with Sentaro21 before uploading it to Git.
C.Basic Wiki Project progress as of 2024/2/12
   30%


Sentaro21 Hors ligne Membre Points: 878 Défis: 0 Message

Citer : Posté le 05/07/2024 06:56 | #


@Lephenixnoir
Thanks for your quick and precise support.

@Calcloverhk
Thanks again.
You are our main development member for the upcoming GCC-based port.

I am looking forward to seeing the FPU emulator library issues resolved and how much performance can be improved by porting to GCC.
If it will be optimized for SH4 as well as SH3, we can expect further performance increase.
Je continue à développer C.Basic. (Il est compatible avec Basic Casio.)
Overclocking utilitaire Ftune/Ptune2/Ptune3 est également disponible.
Si vous avez des questions ou un rapport de bogue, n'hésitez pas à me le faire savoir.

LienAjouter une imageAjouter une vidéoAjouter un lien vers un profilAjouter du codeCiterAjouter un spoiler(texte affichable/masquable par un clic)Ajouter une barre de progressionItaliqueGrasSoulignéAfficher du texte barréCentréJustifiéPlus petitPlus grandPlus de smileys !
Cliquez pour épingler Cliquez pour détacher Cliquez pour fermer
Alignement de l'image: Redimensionnement de l'image (en pixel):
Afficher la liste des membres
:bow: :cool: :good: :love: ^^
:omg: :fusil: :aie: :argh: :mdr:
:boulet2: :thx: :champ: :whistle: :bounce:
valider
 :)  ;)  :D  :p
 :lol:  8)  :(  :@
 0_0  :oops:  :grr:  :E
 :O  :sry:  :mmm:  :waza:
 :'(  :here:  ^^  >:)

Σ π θ ± α β γ δ Δ σ λ
Veuillez donner la réponse en chiffre
Vous devez activer le Javascript dans votre navigateur pour pouvoir valider ce formulaire.

Si vous n'avez pas volontairement désactivé cette fonctionnalité de votre navigateur, il s'agit probablement d'un bug : contactez l'équipe de Planète Casio.

Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2024 | Il y a 243 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements

Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd