This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: code optimizations


>>>>> Dan Conti writes:

> By the way, there's another slight benefit to your method in terms of
> performance. Chances are when you're talking to a peripheral it wont
> matter, but on some of the boards i've worked with (which have 0 wait
> state peripherals but 4 wait state ram), the extra load for the pointer
> in the case of:

> #define foo 0x7ffe1110

> *(volatile unsigned int*)foo = 0xabc;

> can be painful. :)

Why is there an extra load? I would think that using compile time
constants would allow for more optimizations than link time fixups.
Assume mips like architecture, you either have something like:

   ori r2, r0, 0xabc
   lui r1, %hi(foo)
   sw  r2, %lo(foo)(r1)

or

   ori r2, r0, 0xabc
   lui r1, 0x7ffe
   sw  r2, 0x1110(r1)

Both are equal in size and running time. Better optimization is
possible with constants if you do a series of stores to different
addresses. Lets say foo1 is 0x7ffe1114. Then you'd have:

   ori r2, r0, 0xabc
   lui r1, %hi(foo)
   sw  r2, %lo(foo)(r1)
   lui r1, %hi(foo1)
   sw  r2, %lo(foo1)(r1)

or

   ori r2, r0, 0xabc
   lui r1, 0x7ffe
   sw  r2, 0x1110(r1)
   sw  r2, 0x1114(r1)

Here, using compile time constants saved you an insn.

--Mark


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]