Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: GCC - locals performance

2005-12-14 by brendanmurphy37

Hi,

The short answer is that it is impossible to say what either version 
does without looking at the assembler output from the compiler at 
the particular optimisation level you are using.

For example, at anything other than no optimisation, there's a fair 
chance no stack space will be used in either version, as the 
variables can be kept in registers.

At high optimisation levels, for anything other than very trivial 
functions, you'll have a tough time following what's going on. GCC 
does a pretty good job of optimisation, but the cost is that it is 
difficult to relate back to the source.

As a (very) general rule, unless there's some specific (usually 
space saving) requirement, on most processors and most compilers, 
using "int" or "unsigned int" will give the most efficient results. 
However, there's so many exceptions to this (e.g. int size of 32-
bits reading/writing across a 16-bit bus) that it's almost not worth 
bothering with.

By far the most important point I'd make is: "why do you care?". 
Unless the function in question is in the innermost part of a loop 
executed very many times, or is part of a very high frequency 
interrupt handler, I'd be willing to guess it has no effect on your 
system's performance. 

Brendan

--- In lpc2000@yahoogroups.com, "xjag74" <detlef.weidner@w...> wrote:
>
> Hi,
> 
> I wonder which kind of implementation well be performed faster 
using 
> GCC:
> 
> void functionname(void)
> {
>   unsigned char x=0;
>   unsigned char y=1;
>   unsigned char z=2;
> 
>   ...Do something with x,y and z.
> }
> 
> or
> 
> void functionname(void)
> {
>   unsigned long x=0;
>   unsigned long y=1;
>   unsigned long z=2;
> 
>   ...Do something with x,y and z.
> }
> 
> 
> The first example uses less stack, but it takes a longer time for 
> initialization when calling the function cause the 8 bit have to 
be 
> masked out.
> Am I right with that supposition?
> 
> regards
> xjag
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.