This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Writing Efficient C for ARM


Writing Efficient C for ARM

Postby Digby » Dec 26, 2001 @ 9:11pm

I recently came across on ARM's website. While it strictly deals with optimization techniques using the ARM C compiler, some things do carry over to the Microsoft ARM C compiler provided with eVC. I haven't got around to testing some of the topics covered in the article and looking at the resulting assembly language output from the MS compiler. Perhaps one of you lads with tons of time on your hands can do this and share your findings? Anyway, it makes good bathroom reading if nothing else.<br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Writing Efficient C for ARM

Postby Dan East » Dec 27, 2001 @ 4:40am

Last edited by Dan East on Dec 3, 2004 @ 3:00pm, edited 4 times in total.
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Re: Writing Efficient C for ARM

Postby Digby » Dec 27, 2001 @ 5:16pm

Man, you're quite the typist there Dan. Just a reminder that those things are only known to be valid for the ARM C compiler - not the ARM compiler provided with the Microsoft Embedded Visual Tools SDK (clarm.exe).<br><br>There's also a whitepaper up on the ARM site regarding fixed-point math.  This is probably old hat for someone like yourself, but others might be interested.  Here's the link:<br><br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Writing Efficient C for ARM

Postby Mole » Jan 3, 2002 @ 1:26pm

Please, Please don't rely on eVC to compile efficient code, because it won't!!!. apart from the natural speed of the ARM it has some very good features that the compiler just don't use :(, (see assem thread that i started), all instructions can be conditional (not just branches) depending on the outcome of the previous instruction e.g.<br><br>a=a-b<br>if (a<0)<br>{c=0;}<br>else<br>{c=100;}<br><br>can be represented in assembler...<br>r0=a;<br>r1=b;<br>r2=c;<br><br>subs r2,r0,r1<br>movmi r2,#0;<br>movpl r2,#100;<br><br>3 instructions!!!!!!!!<br>evc will push/pull all the vars off/on the stack, then use a CMP instruction for the compare!!!<br><br>Dan,<br>send me a complex and bottleneck function from ur q2 source code and i will show you the differnec hand compilation can make (i bet 3-5 times quicker)<br>but forget pushing ur C code about to get better performance, because eVC just don't compile efficent ARM code<br>Last modification: Mole - 01/03/02 at 10:26:49
Must go faster
Mole
pm Member
 
Posts: 10
Joined: Dec 11, 2001 @ 10:36am


Re: Writing Efficient C for ARM

Postby Phantom » Jan 3, 2002 @ 2:42pm

EVC indeed messes up in a major fashion, but sadly, things that I typically used to turn into asm on the x86 are compiled just fine. I have this huge matrix / vector multiplication that compiles to 'optimal' code. I agree that the case you mentioned can be done much faster, but that's also code that I would rarely turn into hand-optimized asm. :)<br><br>One other thing that I noticed: When I compile with maximum optimizations, the resulting .asm file doesn't compile. It only works without optimizations. That could also explain the bad compiles you mentioned.
Give me some good data and
I will give you the world
User avatar
Phantom
pm Insider
 
Posts: 913
Joined: Feb 21, 2001 @ 8:14am
Location: Houten, Netherlands


Re: Writing Efficient C for ARM

Postby Digby » Jan 4, 2002 @ 12:14am

Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Writing Efficient C for ARM

Postby BadBazza » Jan 4, 2002 @ 6:26am

Lost....... Assumed Coding!
User avatar
BadBazza
pm Insider
 
Posts: 81
Joined: Sep 21, 2001 @ 6:26am
Location: Blackpool, UK


Re: Writing Efficient C for ARM

Postby Dan East » Jan 4, 2002 @ 10:02am

See the thread <br><br>Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Re: Writing Efficient C for ARM

Postby BadBazza » Jan 4, 2002 @ 10:06am

Thanks again Dan,<br><br>I did look at that thread but thought I would need a basic understanding before progressing to these documents.<br><br>Cheers<br>Bad<br><br>
Lost....... Assumed Coding!
User avatar
BadBazza
pm Insider
 
Posts: 81
Joined: Sep 21, 2001 @ 6:26am
Location: Blackpool, UK


Postby Dan East » Dec 2, 2004 @ 3:48pm

User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Postby Structure » Dec 2, 2004 @ 5:47pm

Sticky !!
User avatar
Structure
pm Member
 
Posts: 147
Joined: Sep 17, 2004 @ 8:28pm
Location: UK


Postby Crayfish » Dec 3, 2004 @ 11:06am

User avatar
Crayfish
pm Member
 
Posts: 41
Joined: Oct 1, 2004 @ 11:19am
Location: Lowestoft, UK


Postby bitbank » Dec 8, 2004 @ 4:18am

Allow me to add a few choice words to this discussion...

I've found that no matter how good the compiler is (and the eVC++ one is not great), the C language does not allow you to specify things which will use all of the capabilities of the target CPU. Depending on the application, good old hand-written assembly language can usually get you 2-3X the performance of C code. It certainly is a good idea to create clean C code for the compiler and I've got two good suggestions for speeding things up:

1) The ARM CPU does not do well with global (static) variables because it can only use register-indirect addressing. Keep statics in structures with a variable pointing to the structure.

2) Looping can be done a lot quicker if a loop variable is avoided. e.g.

Slow way:
s = <source pointer>
d = <destination pointer>
for (i=0; i<count; i++)
{
*d++ = *s++;
}

Fast way:
s = <source pointer>
d = <destination pointer>
pEnd = &d[count]

while (d < pEnd)
{
*d++ = *s++;
}

Enjoy,
Larry B.
bitbank
pm Member
 
Posts: 12
Joined: Dec 8, 2004 @ 4:13am
Location: South Florida


Postby fdave » Jul 11, 2005 @ 8:34pm

User avatar
fdave
pm Member
 
Posts: 44
Joined: Apr 12, 2004 @ 10:01pm


Postby frasse » Oct 6, 2005 @ 1:03am

<a href="http://fixerfrasse.blogspot.com">blog</a>
User avatar
frasse
pm Member
 
Posts: 12
Joined: Oct 3, 2005 @ 8:13pm


Next

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron