InvestorsHub Logo
icon url

dacaw

11/02/04 12:25 PM

#46776 RE: mmoy #46775

Loop alignment

In the assembler code of the rc4 the main loop has the label .Lstart

The top of this loop must be aligned on a natural boundary, preferably on a cache line boundary - 32 bytes. There should be an ALIGN directive. Note that the whole function is aligned at 16 bytes, this is pointless as far as I can see (compared to the main loop that is executed hundreds of times).

If the top of the loop is not aligned this will interfere with decoding and may reduce cache efficiency. The final stage of any really time-critical code is seeing where the code boundaries are.

Unless the code is specified to be on a certain boundary you have no idea where it will locate so the first run may be really, really fast then the second run slows right down. This is so common when code is being tested, the addition of a single, seemingly inconsequential, instruction can make or break the runtime. Often its the debug instructions themselves and when they are taken out the code is nowhere near as fast!