5.5.2 Rotation
Rotate operations can be performed in your code, despite the C language not including a rotate operator.
The compiler will detect expressions that implement rotate operations using shift and logical operators and compile them efficiently.
For the following code:
c = (c << 1) | (c >> 7);
if c
is unsigned and non-volatile, the compiler will
detect that the intended operation is a rotate left of 1 bit and will encode the output
using the PIC MCU rotate instructions. A rotate left of 2 bits
would be implemented with code like:
c = (c << 2) | (c >> 6);
This code optimization will also work for integral types larger than a
char
. If the optimization cannot be applied, or this code is ported to
another compiler, the rotate will be implemented, but typically with shifts and a bitwise
OR operation.