5.14.3.10 The #pragma Shift Directive
The #pragma shift
directive allows the programmer to control which encoding
strategy is employed by the compiler for individual shift operations in project's source
code. For more information on how shift operations can be encoded, see Shift Operators.
shift
pragma has the general
form:#pragma shift strategy
where
strategy
can be one of speed
,
space
, or auto
.If this pragma is not in effect, the compiler will choose a strategy for all shift
operations that will favor speed execution when -O3
level optimizations
are selected, or favor code size for all other optimization levels. Choosing the
auto
strategy makes this choice explicit. The
speed
or space
strategies can be specified with
this pragma to encode any subsequent shift operations (up to the end of the translation
unit or function, or the next shift
pragma) so that they will execute
in a shorter time or take up minimal code space, respectively. This, for example, would
allow you to select -Os
optimizations for the whole program to reduce
the total code size, but still allow any number of individually selected shift
operations to be executed as fast as possible.
push
pragma argument, and restored at a later point using the
pop
argument. For example, the
code:#pragma shift push
#pragma shift speed
dispVal = reading << 5;
#pragma shift pop
will save the current shift strategy, then encode the shift
operation favoring speed, then return the shift strategy to what was selected
earlier.At the end of the current translation unit, the compiler's internal stack is emptied and the current shift strategy will be restored to the default for the current optimization level.