
MAC2424
S3FB42F
25-32
BARREL SHIFTER
The barrel shifter performs standard arithmetic and logical shift, and several special shift operations. It is a 32-bit left
and right, single-cycle, non-pipelined barrel shifter. The barrel shifter receives the source operand from either one of
the 24-bit two Ai accumulator registers or 16-bit SI register. When selected source operand is Ai register, 16 LSBs of
24-bit register value are only valid. The upper 8-bit values are ignored. It also receives the shift amount value from
either one of the 24-bit two Ai accumulator registers or 6-bit SA register. Because the maximum amount of shift is
from –32 (right shift 32-bit) to +31 (left shift 31 bit), 6-bit shift amount is sufficient. When Ai register is used as the
shift amount register, 6 LSBs of 24-bit register value are only valid. The amount of shifts is only determined by a
value in the one of these three register and can not be determined by a constant embedded in the instruction opcode
(immediate shift amount is not supported). The barrel shifter takes 16-bit input operand and 6-bit amount value, and
generates 32-bit shifted output values. The destination of shifted value is two 16-bit shift output register SG and SR
register. The SG register holds the value of shifted out, and the SR register holds the shifted 16-bit values.
The flags are affected as a result of the barrel shifter output, as well as a result of the ARU output. When the result is
transferred into the barrel shifter output register, the flags represent the shifter output register status. The C, N, and Z
flag in MSR0 register is used common to the ARU and the BEU, but the V flag is different. The ARU uses the VA
and VB flags as overflow flag, and the BEU uses the VS flag as overflow flag.
Shifting Operations
Several shift operations are available using the barrel shifter, all of them are performed in a single cycle. The detailed
operations of each shift instruction are depicted in figure 2.15. If 6-bit shift amount value is positive, shift left operation
is performed and if negative, shift right operation is performed. After all barrel shifter operation is performed, the carry
flag has the bit value which is shifted out finally.
"ESFT" instruction performs a standard logical shift operation. The shifted bit pattern is stored into the 16-bit SR
register (Shifter Result register), and the shifted out bit pattern is stored into the 16-bit SG register (Shifter Guard
register). When shift left operation, MSBs of SG register and LSBs of SR register is filled with zeros. When shift right
operation, LSBs of SG register and MSBs of SR register is filled with zeros. "ESFTA" instruction performs a
standard arithmetic shift operation. the operation is all the same as a logical shift except that the MSBs of SG
register or MSBs of SR register is sign-extended instead of being filled with zeros.
"ESFTD" instruction is provided for double precision shift operation. With this instruction, one can shift 32-bit number
stored in two registers. Unlike standard logical and arithmetic shift, this instruction only updates the SG register with
the values that is ORed previous SG register value and shifted out result from barrel shifter. The following codes are
examples of double precision shift operation.
// Double Precision Left ({SG,SR}
← {B,A} <<SA
ESFT
A,SA
// Lower Part Shift
ESFTD
B,SA
// Upper Part Shift
// Double Precision Right ({SR,SG}
← {B,A}>>SA
ESFT
B,SA
// Upper Part Shift
ESFTD
A,SA
// Lower Part Shift