29.6. x86 shift and rotate instructions

  • SHL and SHR

    SHift left or Right and insert 0.

    CF == the bit that got shifted out.

    Application: quick unsigned multiply and divide by powers of 2.

  • SAL and SAR

    Application: signed multiply and divide by powers of 2.

    Mnemonics: Shift Arithmetic Left and Right

    Keeps the same sign on right shift.

    Not directly exposed in C, for which signed shift is undetermined behavior, but does exist in Java via the >>> operator. C compilers can omit it however.

  • userland/arch/x86_64/rol.S: ROL and ROR

    Rotates the bit that is going out around to the other side.

  • userland/arch/x86_64/rol.S: RCL and RCR

    Like ROL and ROR, but insert the carry bit instead, which effectively generates a rotation of 8 + 1 bits. TODO application.