next up previous contents index
Next: 8.1.10 Nibble and Byte Up: 8.1 Optimizations Previous: 8.1.8 Bit-shifting Operations.   Contents   Index


8.1.9 Bit-rotation

A special case of the bit-shift operation is bit rotation, SDCC recognizes the following expression to be a left bit-rotation:

unsigned  char i;           /* unsigned is needed for rotation */  
...  
i = ((i << 1) | (i >> 7));
...
will generate the following code:

mov  a,_i  
rl   a  
mov  _i,a
SDCC uses pattern matching on the parse tree to determine this operation.Variations of this case will also be recognized as bit-rotation, i.e.:

i = ((i >> 7) | (i << 1)); /* left-bit rotation */



2008-12-05