This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: An article I alluded to
- From: Ian Lance Taylor <iant at google dot com>
- To: "Bill McEnaney" <bill at rkirkpat dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 26 Jul 2006 22:54:26 -0700
- Subject: Re: An article I alluded to
- References: <20060727030600.EF4DF71A01@saratoga.rkirkpat.net>
"Bill McEnaney" <bill@rkirkpat.net> writes:
> In another e-mail, I told you about an article that said that the
> computer can access static variables faster than it can access automatic
> variables. So here's a link to that article.
>
> http://www.numerix-dsp.com/appsnotes/c_coding.html
That article is very specific to DSPs. I've seen DSPs in which there
is a limited range of memory, so that a load can be done from an
arbitrary memory address in a single instruction, and there is also no
register offset memory addressing. Under those conditions, it is
indeed more efficient to use a static variable than to use an
automatic variable.
However, any ordinary processor has register offset memory addressing,
and on most RISC processors you can not load from an arbitrary memory
address in a single instruction (although you can on x86). So in
these normal conditions, automatic variables will be faster.
The article is wrong to suggest using the "register" declaration, as
it is universally ignored by optimizing compilers. Similarly with the
advice about reusing local variables.
I didn't see any other obvious errors.
Ian