C++ on the MD
Moderator: Mask of Destiny
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
C++ on the MD
I just made a C++ example for the MD using my new toolchain (see the thread in the tools forum). It's a simple Tic-Tac-Toe game, but demonstrates a basic C++ project on the MD. The archive contains a binary as well as the source and an updated linker script for the toolchain.
The game itself is very simple: two players take turns using pad 0 to enter X or O to a spot selected using the DPAD when A is pressed. Press C to exit. After a tie or win, the game restarts.
It's nothing special, it's just a skeleton on which to base your own project.
TicTacToe-MD-Example.7z
The game itself is very simple: two players take turns using pad 0 to enter X or O to a spot selected using the DPAD when A is pressed. Press C to exit. After a tie or win, the game restarts.
It's nothing special, it's just a skeleton on which to base your own project.
TicTacToe-MD-Example.7z
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
I probably should dump main.o to see how the code looks, but I'm willing to bet it's not any better than the corresponding C would be. I'll convert this example into a C one just to be sure. Basically, I want to make a C and C++ version of this for the MD and the 32X to serve as basic skeleton code for the toolchain. Then maybe work in some more complete examples and support for more stuff to make a complete SDK for the MD/32X.
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
I added -fomit-frame-pointers to the C++ makefile to make it more directly comparable to the C code. Here's the dump of the same program as C and C++ compiled at the same level with comparable options:
http://www.mediafire.com/download.php?0eevuz7yeb6e4e1
You'll notice they are virtually identical... just as I figured they would be. While C++ has gotten better, so has the regular C compiler. The main difference people may see between the two is C++ does inlining by default unless you tell it not to, while C only does inlining when you specifically tell it to.
http://www.mediafire.com/download.php?0eevuz7yeb6e4e1
You'll notice they are virtually identical... just as I figured they would be. While C++ has gotten better, so has the regular C compiler. The main difference people may see between the two is C++ does inlining by default unless you tell it not to, while C only does inlining when you specifically tell it to.
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Thanks for testing it !
Well, i guess that guys which were reporting that C++ does better optimisation didn't enabled all optimisations on C compiler.
By the way, does -O1 imply the function inlining ? I remember i never saw any inlining in my generated code and i'm using GCC 3.6.x with -O1 optimisation level (-O2 or greater produce worst code).
Well, i guess that guys which were reporting that C++ does better optimisation didn't enabled all optimisations on C compiler.
By the way, does -O1 imply the function inlining ? I remember i never saw any inlining in my generated code and i'm using GCC 3.6.x with -O1 optimisation level (-O2 or greater produce worst code).
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
On certain platforms at least, it does - I noticed that with dumps I did the other day of disk_io.c for the 68000: -O1 used jsr to the functions, while -O2 made them inline. This is on NEW gcc - 4.1.1 did not inline code at -O2.Stef wrote:Thanks for testing it !
Well, i guess that guys which were reporting that C++ does better optimisation didn't enabled all optimisations on C compiler.
By the way, does -O1 imply the function inlining ? I remember i never saw any inlining in my generated code and i'm using GCC 3.6.x with -O1 optimisation level (-O2 or greater produce worst code).
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
I guess it only inlines small functions... I wonder if there is a specific switch with my GCC version to enable this optimization, it can bring a nice speed boost in some particular cases (we can always do it by hand by the way but registers usage is probably not as good than what compiler can do by itself).
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
Here's the documentation for the current version of GCC. The inlining thresholds has been tweaked back and forth over the years in order to balance performance and space requirements, and there's a couple of command-line parameters you can tweak if you want to.
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
That will be handy to folks working on their own projects. I don't know what half of them do.antime wrote:Here's the documentation for the current version of GCC. The inlining thresholds has been tweaked back and forth over the years in order to balance performance and space requirements, and there's a couple of command-line parameters you can tweak if you want to.