Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Re: arrays & pointers

Re: arrays & pointers

From: Greg Haerr <greg_at_censoft.com>
Date: 2005-01-31

> DIR* pdir = opendirs;
> for ( dd=0; dd<MAX_OPEN_DIRS; dd++, pdir++)
> if ( !pdir->busy )
> break;

Since we're on the subject of generated code efficiency, I just
had to jump in... A couple more comments:

1. With the pdir declaration above, since it's only
used in the single for() statement, it's initialization should be
delayed until within the first expression of the for statement.
In this way, the compiler may be able to optimize its use
to a register, and delay an unneeded store/load combo
if there's code inbetween the declaration and for statement
(which there is).

2. Although some think my next comment a matter of style,
too many compilers emit different code: dd++ vs ++dd.
If ++dd is coded, and the processor has an increment
memory opcode, this will always be emitted. If dd++
is coded, and the compiler's optimization is enabled,
this usually also happens, but otherwise a load/add 1/store
is emitted, which is slower and longer.

3. A lesser known evil: not declaring int as 'unsigned int'
when the variable is ever used in a shift, modulo, divide,
or pointer offset. For instance, there is a huge difference
in the code generated by gcc for the following seemingly
innocuous use of variable i as "int" vs "unsigned int":

    f(i>>3);
    a[i / 2]
etc.
If the var is not unsigned, gcc must sign extend and other
madness before emitting more code. When I contributed
the font code a few years back, I looked over all of it,
but haven't taken another look lately for this big byte-saving
fix.

Regards,

Greg

_______________________________________________
http://cool.haxx.se/mailman/listinfo/rockbox
Received on Mon Jan 31 00:06:09 2005


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