dev builds
themes manual
device status forums
mailing lists
IRC bugs
dev guide

Rockbox mail archive

Subject: Re: arrays & pointers

Re: arrays & pointers

From: Nix <>
Date: 2005-02-06

On Sat, 29 Jan 2005, Björn Stenberg uttered the following:
> /* find a free dir descriptor */
> for ( dd=0; dd<MAX_OPEN_DIRS; dd++ )
> if ( !opendirs[dd].busy )
> break;
> into this:
> DIR* pdir = opendirs;
> /* find a free dir descriptor */
> for ( dd=0; dd<MAX_OPEN_DIRS; dd++, pdir++)
> if ( !pdir->busy )
> break;
> It does this in a couple of places, which all in all gives roughly 250
> bytes shorter code.

What I think is happening (I'd need to see the assembler or RTL output
to be sure) is that you're eliminating some arithmetic. Every array
dereference is decaying into


while the second doesn't need that addition.

(I'd have expected GCC to spot most of this and prove that the dd's must
have unchanging values, and move the pointer arithmetic a long way up,
but possibly the appropriate optimization wasn't present in the GCC
version you're using, or was buggy. Full value range propagation is
needed to do this in many cases, and GCC can't do that at all before GCC

-Os will tend to make GCC look harder for things like this.

(This is not the same as the problem BlueChip had, in which he was doing
a different number of pointer indirections when using arrays from when
using pointers.)

`anybody who quotes Russ [Allbery] can be forgiven almost anything!'
                                                  -- Stephen J. Turnbull
Received on Sun Feb 6 14:35:43 2005

Page was last modified "Jan 10 2012" The Rockbox Crew