Academic Program

Barrel Shifter

Barrel Shifter

Instructions

The barrel shifter is capable of shifting a 40-bit value, up to 16bits right or left, in a single cycle. The source can be either of the two DSP accumulators or the X bus, to support multi-bit shifts of register or memory data. The shifter requires a signed binary value to determine both the magnitude (number of bits) and direction of the shift operation. A positive value shifts the operand right. A negative value shifts the operand left. A value of ‘0’ does not modify the operand.

The barrel shifter can be used by both MCU and DSP instructions. The barrel shifter is 40 bits wide, thereby obtaining a 40-bit result for DSP shift operations and a 16-bit result for MCU shift operations. Data from the X bus is presented to the barrel shifter between bit positions 16 to 31 for right shifts, and between bit positions 0 to 16 for left shifts.

  • Single cycle ±16-bit shift
    • Shift left
    • Logical shift right - ignores sign bit
    • Arithmetic shift left - retains sign bit
  • ASR, LSR & SL are identical in dsPIC® DSC and PIC24
  • Rotate instructions (RRC, etc.) do not use barrel shifter

Barrel shifter instructions

Instruction Description
ASR Arithmetic multi-bit right shift of data memory
LSR Logical multi-bit right shift of data memory
SL Multi-bit shift left of data memory
SAC Store DSP accumulator with optional shift
SAC.R Store Rounded DSP accumulator with optional shift
SFTAC Shift DSP Accumulator

ASRLSR, and SL operate on the ALU, while SACSAC.R, and SFTAC operate on the accumulators.

Examples

The first example is using the arithmetic multi-bit right shift of data memory, asr instruction, while the second example utilizes the logical multi-bit right shift of data memory, lsr instruction. The third example performs a multi-bit left shift, and the last example shows the DSP Accumulator shift.

BarrelShifterEx.png