C optimizations

SGDK only sub forum

Moderator: Stef

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Re: C optimizations

Post by r57shell »

tryphon wrote:In fact, no. Until recently, I didn't even know these tools exist, and since, I don't really see how they help.
Code profiler providing info how long takes execution of each part of your program. In result, if something does spent most of CPU time, it means that it's your program bottleneck. If you speed up this part of code, your program will increase speed very much.
Image
KanedaFr
Administrateur
Posts: 1154
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Re: C optimizations

Post by KanedaFr »

what about the array vs pointer optimization ?
and limit loop using several test per loop, not only one ?
more on http://www.linuxjournal.com/article/2622?page=0,1

is it valuable on this gcc version ?
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: C optimizations

Post by Stef »

Of course, that kind of optimization always help the compiler :)
tryphon
Very interested
Posts: 316
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: C optimizations

Post by tryphon »

Some things I noticed reading disassemblies.

When I do a multiplication :

Code: Select all

	pos = tile*4;
I get :

Code: Select all

	move.w	10(a6), d2	;     pos = tile*4;

	lsl.l	#2, d2
	and.l	#0xFFFC, d2
Why is that ? shouldn't be the 2 lowest bits cleared adter a lsl ? (not that it really slows down things)
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: C optimizations

Post by Stef »

I guess it does that because you are using a 16 bit type ? still it shows the poor code generation of GCC here, if you really use 16 bit type it should then use "lsl.w" instruction instead (and so the and operation become useless)
ehaliewicz
Very interested
Posts: 50
Joined: Tue Dec 24, 2013 1:00 am

Re: C optimizations

Post by ehaliewicz »

cero wrote:OP: Port the cpu-heavy parts to your host machine and profile there, with the superior tools available.
You'll want to be careful with this idea. Modern CPUs are very different from something like the 68k, and what works well on one might not work well on another.
Post Reply