Share via


Implementing the Optimization Function (Windows Embedded CE 6.0)

1/6/2010

For every generated function, the optimization function executes fewer times than specified by GENBLT_OPTIMIZE_LEVELS. The default value for GENBLT_OPTIMIZE_LEVELS is four. Each time the optimization function executes, the optimization function is passed an integer that indicates which pass the optimization function is executing. The following code example shows the definition for the optimization function.

typedef BOOL (*PFN_CpuOptimize)(int FnIndex, void * pMCode, DWORD Level);

In general, the optimization functions can perform any optimization task. An optimization pass is guaranteed to be completed before the next optimization pass begins.

Choosing the correct point to perform an optimization requires profiling. If optimization passes are executed too close together, the optimization might result in overall performance degradation. This is likely to occur if the function being optimized is flushed from the blit cache before the optimization cost has been amortized. The number of blits separating optimization passes is proportional to the cost of a particular optimization pass.

The following table shows some general guidelines for the optimization passes.

Pass Description

First pass

Removes unnecessary code, such as code that reads the same variable immediately after writing that variable. Instruction sequences might be replaced by a single instruction that performs the same operations.

Second pass

Assigns unused registers to frequently used variables, which reduces the amount of reading and writing to and from memory.

Subsequent passes

Depends on the microprocessor.

See Also

Concepts

Improving the Performance of Software Blits by Generating Blit Functions at Run Time
Implementing the GenBltCpuInitialize Function
Implementing the Translation Function