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 » Fri Jan 29, 2016 2:23 pm

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: 1127
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Re: C optimizations

Post by KanedaFr » Sat Jan 30, 2016 10:09 pm

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: 2976
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: C optimizations

Post by Stef » Sun Jan 31, 2016 12:54 pm

Of course, that kind of optimization always help the compiler :)

tryphon
Very interested
Posts: 303
Joined: Sat Aug 17, 2013 9:38 pm
Location: France

Re: C optimizations

Post by tryphon » Thu Feb 25, 2016 1:15 pm

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: 2976
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: C optimizations

Post by Stef » Fri Feb 26, 2016 1:00 pm

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
Interested
Posts: 43
Joined: Tue Dec 24, 2013 1:00 am

Re: C optimizations

Post by ehaliewicz » Wed Mar 02, 2016 9:13 pm

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