Regarding shifting, it is particularly important to avoid
shifting by a
variable amount - shifting by known constants is not nearly
as time
consuming.
I take it you are compiling with fairly heavy optimisations
enabled.
Generate assembly listings of the output and experiment with
different
compiler flags to see what gives the best results. You
should probably aim
to get the inner loop unrolled, and you also want to check
that the compiler
is assuming there is no aliasing between your different
arrays.
Use ints (or unsigned ints) for your local variables - this
is often faster.
Of course, this is assuming you've thought through your
algorithm and found
it to be the best method you can find.
mvh.,
David
> 1. Don't bother resetting the array values to zero,
you're going to set
> them to their final value anyway..
> 2. Use a translation table instead of shifting bits.
> 3. Generate a new translation table internally, in the
program, whenever
> the mapping information changes (for example, during
initialization, if
> the mapping doesn't change during the run).
>
> Jens Bürger (sent by Nabble.com) wrote:
>
> >Hello,
> >I have a student research project about code and
speed optimisation for a
> >MCF5282.
> >The topic is to map an input data field (128Byte)
to an output data field
> >(128Byte). The content of both fields is the same,
only the bitpositions
can
> >vary. The problem is that we can't initialise a
constant mapping, because
> >the information how to map can change.
> >Here is the recent source code for this problem.
> >
> >void HW_Configuration(void)
> > {
> > BYTE i, j;
> > BYTE Value = 0;
> > BYTE
ByteArray[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
> >
> > /* RESET ARRAY */
> > for (i=0; i<128; i++)
> > {
> > Hw_Config.abHWConfCubeOutputData[i] = 0;
> > }
> >
> > /* BYTE BY BYTE EXCHANGE */
> > for (i=0; i<128; i++)
> > {
> > for (j=0; j<8; j++)
> > {
> > /* get the bit value */
> > Value = abCubeInputData[i] &
ByteArray[j];
> >
> > /* number of the new bit position */
> > if (Hw_Config.InputDesc[i].BitNum[j] == j)
> > {
> > /* do nothing */
> > asm("nop");
> > }
> > else if (Hw_Config.InputDesc[i].BitNum[j]
> j)
> > {
> > /* shift left */
> > Value <<=
Hw_Config.InputDesc[i].BitNum[j];
> > }
> > else if (Hw_Config.InputDesc[i].BitNum[j]
< j)
> > {
> > /* shift right */
> > Value >>=
Hw_Config.InputDesc[i].BitNum[j];
> > }
> > /* Build the byte bitwise */
> >
Hw_Config.abHWConfCubeOutputData[Hw_Config.InputDesc[i].Byte
Num] |=
> >Value;
> > }
> > }
> >}
> >/* end of file */
> >
> >This code need 2.5ms and the goal is around 1.4ms.
> >I think that there are not so much things to
optimise in the source code.
> >But I would be glad about every kind of help. I
could imagine to modify
the
> >Compiler (I use the GCC), but I need more
Informations. Or if any one
knows
> >some good weblinks for this kind of problem, please
let me know.
> >
> >Best regards
> >Jens
> >--
> >View this message in context:
http://www.nabble.com/Speed-optimisation-
MCF5282-t1411362.html#a3801386
> >Sent from the Coldfire forum at Nabble.com.
> >
>
>--------------------------------------------------------
------------
> >To Subscribe send a message to:
ColdFire-On Lists.Wildrice.com
> >To Unsubscribe send a message to:
ColdFire-Off Lists.Wildrice.com
> >For further information, visit: <http://www.Wild
Rice.com/ColdFire/>
> >
> >
> >
> >
> >
>
> --
> Paul Wujek, Director, Network Software,
> Embedded Sense Inc., 2145 Meadowpine Blvd.,
Mississauga, Ontario, Canada,
L5N 6R8.
>
>
------------------------------------------------------------
--------
> To Subscribe send a message to: ColdFire-On Lists.Wildrice.com
> To Unsubscribe send a message to: ColdFire-Off Lists.Wildrice.com
> For further information, visit: <http://www.Wild
Rice.com/ColdFire/>
>
>
>
------------------------------------------------------------
--------
To Subscribe send a message to: ColdFire-On Lists.Wildrice.com
To Unsubscribe send a message to: ColdFire-Off Lists.Wildrice.com
For further information, visit: <http://www.Wild
Rice.com/ColdFire/>
|