# Patent

## Title
Microprocessor Shifter Circuits Utilizing Butterfly and Inverse Butterfly Routing Circuits, and Control Circuits Therefor

## Abstract

Microprocessor shifter circuits utilizing butterfly and inverse butterfly circuits, and control circuits therefor, are provided. The same shifter circuits can also perform complex bit manipulations at high speeds, including butterfly and inverse butterfly operations, parallel extract and deposit operations, group operations, mix operations, permutation operations, as well as instructions executed by existing microprocessors, including shift right, shift left, rotate, extract, deposit and multimedia mix operations. The shifter circuits can be provided in various combinations to provide microprocessor functional units which perform a plurality of bit manipulation operations.

## Background
RELATED APPLICATIONS
This application is a continuation application of and claims the benefit of priority to U.S. patent application Ser. No. 12/126,616 filed May 23, 2008, now U.S. Pat. No. 8,285,766, which claims the priority of U.S. Provisional Application Ser. No. 60/931,493 filed May 23, 2007, the entire disclosures of which are expressly incorporated herein by reference.


STATEMENT OF GOVERNMENT INTERESTS
The present invention was made with government support under Department of Defense Grant No. H98230-04-C-0496. Accordingly, the Government has certain rights to the present invention.


BACKGROUND OF THE INVENTION
1. Field of the Invention
The present invention relates to circuitry for computer systems, and more specifically, to microprocessor shifter circuits utilizing butterfly and inverse butterfly circuits, and control circuits therefor.
2. Related Art
Bit manipulation operations are important features of modern microprocessors. Unfortunately, bit manipulation operations carried out by existing microprocessors are limited in terms of flexibility and ease of implementation at the hardware level. For example, bit manipulation operations performed by existing microprocessors are often limited to shift and rotate operations. Since a microprocessor is typically optimized around the processing of words (i.e., fixed-length groups of binary bits of information), it is not surprising that bit-level operations are not well-supported by current word-oriented microprocessors. Simple “bit-parallel” Boolean operations such as AND, OR, XOR, and NOT are usually supported as the “logical” operations of the Arithmetic-Logic Unit (ALU), the most fundamental functional unit of a microprocessor. However, only very simple non-bit-parallel operations are supported, such as shift and rotate operations, in which all bits of an operand move by the same amount. These operations are usually supported by separate shifter functional units.
A few microprocessor Instruction Set Architectures (ISAs) have more advanced bit operations. However, these operations are implemented by complex shifter functional unit circuitry, which appreciably adds to the size and complexity of the microprocessor. Examples of such operations include subword extract and deposit operations (e.g., “pextrw” and “pinsrw” operations in the INTEL IA-32 ISA), field extract and deposit operations (e.g., “extr” and “dep” operations in HEWLETT PACKARD PA-RISC or INTEL IA-64 ISAs), or rotate and mask operations (e.g., “rldimi” in POWERPC ISA). These can be viewed as variants of the basic shift or rotate operation operations, with certain bits masked out and set to zeros, or sign bits replicated, or bits from a second operand merged into the result. Additionally, some instruction sets have multimedia permute operations that rearrange the subwords packed into one or more registers (e.g., “mix” operation in HEWLETT PACKARD PA-RISC 2.0 and INTEL IA-64 architectures).
There are also many emerging applications, such as cryptography, imaging, and bioinformatics, where even more advanced bit manipulation operations are needed. While circuitry to achieve these operations can be built by assembling simple logical and shift operation circuits, or by implementing same in firmware, such approaches often result in very large circuits or slow execution speeds. Applications using these advanced bit manipulation operations would thus be significantly sped-up if the processor were able to support more powerful bit manipulation instructions. Such operations include arbitrary bit permutations, bit gather operations (performing multiple bit-field extract operations in parallel), and bit scatter operations (performing multiple bit-field deposit operations in parallel).
Accordingly, what would be desirable, but has not yet been provided, are shifter circuits utilizing butterfly and inverse butterfly circuits, and control circuits therefor, which address the foregoing shortcomings of existing microprocessors.
SUMMARY OF THE INVENTION
The present invention relates to microprocessor shifter circuits utilizing butterfly and inverse butterfly circuits, and control circuits therefor. The shifter circuits can be implemented in existing microprocessors, and allow for complex bit manipulations to be performed by such microprocessors at high speeds. The shifter circuits can perform butterfly and inverse butterfly operations, parallel extract and parallel deposit operations, group operations, mix operations, bit permutation operations, as well as instructions executed by existing microprocessors. The shifter circuits can replace existing shifter circuits in microprocessors, so as to provide new ways for conducting existing shift, rotate, extract, deposit, and mix operations, as well as more advanced bit manipulation instructions. The shifter circuits can be implemented with a reduced amount of circuitry, thus conserving chip space. User applications relating to steganography, binary image morphology, transfer coding, bioinformatics, imaging, and integer compression techniques, among other applications, can be implemented using the shifter circuits of the present invention. The shifter circuits can be provided in various combinations to provide microprocessor functional units which perform a plurality of bit manipulation processes.



BRIEF DESCRIPTION OF THE DRAWINGS
The foregoing features of the invention will be apparent from the following Detailed Description of the Invention, taken in connection with the accompanying drawings, in which:
FIG. 1 is a diagram showing a first embodiment of the shifter circuit of the present invention, implemented using a butterfly circuit;
FIG. 2 is a diagram showing another embodiment of the shifter circuit of the present invention, implemented using an inverse butterfly circuit;
FIGS. 3-4 are circuit diagrams showing, in greater detail, multiplexers utilized by the shifter circuit of the present invention;
FIG. 5 is a circuit diagram showing the butterfly circuit shifter circuit of the present invention implemented using the multiplexer shown in FIG. 4;
FIG. 6 is a diagram showing bit extract and deposit operations capable of being performed by the present invention;
FIG. 7 is a diagram showing bit mix operations capable of being performed by the present invention;
FIG. 8 is a diagram showing the group (grp) instruction capable of being performed by the present invention;
FIG. 9 is a diagram showing parallel extract and parallel deposit operations which are capable of being performed by the present invention;
FIG. 10 is a diagram showing symmetrical operations performed by the inverse butterfly and butterfly embodiments of the present invention;
FIGS. 11-12 are diagrams showing control bit states corresponding to bit manipulation procedures;
FIG. 13 is a diagram showing a control bit generator circuit according to the present invention for controlling the shift circuits;
FIG. 14 is a diagram showing subnetworks of the inverse butterfly circuit of the present invention;
FIG. 15 is a diagram showing the final stage of the pex operation, as processed by the shifter circuit of the present invention;
FIG. 16 is a block diagram showing the decoder for a parallel extract instruction in accordance with the present invention;
FIGS. 17A-17B are block diagrams showing shift-permute functional units in accordance with the present invention;
FIGS. 18A-18B are block diagrams showing the control bit generators of FIG. 17A-17B in greater detail;
FIGS. 19A-31 are diagrams showing implementation of a parallel deposit (pdep) operation using the butterfly network embodiment of the shifter circuit of the present invention;
FIGS. 32-37 are diagrams showing various functional units in accordance with the present invention for implementing combinations of parallel extract, parallel deposit, butterfly permutations, and inverse butterfly permutations;
FIG. 38 is a diagram showing a bit compression procedure capable of being carried out by the present invention;
FIG. 39 shows a steganography procedure capable of being carried out by the present invention;
FIG. 40 shows a binary image morphology procedure capable of being carried out by the present invention;
FIG. 41 shows a transfer coding procedure capable of being carried out by the present invention;
FIGS. 42-44 show sample bioinformatics operations which are capable of being carried out by the present invention;
FIG. 45 shows an integer compression technique capable of being carried out by the present invention;
FIG. 46 shows performance results, normalized to the baseline Alpha ISA cycle counts, of the present invention;
FIG. 47 illustrates a process according to the present invention for generating rotation control bits;
FIG. 48 depicts a dot diagram of the parallel prefix network;
FIGS. 49-50 are circuit diagrams showing Left Rotate and Complement circuits according to the present invention;
FIG. 51 is a circuit diagram showing 64-bit-wide inverse butterfly circuit implemented in accordance with the present invention; and
FIG. 52 is a block diagram showing a sample microprocessor architecture in which the present invention could be implemented.



DETAILED DESCRIPTION OF THE INVENTION
The present invention relates to microprocessor shifter circuits utilizing butterfly and inverse butterfly circuits, and control circuits therefore, for performing complex bit manipulations at high speeds. The shifter circuits can perform butterfly and inverse butterfly operations, parallel extract and parallel deposit operations, group operations, mix operations, permutation operations, as well as instructions executed by existing microprocessors. The shifter circuits can be provided in various combinations to provide microprocessor functional units which perform a plurality of bit manipulation processes.
FIG. 1 is a diagram showing a first embodiment of the shifter circuit 10 of the present invention. The shifter circuit 10 includes a register input 12, a first shifter stage 14, a second shifter stage 16, and a third shifter stage 18, and a register output 20. The shifter circuit 10 can replace shifter circuits of existing processors. By the term “processor,” it is meant a microprocessor (or other circuitry of existing microprocessors which perform bit operations, such as those discussed above) or any other type of processor, such as digital signal processors, embedded processors, cryptoprocessors, communications processors, System-On-Chip(s) (SOC), etc. The register input 12 and output 20 are showing having a width of 8 bits (i.e., bit positions 0 through 7), but it is to be understood that any desired bit widths could be accommodated. The circuit stages 14-18 and their associated interconnections form a butterfly circuit, wherein the first stage 14 includes multiplexers 14a-14h, the second stage 16 includes multiplexers 16a-16h, and the third stage includes multiplexers 18a-18h. As discussed below, the bit width of the circuit 10 determines the number of stages in the circuit.
FIG. 2 is a diagram showing a second embodiment of the shifter circuit of the present invention, indicated generally at 22, wherein an inverse butterfly configuration is shown. As can be seen, the circuit stages 14-18 and their associated interconnections are reversed, such that the circuit stage 18 is provided as the first circuit stage and is connected to the register input 12, and the circuit stage 14 is provided as the third circuit stage and is interconnected to the register output 20. The circuit stage 16 remains the second circuit stage, interconnected between the first and third circuit stages 18 and 14. As mentioned above, the shifter circuit 22 can replace shifter circuits of existing microprocessors (or other circuitry of existing microprocessors which perform bit operations, such as those discussed above), and any desired bit width could be provided.
The shifter circuits 10 and 22 could be implemented in a microprocessor individually, or they could be connected to each other to form a Benes network, which is a general permutation network. The butterfly configuration of the circuit 10 is referred to herein as “bfly,” and the inverse butterfly configuration of the circuit 22 is referred to herein as “ibfly.” A single execution of bfly followed by ibfly (or vice versa) can achieve any of the n! permutations of n bits in, at most, 2 instruction cycles of a microprocessor.
The circuits shown in FIGS. 1-2 represent n-bit circuits of lg(n) stages, wherein each stage comprises n/2 2-input switches (n being any desired bit width, generally a power of 2). Each of these circuits takes at most one processor cycle, since they are less complicated than an ALU of the same width (a processor cycle is assumed to be normalized to the latency of an ALU). Further, as discussed in greater detail below, each switch is composed of two 2:1 multiplexers, totaling n×lg(n) multiplexers for each circuit, which results in small circuit area.
Each of the circuit stages 14-18 of FIGS. 1-2 has n/2 switches, with a pair of inputs going into each switch and a pair of outputs coming out. For each switch, the inputs either pass through to the outputs, or they are swapped, as shown in FIG. 3 described below. In the ith stage (i starting from 1), the paired bits are n/2i positions apart for the butterfly circuit shown in FIG. 1, and 2i-1 positions apart for the inverse butterfly circuit shown in FIG. 2. A switch either passes through or swaps its inputs based on the value of a control bit. Thus, the operation requires n/2×lg(n) control bits. For n=64, four 64-bit registers are required to hold the 64 data bits and the 32×6 control bits.
An embodiment of the present invention provides an architecture that has only 2 source operands per instruction, and which utilizes 3 Application Registers (ar.b1, ar.b2, ar.b3) associated with the functional unit to supply the control bits during the execution of these instructions. Application Registers are registers which are already available in some Instruction Set Architectures (also abbreviated ISAs), such as the INTEL IA-64 ISA. The control bits are determined either statically by a compiler, or dynamically by software. Other permutation primitives like “grp,” discussed below, do not require Application Registers. An arbitrary permutation of the n bits within a register can be performed by a sequence of at most lg(n) grp instructions, or by a sequence of at most 2 instructions using bfly and ibfly instructions. The latter (bfly and ibfly) achieve arbitrary n-bit permutations in O(1) cycles, rather than O(lg(n)) cycles.
FIG. 3 is a circuit diagram showing a switch 24 according to the present invention formed from a pair of 2:1 multiplexers 26. The switch 24 corresponds to a pair of multiplexers shown in FIGS. 1-2, e.g., multiplexers 14a and 14e of FIG. 2 form a single switch 24. Each switch 24 receives two input bits (in1 and in2) and generates two output bits (out1 and out2) which depend on the value of a control bit (cb). If the control bit is set to zero, the circuit 24 passes the input bits directly through as the output bits (i.e., out1=in1, and out2=in2). If the control bit is set to one, the circuit 24 swaps the positions of the input bits and passes the swapped bits as the output bits (i.e., out2=in1, and out1=in2). In certain embodiments, the two functions of the control bit are swapped.
FIG. 4 is a circuit diagram showing an implementation of the multiplexers 26 of FIG. 3 in greater detail. Each of the multiplexers 26 includes a first AND gate 28 having a single inverted input, a second AND gate 30, and an OR gate 32. The control bit cb is provided as inputs to both gates 28 and 30. It is noted that any other suitable circuit configuration for implementing the multiplexers 26 could be utilized without departing from the spirit or scope of the present invention.
FIG. 5 is a circuit diagram showing the shifter circuit 22 of FIG. 2 implemented using the 2:1 multiplexers of FIGS. 3-4. As can be seen, each of the circuit stages 14-18 utilizes eight 2:1 multiplexers. Control bits cb0-cb2 are supplied to the multiplexers of the circuit stages 14-18 to control operation of the multiplexers. Each of the control bits cb0, cb1 and cb2 represents 4 control bits. The generation of control bits in accordance with the present invention is discussed in further detail herein below.
FIG. 6 is a diagram showing bit extract and deposit operations capable of being performed by the present invention. The extract operation, indicated at 40, selects a single field of bits of arbitrary length from any arbitrary position in the source register (i.e., register input 12 in FIGS. 1-2) and right justifies that field in the register output 20 in FIGS. 1-2. This is equivalent to a shift right and mask operation. The extract operation has both unsigned and signed variants. In the latter, the sign bit of the extracted field is propagated to the most-significant bit of the destination register (i.e., register output 20 in FIGS. 1-2). The deposit operation, indicated at 42, takes a single right-justified field of arbitrary length from the source register (i.e., register input 12 in FIGS. 1-2) and deposits it at any arbitrary position in the destination register (i.e., register output 20 in FIGS. 1-2). The deposit operation is equivalent to a left shift and mask operation. Two variants of the deposit operation are possible: the remaining bits can be zeroed out (as shown at 42 in FIG. 6), or they can be supplied from a second register, in which case a masked merge operation is required.
FIG. 7 is a diagram showing bit mix operations capable of being performed by the present invention. The mix operation is a known subword permutation operation, initially designed to accelerate multimedia applications operating on subwords of 8, 16, or 32 bits, packed into a word. The “Mix_left” operation selects the left subwords from each pair of subwords, alternating between the two source registers r2 and r3, as illustrated at 44 in FIG. 7. The “Mix_right” operation does the same on the right subwords of the two source registers, as shown at 46 in FIG. 7. Advantageously, the present invention allows for mixing of subwords smaller than a byte, which is useful for bit matrix transposition and fast parallel sorting procedures. Mix operations for bits, as well as all subword sizes that are powers of 2, are supported by the present invention. This includes 12 mix operations: mix_left and mix_right for each of 6 subword sizes of 20, 21, 22, 23, 24, 25, for a 64-bit processor. Additionally, the present invention also allows for mixing of bit-fields that are not powers of 2, or of different sizes, as long as the sum of the field sizes equals n, the width of the registers.
FIG. 8 is a diagram showing the group (grp) instruction capable of being performed by the present invention. The grp instruction is a permutation primitive that gathers to the right the data bits selected by “1”s in the mask, and to the left those selected by “0”s in the mask. Arbitrary bit permutations can be accomplished by a sequence of at most lg(n) of these grp instructions. Its advantage over the faster sequence of 2 instructions (bfly followed by ibfly) for achieving arbitrary n-bit permutations is that it does not need additional (control or application) registers to configure its datapath.
FIG. 9 is a diagram showing parallel extract and parallel deposit operations, indicated generally at 48 and 50, respectively, which are capable of being performed by the present invention. The parallel extract (“pex”) and parallel deposit (“pdep”) instructions can be viewed as generalizations of the extract and deposit instructions discussed above. Parallel extract performs a bit gather operation; it extracts and compacts bits from one source register from positions selected by “1”s in a second source register (as shown at 48 in FIG. 9). The rest of the bits in the result register are cleared to “0”s. Thus, the parallel extract operation can also be thought of as the right half of the grp operation (grp_right). Parallel deposit performs a bit scatter operation; it deposits bits from one source register to positions selected by “1”s in a second source register (as shown at 50 in FIG. 9). The remaining bits in the result register are cleared to “0”s.
The present invention can support a number of bit manipulation operations, which could be implemented as instructions which are added to the existing instruction set of a microprocessor. These instructions are summarized in Table 1 below:








TABLE 1





Instruction
Description







rotr r1 = r2, shamt
Right rotate of r2. The rotate amount is an immediate in the opcode (shamt).


rotr r1 = r2, r3
Right rotate of r2. The rotate amount is specified using a second source register r3.


rotl r1 = r2, shamt
Left rotate of r2. The rotate amount is an immediate in the opcode (shamt).


rotl r1 = r2, r3
Left rotate of r2. The rotate amount is specified using a second source register r3.


shr r1 = r2, shamt
Right shift of r2 with vacated positions on the left filled with the sign bit (most



significant bit of r2). The shift amount is an immediate in the opcode.


shr r1 = r2, r3
Right shift of r2 with vacated positions on the left filled with the sign bit (most



significant bit of r2). The shift amount is specified using a second source register



r3.


shr.u r1 = r2, shamt
Right shift of r2 with vacated positions on the left zero-filled. The shift amount is



an immediate in the opcode.


shr.u r1 = r2, r3
Right shift of r2 with vacated positions on the left zero-filled. The shift amount is



specified using a second source register r3.


shl r1 = r2, shamt
Left shift of r2 with vacated positions on the right zero-filled. The shift amount is



an immediate in the opcode.


shl r1 = r2, r3
Left shift of r2 with vacated positions on the right zero-filled. The shift amount is



specified using a second source register r3.


extr r1 = r2, pos, len
Extraction and right justification of single field from r2 of length len from



position pos. The high order bits are filled with the sign bit of the extracted field.


extr.u r1 = r2, pos, len
Extraction and right justification of single field from r2 of length len from



position pos. The high order bits are zero-filled.


dep.z r1 = r2, pos, len
Deposit at position pos of single right justified field from r2 of length len.



Remaining bits are zero-filled.


dep r1 = r2, r3, pos, len
Deposit at position pos of single right justified field from r2 of length len.



Remaining bits are merged from second source register r3.


mix {r, l} {0, 1, 2, 3, 4, 5} r1 = r2, r3
Select right or left subword from a pair of subwords, alternating between source



registers r2 and r3. Subword sizes are 2i bits, for i = 0, 1, 2, . . ., 5, for a 64-bit



processor.







---------------------------------------------------------------------------------------------------------------------------------------------------








bfly r1 = r2, ar.b1, ar.b2, ar.b3
Perform Butterfly permutation of data bits in r2


ibfly r1 = r2, ar.ib1,ar.ib2, ar.ib3
Perform Inverse Butterfly permutation of data bits in r2


pex r1 = r2, r3, ar.ib1, ar.ib2,
Parallel extract, static: Data bits in r2 selected by a pre-decoded mask r3 are


ar.ib3
extracted, compressed and right-aligned in the result r1


pdep r1 = r2, r3, ar.b1, ar.b2, ar.b3
Parallel deposit, static: Right-aligned data bits in r2 are deposited, in order, in



result r1 at bit positions marked with a “1” in the statically-decoded mask r3


mov ar.x = r2, r3
Move values from GRs to ARs, to set controls (calculated by software) for pex,



pdep, bfly or ibfly


pex.v r1 = r2, r3
Parallel extract, variable: Data bits in r2 selected by a dynamically-decoded



mask r3 are extracted, compressed and right-aligned in the result r1.


pdep.v r1 = r2, r3
Parallel deposit, variable: Right-aligned data bits in r2 are deposited, in order, in



bit positions marked with a “1” in the dynamically-decoded mask r3.


setib ar.ib1, ar.ib2, ar.ib3 = r3
Set inverse butterfly circuit controls in associated ARs, using hardware decoder



to translate the mask r3 to inverse butterfly controls.


setb ar.b1, ar.b2, ar.b3 = r3
Set butterfly circuit controls in associated ARs, using hardware decoder to



translate the mask r3 to butterfly controls.









The conventional shifter instructions executed by existing microprocessors and listed in the top half of Table 1 above (i.e., above the dotted line in Table 1) can also be implemented by the present invention, since they are all based upon rotation operations. The additional functions implemented by the present invention are listed in the bottom half of Table 1 (i.e., below the dotted line in Table 1). An inverse butterfly circuit can achieve any rotation (cyclic shift) of its input, and can perform the following on its input: right and left shifts, extract operations, deposit operations, and mix operations. These operations can be modeled as a rotate operation with additional logic handling zeroing or sign extension from an arbitrary position, or merging bits from the second source operand (for deposit). Mix operations can be modeled as a rotate of one operand by the subword size and then a merge of subwords alternating between the two operands. Since inverse butterfly circuits only perform permutations without zeroing and without replication, an extra 2:1 multiplexer stage at the end of the shifter circuits of the present invention either selects the rotated bits as-is or other bits which are computed as either zero, or the sign bit (replicated), or the bits of the second source operand, depending on the operation.
FIG. 10 is a diagram showing symmetrical operations performed by the inverse butterfly (indicated at 52) and butterfly (indicated at 54) embodiments of the present invention. The butterfly and inverse butterfly circuits implemented by the present invention exhibit a reverse symmetry of their stages from input to output. Thus, a rotation on the inverse butterfly circuit is equivalent to a rotation in the opposite direction on the butterfly circuit. Hence, a butterfly circuit can also achieve any rotation of its inputs. A butterfly circuit enhanced with an extra multiplexer stage at the end (as implemented in the present invention) is needed to handle zeroing or sign extension, or merging bits from the second source operand.
The generation of control bits for the shifter circuits of the present invention is now discussed with reference to FIGS. 11-13. To achieve a right (or left) rotation by s positions, for s=0, 1, 2 . . . n−1, using the n-bit wide inverse butterfly circuit with lg(n) stages, the input must be right (or left) rotated by s mod 2j within each 2j-bit wide inverse butterfly circuit at each stage j. This is because from stage j+1 on, the inverse butterfly circuit can only move bits at granularities larger than 2j positions (so the finer movements must have already been performed in the prior stages).
An n-bit inverse butterfly circuit can be viewed as two (lg(n)−1)-stage circuits followed by a stage that swaps or passes through paired bits that are n/2 positions apart. To right_rotate the input {inn-1 . . . in0} by s positions, the two (lg(n)−1)-stage circuits must have right_rotated their half inputs by s′=s mod n/2 and the input to stage lg(n) must be of the form:

{inn/2+s′-1 . . . inn/2inn-1 . . . inn/2+s′∥ins′-1 . . . in0inn/2-1 . . . ins′}  (1)

which is true for s less than or greater than n/2.

As shown at 56 in FIG. 11, when the rotation amount s is less than n/2, then the bits that wrapped around in the (lg(n)−1)-stage circuits (indicated by hatching in FIG. 11) must be swapped in the final stage to yield the input right_rotated by s:

{ins′-1 . . . in0 inn-1 . . . inn/2+s′∥inn/2+s′-1 . . . inn/2 inn/2-1 . . . ins′}  (2)

When the rotation amount is greater than or equal to n/2 then the bits that do not wrap in the (lg(n)−1)-stage circuits (solid) must be swapped in the final stage to yield the input right_rotated by s (as illustrated at 58 in FIG. 11):

{inn/2+s′-1 . . . inn/2 inn/2-1 . . . ins′∥ins′-1 . . . in0 inn-1 . . . inn/2+s′}  (3)

For example, consider the 8-bit inverse butterfly circuit with right rotation amount s=5, depicted in FIG. 12. As s=5 is greater than n/2=4, the bits that did not wrap in stage 2 are swapped in stage 3 to yield the final result. As the rotation amount through stage 2, s mod 22=5 mod 4=1, is less than n/4=2, the bits that did wrap in stage 1 are swapped in stage 2 to yield the input to stage 3. As the rotation amount through stage 1, s mod 21=5 mod 2=1, is equal to than n/8=1, the bits that did not wrap in the input, i.e., all the bits, are swapped in stage 1 to yield the input to stage 2.
One can mathematically derive recursive equations for the control bits, cbj, j=1, 2, . . . lg(n), for achieving rotations on an inverse butterfly datapath. These equations yield the compact circuit shown in FIG. 13 for the rotation control bit generator. The process for generating these equations is now discussed.
From Equations 1-3 and FIG. 11, it is observed that the pattern for the control bits for the final stage, which is referred to as cblg(n), for a rotate of s bits, is:




  
    
      
        
          cb
          
            1
            ⁢
            
              g
              ⁡
              
                (
                n
                )
              
            
          
        
        =
        
          {
          
            
              
                
                  
                    1
                    s
                  
                  ⁢
                  
                    
                    
                      
                        0
                        
                          
                            n
                            /
                            2
                          
                          -
                          s
                        
                      
                      ,
                    
                  
                
              
              
                
                  s
                  <
                  
                    n
                    /
                    2
                  
                
              
            
            
              
                
                  
                    0
                    
                      s
                      -
                      
                        n
                        /
                        2
                      
                    
                  
                  ⁢
                  
                    
                    
                      
                        1
                        
                          
                            n
                            /
                            2
                          
                          -
                          
                            (
                            
                              s
                              -
                              
                                n
                                /
                                2
                              
                            
                            )
                          
                        
                      
                      ,
                    
                  
                
              
              
                
                  s
                  ≥
                  
                    n
                    /
                    2
                  
                
              
            
          
        
      
    
    
      
        (
        4
        )
      
    
  




where ak is a string of k “a”s, “1” means “swap” and “0” means “pass through.” Note that s=s mod n/2 when s<n/2 and s−n/2=s mod n/2 when s≧n/2:





  
    
      
        
          cb
          
            1
            ⁢
            
              g
              ⁡
              
                (
                n
                )
              
            
          
        
        =
        
          {
          
            
              
                
                  
                    
                      
                        1
                        
                          s
                          ⁢
                          
                            
                          
                          ⁢
                          mod
                          ⁢
                          
                            
                          
                          ⁢
                          
                            n
                            /
                            2
                          
                        
                      
                      ⁢
                      
                        
                        
                          
                            0
                            
                              
                                n
                                /
                                2
                              
                              -
                              
                                (
                                
                                  smodn
                                  /
                                  2
                                
                                )
                              
                            
                          
                          ,
                        
                      
                    
                  
                  
                    
                      
                        s
                        ⁢
                        
                          
                        
                        ⁢
                        mod
                        ⁢
                        
                          
                        
                        ⁢
                        n
                      
                      <
                      
                        n
                        /
                        2
                      
                    
                  
                
                
                  
                    
                      
                        0
                        
                          smodn
                          /
                          2
                        
                      
                      ⁢
                      
                        
                        
                          
                            1
                            
                              
                                n
                                /
                                2
                              
                              -
                              
                                (
                                
                                  smodn
                                  /
                                  2
                                
                                )
                              
                            
                          
                          ,
                        
                      
                    
                  
                  
                    
                      
                        s
                        ⁢
                        
                          
                        
                        ⁢
                        mod
                        ⁢
                        
                          
                        
                        ⁢
                        n
                      
                      ≥
                      
                        n
                        /
                        2
                      
                    
                  
                
              
              ⁢
              
                

              
              ⁢
              
                cb
                
                  1
                  ⁢
                  
                    g
                    ⁡
                    
                      (
                      n
                      )
                    
                  
                
              
            
            =
            
              {
              
                
                  
                    
                      
                        1
                        
                          smodn
                          /
                          2
                        
                      
                      ⁢
                      
                        
                        
                          
                            0
                            
                              
                                n
                                /
                                2
                              
                              -
                              
                                (
                                
                                  smodn
                                  /
                                  2
                                
                                )
                              
                            
                          
                          ,
                        
                      
                    
                  
                  
                    
                      
                        s
                        ⁢
                        
                          
                        
                        ⁢
                        mod
                        ⁢
                        
                          
                        
                        ⁢
                        n
                      
                      <
                      
                        n
                        /
                        2
                      
                    
                  
                
                
                  
                    
                      ~
                      
                        (
                        
                          
                            
                              1
                              
                                smodn
                                /
                                2
                              
                            
                            ⁢
                            
                              
                              
                                0
                                
                                  
                                    n
                                    /
                                    2
                                  
                                  -
                                  
                                    (
                                    
                                      smodn
                                      /
                                      2
                                    
                                    )
                                  
                                
                              
                              )
                            
                          
                          ,
                        
                      
                    
                  
                  
                    
                      
                        s
                        ⁢
                        
                          
                        
                        ⁢
                        mod
                        ⁢
                        
                          
                        
                        ⁢
                        n
                      
                      ≥
                      
                        n
                        /
                        2
                      
                    
                  
                
              
            
          
        
      
    
    
      
        (
        5
        )
      
    
  




where  ̃ indicates negation.

Due to the recursive structure of the inverse butterfly circuit, Equation 5 can be generalized by substituting j for lg(n), 2j for n and 2j−1 for n/2:




  
    
      
        
          cb
          j
        
        =
        
          {
          
            
              
                
                  
                    1
                    
                      s
                      ⁢
                      
                        
                      
                      ⁢
                      mod
                      ⁢
                      
                        
                      
                      ⁢
                      
                        2
                        
                          j
                          -
                          1
                        
                      
                    
                  
                  ⁢
                  
                    
                    
                      
                        
                          0
                          
                            2
                            
                              j
                              -
                              1
                            
                          
                        
                        -
                        
                          (
                          
                            s
                            ⁢
                            
                              
                            
                            ⁢
                            mod
                            ⁢
                            
                              
                            
                            ⁢
                            
                              2
                              
                                j
                                -
                                1
                              
                            
                          
                          )
                        
                      
                      ,
                    
                  
                
              
              
                
                  
                    s
                    ⁢
                    
                      
                    
                    ⁢
                    mod
                    ⁢
                    
                      
                    
                    ⁢
                    
                      2
                      j
                    
                  
                  <
                  
                    2
                    
                      j
                      -
                      1
                    
                  
                
              
            
            
              
                
                  ~
                  
                    (
                    
                      
                        
                          1
                          
                            s
                            ⁢
                            
                              
                            
                            ⁢
                            mod
                            ⁢
                            
                              
                            
                            ⁢
                            
                              2
                              
                                j
                                -
                                1
                              
                            
                          
                        
                        ⁢
                        
                          
                          
                            0
                            
                              
                                2
                                
                                  j
                                  -
                                  1
                                
                              
                              -
                              
                                (
                                
                                  smod
                                  ⁢
                                  
                                    
                                  
                                  ⁢
                                  
                                    2
                                    
                                      j
                                      -
                                      1
                                    
                                  
                                
                                )
                              
                            
                          
                          )
                        
                      
                      ,
                    
                  
                
              
              
                
                  
                    s
                    ⁢
                    
                      
                    
                    ⁢
                    mod
                    ⁢
                    
                      
                    
                    ⁢
                    
                      2
                      j
                    
                  
                  ≥
                  
                    2
                    
                      j
                      -
                      1
                    
                  
                
              
            
          
        
      
    
    
      
        (
        6
        )
      
    
  




There are j bits in s mod 2j, with the most significant bit denoted sj−1. The condition s mod 2j<2j−1 is equivalent to sj−1 being equal to 0 and the condition s mod 2j≧2j−1 is equivalent to sj−1 being equal to 1:




  
    
      
        
          cb
          j
        
        =
        
          {
          
            
              
                
                  
                    
                      1
                      
                        smod
                        ⁢
                        
                          
                        
                        ⁢
                        
                          2
                          
                            j
                            -
                            1
                          
                        
                      
                    
                    ⁢
                    
                      
                      
                        0
                        
                          
                            2
                            
                              j
                              -
                              1
                            
                          
                          -
                          
                            (
                            
                              smod
                              ⁢
                              
                                
                              
                              ⁢
                              
                                2
                                
                                  j
                                  -
                                  1
                                
                              
                            
                            )
                          
                        
                      
                      )
                    
                  
                  ,
                
              
              
                
                  
                    s
                    
                      j
                      -
                      1
                    
                  
                  =
                  0
                
              
            
            
              
                
                  ~
                  
                    (
                    
                      
                        
                          1
                          
                            smod
                            ⁢
                            
                              
                            
                            ⁢
                            
                              2
                              
                                j
                                -
                                1
                              
                            
                          
                        
                        ⁢
                        
                          
                          
                            0
                            
                              
                                2
                                
                                  j
                                  -
                                  1
                                
                              
                              -
                              
                                (
                                
                                  smod
                                  ⁢
                                  
                                    
                                  
                                  ⁢
                                  
                                    2
                                    
                                      j
                                      -
                                      1
                                    
                                  
                                
                                )
                              
                            
                          
                          )
                        
                      
                      ,
                    
                  
                
              
              
                
                  
                    s
                    
                      j
                      -
                      1
                    
                  
                  =
                  1
                
              
            
          
        
      
    
    
      
        (
        7
        )
      
    
  




Equation 7 can be rewritten as the pattern XORed with sj−1:

cbj=(1s mod 2j−1∥02j−1−(s mod 2j−1))⊕sj−1  (8)

Since s mod k≦k−1, k−(s mod k)≧1 and hence the length of the string of zeros in Equation 8 is always ≧1 (k=2j−1). Consequently, the least significant bit of the pattern (prior to XOR with sj−1) is always “0”:

cbj=(1s mod 2j−1∥02j−1−1−(s mod 2j−1)∥0)⊕sj−1 

cbj=((1s mod 2j−1∥02j−1−1−(s mod 2j−1))⊕sj−1)∥sj−1  (9)

The bit pattern inside the inner parenthesis of the bottom Equation 9 is referred to as f(s, j), a string of 2j−1−1 bits with the s mod 2j−1 leftmost bits set to “1” and the remaining bits set to “0.” This function is only defined for j≧2 and returns the empty string for j=1:




  
    
      
        
          f
          ⁡
          
            (
            
              s
              ,
              j
            
            )
          
        
        =
        
          {
          
            
              
                
                  
                    1
                    
                      smod
                      ⁢
                      
                        
                      
                      ⁢
                      
                        2
                        
                          j
                          -
                          1
                        
                      
                    
                  
                  ⁢
                  
                    
                    
                      
                        0
                        
                          
                            2
                            
                              j
                              -
                              1
                            
                          
                          -
                          1
                          -
                          
                            (
                            
                              smod
                              ⁢
                              
                                
                              
                              ⁢
                              
                                2
                                
                                  j
                                  -
                                  1
                                
                              
                            
                            )
                          
                        
                      
                      ,
                    
                  
                
              
              
                
                  j
                  ≥
                  2
                
              
            
            
              
                
                  {
                  }
                
              
              
                
                  j
                  =
                  1
                
              
            
          
        
      
    
    
      
        (
        10
        )
      
    
  
  
    
      
        
          cb
          j
        
        =
        
          
            (
            
              
                f
                ⁡
                
                  (
                  
                    s
                    ,
                    j
                  
                  )
                
              
              ⊕
              
                s
                
                  j
                  -
                  1
                
              
            
            )
          
          ⁢
          
            
            
              s
              
                j
                -
                1
              
            
          
        
      
    
    
      
        (
        11
        )
      
    
  




Note that one can derive f(s, j+1) from f(s, j):

f(s,j+1)=1s mod 2j∥02j−1−(s mod 2j)  (12)

If bit sj−1=0 then s mod 2j=s mod 2j−1:





  
    
      
        
          
            
              
                f
                ⁡
                
                  (
                  
                    s
                    ,
                    
                      j
                      +
                      1
                    
                  
                  )
                
              
              =
              
              ⁢
              
                
                  1
                  
                    smod
                    ⁢
                    
                      
                    
                    ⁢
                    
                      2
                      
                        j
                        -
                        1
                      
                    
                  
                
                ⁢
                
                  
                  
                    0
                    
                      
                        2
                        j
                      
                      -
                      1
                      -
                      
                        (
                        
                          smod
                          ⁢
                          
                            
                          
                          ⁢
                          
                            2
                            
                              j
                              -
                              1
                            
                          
                        
                        )
                      
                    
                  
                
              
            
          
        
        
          
            
              =
              
              ⁢
              
                
                  1
                  
                    smod
                    ⁢
                    
                      
                    
                    ⁢
                    
                      2
                      
                        j
                        -
                        1
                      
                    
                  
                
                ⁢
                
                  
                  
                    0
                    
                      
                        2
                        
                          j
                          -
                          1
                        
                      
                      -
                      1
                      -
                      
                        (
                        
                          smod
                          ⁢
                          
                            
                          
                          ⁢
                          
                            2
                            
                              j
                              -
                              1
                            
                          
                        
                        )
                      
                    
                  
                  
                
                ⁢
                
                  0
                  
                    2
                    
                      j
                      -
                      1
                    
                  
                
              
            
          
        
      
    
    
      
        (
        13
        )
      
    
  
  
    
      
        
          f
          ⁡
          
            (
            
              s
              ,
              
                j
                +
                1
              
            
            )
          
        
        =
        
          
            f
            ⁡
            
              (
              
                s
                ,
                j
              
              )
            
          
          ||
          
            0
            
              2
              
                j
                -
                1
              
            
          
        
      
    
    
      
        
      
    
  




If bit sj−1=1 then s mod 2j=2j−1+s mod 2j−1:





  
    
      
        
          
            
              
                f
                ⁡
                
                  (
                  
                    s
                    ,
                    
                      j
                      +
                      1
                    
                  
                  )
                
              
              =
              
              ⁢
              
                
                  1
                  
                    
                      2
                      
                        j
                        -
                        1
                      
                    
                    +
                    
                      smod
                      ⁢
                      
                        
                      
                      ⁢
                      
                        2
                        
                          j
                          -
                          1
                        
                      
                    
                  
                
                ⁢
                
                  
                  
                    0
                    
                      
                        2
                        j
                      
                      -
                      1
                      -
                      
                        (
                        
                          
                            2
                            
                              j
                              -
                              1
                            
                          
                          +
                          
                            smod
                            ⁢
                            
                              
                            
                            ⁢
                            
                              2
                              
                                j
                                -
                                1
                              
                            
                          
                        
                        )
                      
                    
                  
                
              
            
          
        
        
          
            
              =
              
              ⁢
              
                
                  1
                  
                    2
                    
                      j
                      -
                      1
                    
                  
                
                ⁢
                
                  
                  
                    1
                    
                      s
                      ⁢
                      
                        
                      
                      ⁢
                      mod
                      ⁢
                      
                        
                      
                      ⁢
                      
                        2
                        
                          j
                          -
                          1
                        
                      
                    
                  
                  
                
                ⁢
                
                  0
                  
                    
                      2
                      
                        j
                        -
                        1
                      
                    
                    -
                    1
                    -
                    
                      (
                      
                        s
                        ⁢
                        
                          
                        
                        ⁢
                        mod
                        ⁢
                        
                          
                        
                        ⁢
                        
                          2
                          
                            j
                            -
                            1
                          
                        
                      
                      )
                    
                  
                
              
            
          
        
      
    
    
      
        (
        14
        )
      
    
  
  
    
      
        
          f
          ⁡
          
            (
            
              s
              ,
              
                j
                +
                1
              
            
            )
          
        
        =
        
          
            1
            
              2
              
                j
                -
                1
              
            
          
          ⁢
          
            
            
              f
              ⁡
              
                (
                
                  s
                  ,
                  j
                
                )
              
            
          
        
      
    
    
      
        
      
    
  




Combining Equations 13 and 14, we get:





  
    
      
        
          f
          ⁡
          
            (
            
              s
              ,
              
                j
                +
                1
              
            
            )
          
        
        =
        
          {
          
            
              
                
                  
                    
                      
                        
                          f
                          ⁡
                          
                            (
                            
                              s
                              ,
                              j
                            
                            )
                          
                        
                        ||
                        
                          0
                          
                            2
                            
                              j
                              -
                              1
                            
                          
                        
                      
                      ,
                    
                  
                  
                    
                      
                        s
                        
                          j
                          -
                          1
                        
                      
                      =
                      0
                    
                  
                
                
                  
                    
                      
                        1
                        
                          2
                          
                            j
                            -
                            1
                          
                        
                      
                      ⁢
                      
                        
                        
                          
                            f
                            ⁡
                            
                              (
                              
                                s
                                ,
                                j
                              
                              )
                            
                          
                          ,
                        
                      
                    
                  
                  
                    
                      
                        s
                        
                          j
                          -
                          1
                        
                      
                      =
                      1
                    
                  
                
              
              ⁢
              
                

              
              ⁢
              
                f
                ⁡
                
                  (
                  
                    s
                    ,
                    
                      j
                      +
                      1
                    
                  
                  )
                
              
            
            =
            
              {
              
                
                  
                    
                      
                        
                          f
                          ⁡
                          
                            (
                            
                              s
                              ,
                              j
                            
                            )
                          
                        
                        ⁢
                        
                          
                          0
                          
                        
                        ⁢
                        
                          0
                          
                            2
                            
                              j
                              -
                              1
                            
                          
                        
                      
                      ,
                    
                  
                  
                    
                      
                        s
                        
                          j
                          -
                          1
                        
                      
                      =
                      0
                    
                  
                
                
                  
                    
                      
                        
                          1
                          
                            
                              2
                              
                                j
                                -
                                1
                              
                            
                            -
                            1
                          
                        
                        ⁢
                        
                          
                          1
                          
                        
                        ⁢
                        
                          f
                          ⁡
                          
                            (
                            
                              s
                              ,
                              j
                            
                            )
                          
                        
                      
                      ,
                    
                  
                  
                    
                      
                        s
                        
                          j
                          -
                          1
                        
                      
                      =
                      1
                    
                  
                
              
            
          
        
      
    
    
      
        (
        15
        )
      
    
  




Since f(s, j) is a string of 2j−1−1 bits, we can replace the string of ones in the lower Equation 15 by f(s, j) ORed (+) with 0 or 1, respectively. Similarly, we can replace the string of zeros in Equation 15 by f(s, j) ANDed (·) with 0 or 1, respectively. The value of sj−1 determines whether 0 or 1 is used:




  
    
      
        
          f
          ⁡
          
            (
            
              s
              ,
              
                j
                +
                1
              
            
            )
          
        
        =
        
          {
          
            
              
                
                  
                    
                      
                        
                          f
                          ⁡
                          
                            (
                            
                              s
                              ,
                              j
                            
                            )
                          
                        
                        +
                        
                          0
                          ⁢
                          
                            
                            0
                            
                          
                          ⁢
                          
                            
                              f
                              ⁡
                              
                                (
                                
                                  s
                                  ,
                                  j
                                
                                )
                              
                            
                            ·
                            0
                          
                        
                      
                      ,
                    
                  
                  
                    
                      
                        s
                        
                          j
                          -
                          1
                        
                      
                      =
                      0
                    
                  
                
                
                  
                    
                      
                        
                          f
                          ⁡
                          
                            (
                            
                              s
                              ,
                              j
                            
                            )
                          
                        
                        +
                        
                          1
                          ⁢
                          
                            
                            1
                            
                          
                          ⁢
                          
                            
                              f
                              ⁡
                              
                                (
                                
                                  s
                                  ,
                                  j
                                
                                )
                              
                            
                            ·
                            1
                          
                        
                      
                      ,
                    
                  
                  
                    
                      
                        s
                        
                          j
                          -
                          1
                        
                      
                      =
                      1
                    
                  
                
              
              ⁢
              
                

              
              ⁢
              
                f
                ⁡
                
                  (
                  
                    s
                    ,
                    
                      j
                      +
                      1
                    
                  
                  )
                
              
            
            =
            
              
                (
                
                  
                    f
                    ⁡
                    
                      (
                      
                        s
                        ,
                        j
                      
                      )
                    
                  
                  +
                  
                    s
                    
                      j
                      -
                      1
                    
                  
                
                )
              
              ⁢
              
                
                
                  s
                  
                    j
                    -
                    1
                  
                
                
              
              ⁢
              
                (
                
                  
                    f
                    ⁡
                    
                      (
                      
                        s
                        ,
                        j
                      
                      )
                    
                  
                  ·
                  
                    s
                    
                      j
                      -
                      1
                    
                  
                
                )
              
            
          
        
      
    
    
      
        (
        16
        )
      
    
  




From Equations 10 and 16 we obtain a simple recursive expression for f(s, j):




  
    
      
        
          f
          ⁡
          
            (
            
              s
              ,
              j
            
            )
          
        
        =
        
          {
          
            
              
                
                  
                    
                      (
                      
                        
                          f
                          ⁡
                          
                            (
                            
                              s
                              ,
                              
                                j
                                -
                                1
                              
                            
                            )
                          
                        
                        +
                        
                          s
                          
                            j
                            -
                            2
                          
                        
                      
                      )
                    
                    ⁢
                    
                      
                      
                        S
                        
                          j
                          -
                          2
                        
                      
                      
                    
                    ⁢
                    
                      (
                      
                        
                          f
                          ⁡
                          
                            (
                            
                              s
                              ,
                              
                                j
                                -
                                1
                              
                            
                            )
                          
                        
                        ·
                        
                          s
                          
                            j
                            -
                            2
                          
                        
                      
                      )
                    
                  
                  ,
                
              
              
                
                  j
                  ≥
                  2
                
              
            
            
              
                
                  
                    {
                    }
                  
                  ,
                
              
              
                
                  j
                  =
                  1
                
              
            
          
        
      
    
    
      
        (
        17
        )
      
    
  




Equation 11 shows a method for getting the j/2 control bits cbj for the switches in any stage j of the inverse butterfly circuit using a recursive function f(s, j) and a bit sj−1 from the shift amount s. This can also be seen in FIG. 13, described below. For a rotation, every bit moves by the same amount, namely the shift amount s. Hence, the control bits to subsets of switches, belonging to the smaller inverse butterfly circuits up to that stage, are the same.
Referring to FIGS. 2 and 12, which show an 8-bit inverse butterfly circuit, the 1-bit control bits, cb1, from FIG. 13 goes to four switches in stage 1 that pair bits that are 1 bit apart, which represent four 2-bit inverse butterfly circuits. The 2-bit control bits, cb2, for stage 2 go to four switches that pair bits that are 2 bits apart, which together with stage 1 represent two 4-bit inverse butterfly circuits. The 4-bit control bits, cb3, for stage 3 go to four switches that pair bits that are 4 bits apart, which together with stages 1 and 2 represent the 8-bit inverse butterfly circuit. Equation 11 and FIG. 13 show how these control bits cbj or each stage j can be generated using the recursive function f(s,j) described in Equation 17.
Equation 11 provides that the control bits cbj are generated by taking the recursive function f(s,j) and Exclusive-OR it with a bit from the shift amount, sj−1, and concatenate the result with sj−1. Equation 17 then describes how the function f(s,j) can be recursively generated from the same function for the previous stage, f(s, j−1). This uses the OR function, +, and the AND function with f(s, j−1). The recursive function f(s,j) is derived by f(s, j−1) OR with sj−2, concatenated with sj−2, then concatenated with f(s, j−1) AND with sj−2. This can also be seen in the hardware realization in FIG. 13, described below. It should be clear that other embodiments of control bit generation for doing rotations on an inverse butterfly circuit, or on a butterfly circuit, are possible.
FIG. 13 depicts the hardware implementation of the control bit generator for rotations. Equation 17 is used to derive f(s, 2), f(s, 3), f(s, 4) and f(s, 5). Also, the control bits for rotations, cb1, cb2, cb3, cb4 and cb5, are obtained using Equation 11. This implementation is based on sharing of gates by reusing f(s,j) for both cbj and f(s, j+1). It is noted that other implementations of the control bit generator are also possible.
Discussion of the use of these equations is now provided with the example of FIG. 12, the 8-bit inverse butterfly circuit with right rotation amount s=5 (s2s1s0=101). The first stage control bit, cb1, replicated for the four 2-bit circuits, is given by Equations 11 and 17 and expressed as follows:

cb1=(f(5,1)⊕s0)∥s0{ }⊕s0∥s0=s0=1.  (18)

The second stage control bits, cb2, replicated for the two 4-bit circuits, are given by:




  
    
      
        
          
            
              
                cb
                2
              
              =
              
              ⁢
              
                
                  (
                  
                    
                      f
                      ⁡
                      
                        (
                        
                          5
                          ,
                          2
                        
                        )
                      
                    
                    ⊕
                    
                      s
                      1
                    
                  
                  )
                
                ⁢
                
                  
                  
                    s
                    1
                  
                
              
            
          
        
        
          
            
              =
              
              ⁢
              
                
                  (
                  
                    
                      (
                      
                        
                          f
                          ⁡
                          
                            (
                            
                              5
                              ,
                              1
                            
                            )
                          
                        
                        +
                        
                          
                            s
                            0
                          
                          ⁢
                          
                            
                            
                              s
                              0
                            
                            
                          
                          ⁢
                          
                            
                              f
                              ⁡
                              
                                (
                                
                                  5
                                  ,
                                  1
                                
                                )
                              
                            
                            ·
                            
                              s
                              0
                            
                          
                        
                      
                      )
                    
                    ⊕
                    
                      s
                      1
                    
                  
                  )
                
                ⁢
                
                  
                  
                    s
                    1
                  
                
              
            
          
        
        
          
            
              =
              
              ⁢
              
                
                  (
                  
                    
                      (
                      
                        
                          {
                          }
                        
                        +
                        
                          
                            s
                            0
                          
                          ⁢
                          
                            
                            
                              s
                              0
                            
                            
                          
                          ⁢
                          
                            
                              {
                              }
                            
                            ·
                            
                              s
                              0
                            
                          
                        
                      
                      )
                    
                    ⊕
                    
                      s
                      1
                    
                  
                  )
                
                ⁢
                
                  
                  
                    s
                    1
                  
                
              
            
          
        
        
          
            
              =
              
              ⁢
              
                
                  (
                  
                    
                      s
                      0
                    
                    ⊕
                    
                      s
                      1
                    
                  
                  )
                
                ⁢
                
                  
                  
                    s
                    1
                  
                
              
            
          
        
        
          
            
              =
              
              ⁢
              
                
                  (
                  
                    1
                    ⊕
                    0
                  
                  )
                
                ⁢
                
                  
                  0
                
              
            
          
        
        
          
            
              =
              
              ⁢
              10.
            
          
        
      
    
    
      
        (
        19
        )
      
    
  




Note that f(5,2)=1 in the above. The final stage control bits, cb3, are given by:




  
    
      
        
          
            
              
                cb
                3
              
              =
              
              ⁢
              
                
                  (
                  
                    
                      f
                      ⁡
                      
                        (
                        
                          5
                          ,
                          3
                        
                        )
                      
                    
                    ⊕
                    
                      s
                      2
                    
                  
                  )
                
                ⁢
                
                  
                  
                    s
                    2
                  
                
              
            
          
        
        
          
            
              =
              
              ⁢
              
                
                  (
                  
                    
                      (
                      
                        
                          f
                          ⁡
                          
                            (
                            
                              5
                              ,
                              2
                            
                            )
                          
                        
                        +
                        
                          
                            s
                            1
                          
                          ⁢
                          
                            
                            
                              s
                              1
                            
                            
                          
                          ⁢
                          
                            
                              f
                              ⁡
                              
                                (
                                
                                  5
                                  ,
                                  2
                                
                                )
                              
                            
                            ·
                            
                              s
                              1
                            
                          
                        
                      
                      )
                    
                    ⊕
                    
                      s
                      2
                    
                  
                  )
                
                ⁢
                
                  
                  
                    s
                    2
                  
                
              
            
          
        
        
          
            
              =
              
              ⁢
              
                
                  (
                  
                    
                      (
                      
                        1
                        +
                        
                          
                            s
                            1
                          
                          ⁢
                          
                            
                            
                              s
                              1
                            
                            
                          
                          ⁢
                          
                            1
                            ·
                            
                              s
                              1
                            
                          
                        
                      
                      )
                    
                    ⊕
                    
                      s
                      2
                    
                  
                  )
                
                ⁢
                
                  
                  
                    s
                    2
                  
                
              
            
          
        
        
          
            
              =
              
              ⁢
              
                
                  (
                  
                    
                      (
                      
                        1
                        +
                        
                          0
                          ⁢
                          
                            
                            0
                            
                          
                          ⁢
                          
                            1
                            ·
                            0
                          
                        
                      
                      )
                    
                    ⊕
                    1
                  
                  )
                
                ⁢
                
                  
                  1
                
              
            
          
        
        
          
            
              =
              
              ⁢
              
                
                  ~
                  
                    (
                    100
                    )
                  
                
                ⁢
                
                  
                  1
                
              
            
          
        
        
          
            
              =
              
              ⁢
              0111.
            
          
        
      
    
    
      
        (
        20
        )
      
    
  




FIG. 12 shows that this configuration of the inverse butterfly circuit does indeed right rotate the input by 5 mod 8 (and that the outputs of stage 2 are rotated by 5 mod 4=1 and that the outputs of stage 1 are rotated by 5 mod 2=1).
The other operations (shifts, extract, deposit, and mix) shown in Table 1 above can be modeled as a rotation part plus a masked-merge part with zeroes, sign bits or second source operand bits. The rotation part can use the same rotation control bit generator described above to configure the inverse butterfly circuit datapath. The masked-merge part can be achieved by using an enhanced inverse butterfly datapath with an extra multiplexer stage added as the final stage. The mask control bits are “0” when selecting the rotated bits and “1” when selecting the merge bits.
For a right shift by s, the s sign or zero bits on the left are merged in. This requires a control string 1s∥0n−s for the extra multiplexer stage. From the definition of f(s, j), it can be seen that f(s, lg(n)+1) is the string 1s∥0n−1−s. Thus, the desired control string is given by f(s, lg(n)+1)∥0 (recall that s<n therefore the least significant bit is always “0”, i.e., the least significant bit is always selected from the inverse butterfly datapath). f(s, lg(n)+1) can easily be produced by extending the rotation control bit generator by one extra stage. For left shift, which can be viewed as the left-to-right reversal of right shift, the control bits for the extra stage are obtained by reversing left-to-right the right shift control string to yield 0n−s∥1s.
For extract operations, which are like right shift operations with the left end replaced by the sign bit of the extracted field or zeros, the inverse butterfly circuit of the present invention selects in its extra multiplexer stage the rotated bits or zeros or the sign bit of the extracted field i.e., the bit in position pos+len−1 in the source register (see FIG. 6 at 40). The bit can be selected using an n:1 multiplexer. The control bit pattern for this stage is n-len “1”s followed by len “0”s (1n-len∥0len) to propagate the sign bit of the extracted field in the output (which is in position len-1) to the high order bits. Note that cblg(n)+1(len)={f(len, lg(n)+1)⊕lenlg(n)∥lenlg(n)} is 1len∥0n-len (as len ranges from 0 to n and has lg(n)+1 bits: lenlg(n) . . . 0) So, reversing left-to-right cblg(n)+1(len) yields 0n-len∥1len and then negating it produces 1n-len∥0len, the correct bit pattern for stage lg(n)+1.
For deposit operations, which are like left shift operations with the right and left ends replaced by zeros or bits from the second operand, the inverse butterfly circuit of the present invention selects in its extra multiplexer stage the rotated bits or zeros or bits from the second input operand. The correct pattern is a string of n-pos−len “1”s followed by len “0”s followed by s=pos “1”s (1n-pos−len∥0len∥1pos) merge in bits on the right and left around the deposited field. cblg(n)+1(pos+len)={f(pos+len, lg(n)+1)⊕(pos+len)lg(n)∥(pos+len)lg(n)} is 1pos+len∥0n-pos−len (as pos+len ranges from 0 to n and has lg(n)+1 bits: (pos+len)lg(n) . . . 0.). Reversing left-to-right this string yields 0n-pos−len∥1pos+len and then negating it produces 1n-pos−len∥0pos+len. Bitwise ORing this with the left shift control string, 0n-pos∥1pos, yields 1n-pos−len∥0len∥1pos, the correct pattern for the masked-merge part of the deposit operation is produced.
For mix operations, the enhanced inverse butterfly circuit of the present invention selects in its extra multiplexer stage the rotated bits or the bits from the second input operand. The control bit pattern is simply a pattern of alternating strings of “0”s and “1”s, the precise pattern depending on the subword size and whether mix left or mix right is executed. These patterns can be hard coded in the circuit for the 12 mix operations (6 operand sizes×2 directions).
The foregoing mask-merged bit patterns and mask control are summarized in Table 2 below:










TABLE 2









Instruction
Merge Bits







rotr/rotl
—



shr
(sign bit)n



shr.u
0n



shl
0n



extr
(r2[pos + len − 1])n



extr.u
0n



dep.z
0n



dep
r3



mix.r
r3



mix.l
r3



bfly/ibfly
—



pex/pex.v
—



pdep/pdep.v
0n







Instruction
Mask Control







rotr/rotl
0n



Shr
1s || 0n-s



Shr.u
1s || 0n-s



Shl
0s || 1n-s



extr
1n−len || 0len



extr.u
1n−len || 0len



dep.z
1n−pos−len || 0len || 1pos



dep
1n−pos−len || 0len || 1pos



mix.r
(0k || 1k)n/2k, k = 1, 2, 4, 8, 16, 32



mix.l
(1k || 0k)n/2k, k = 1, 2, 4, 8, 16, 32



bfly/ibfly
0n



pex/pex.v
0n



pdep/pdep.v
r3










The inverse butterfly circuit implemented by the present invention can perform a parallel extract (pex) operation. The inverse butterfly circuit is decomposed into even and odd subcircuits. As shown in FIG. 14, the even subcircuits are shown with dotted lines and the odd subcircuits with solid lines. These can also be called right and left subcircuits. For simplicity and clarity of notation even subcircuits are referred to herein as R (right) and odd subcircuits as L (left). The circuit 60 of FIG. 14 is similar to the inverse butterfly circuit shown in FIG. 2, and includes a register input 62 and three circuit stages 64-68. The proof in support of implementing pex on an inverse butterfly circuit is provided as follows:
Fact 1. Any single data bit can be moved to any result position by just moving it to the correct R or L subcircuit of the intermediate result at every stage of the inverse butterfly circuit.
Proof. This can be proved by induction on the number of stages. At stage 1, the data bit is moved to its final position mod 2 (i.e., to R or L). At stage 2, it is moved to its final position mod 4, and so on. At stage lg(n), it is moved to its final position mod 2lg(n)=n, which is its final result position.
Fact 2. A permutation is routable on an inverse butterfly circuit if the destinations of the bits constitute a complete set of residues mod m (i.e., the destinations equal 0, 1, . . . , m−1 mod m) for each subcircuit of width m.
Proof. Based on Fact 1, bits are routed on the inverse butterfly circuit by moving them to the correct position mod 2 after the first stage, mod 4 after the second stage, etc. Consequently, if the two bits entering stage 1, (with 2-bit wide inverse butterfly circuits as shown in FIG. 14), have destinations equal to 0 and 1 mod 2 (i.e., one is going to R and one to L), Fact 1 can be satisfied for both bits and they are routable through stage 1 without conflict. Subsequently, the four bits entering stage 2 (with the 4-bit wide butterfly circuits) must have destinations equal to 0, 1, 2 and 3 mod 4 to satisfy Fact 1 and be routable through stage 2 without conflict. A similar constraint exists for each stage.
Theorem 1. Any Parallel Extract instruction on n=2lg(n) bits can be implemented with one pass through an inverse butterfly circuit of lg(n) stages without path conflicts (with the un−selected bits on the left zeroed out).
Proof. The pex operation compresses bits in their original order into adjacent bits in the result. Consequently, two adjacent selected data bits that enter the same stage 1 subcircuit must be adjacent in the output. In other words, one bit has a destination equal to 0 mod 2 and the other has a destination equal to 1 mod 2—the destinations constitute a complete set of residues mod 2 and thus are routable through stage 1. The selected data bits that enter the same stage 2 subcircuit must be adjacent in the output and thus form a set of residues mod 4 and are routable through stage 2. A similar situation exists for the subsequent stages, up to the final n-bit wide stage. No matter what the bit mask of the overall pex operation is, the selected data bits will be adjacent in the final result. Thus the destination of the selected data bits will form a set of residues mod n and the bits will be routable through all lg(n) stages of the inverse butterfly circuit.
Parallel deposit can be performed using the butterfly circuit of the present invention, since the parallel deposit operation is the inverse of the parallel extract operation. Also, the grp operation discussed above can be mapped to two parallel inverse butterfly circuits, since grp is a combination of a grp_right (or pex) and a grp_left (a mirrored pex).
A decoder for the parallel extract (and parallel deposit) instruction takes as its input the n-bit mask and produces the n/2×lg(n) control bits for the inverse butterfly (or butterfly) circuit. The decoder can be designed to consist of only two types of operations that can be performed in software or implemented as circuits: a parallel prefix population counter, which counts the ones from position 0 (on the right) to every bit position from 0 to n−2, and a set of left rotators that complement bits upon wraparound (LROTC—Left ROTate and Complement). The theoretical underpinnings for a parallel extract decoder are discussed below in connection with FIG. 15.
FIG. 15 is a diagram showing the final stage of the pex operation, as processed by the shifter circuit of the present invention. In the final stage, X represents the selected data bits that pass through in R, Y represents the selected data bits that are transferred from L to R, and Z represents the selected data bits that pass through in L (R is used to denote the right subnet and L is used to denote the left subnet in an inverse butterfly circuit, as discussed above in connection with FIG. 14).
X is the rightmost bits of R, as the output of pex is the selected data bits compressed and right justified in the result. Y is rotated left from the midpoint by the size of X, |X|, at the input to the final stage so that when it is swapped into R in the final stage it is contiguous to X on its right. Z is the rightmost bits in L at the input to the final stage, so that when it is passed through in L, it is contiguous with the bits in R. Thus, the control bit pattern for the final stage is 1n/2-|X|∥0|X|, where “1” denotes swap, and “0” denotes pass-through of the paired bits in L and R, in the last stage. |X| is equal to the count of “1”s in the right half of the bit mask as all the selected data bits in the right half of the input have already been compressed and right justified prior to the input to the final stage. This pattern can be generated by a left rotate and complement on wraparound (LROTC) operation of the one string of length n/2. For every position in the rotation, a “1” is wrapped around from the left and complemented to obtain a “0” on the right. The end result, after a LROTC by |X| bits, is a string with the |X| rightmost bits set to “0” and the rest set to “1.”
Referring to the top row of FIG. 15, Y and Z can be viewed as having been left rotated by |X| from being the rightmost bits of L at the output of stage lg(n)−1. Consequently, it is possible to iterate backwards through the stages, performing a pex operation within each half subcircuit and then explicitly left rotate each local L at the input of the next stage by the number of selected data bits in the local R at the input of the next stage prior to the swapping or passing through of bits in this next stage.
Rather than rotating the data bits explicitly, it is possible to compensate for the rotation by modifying the routing through the subsequent stages. This can be achieved by rotating the control bits by the same number of positions, complementing upon wraparound (LROTC). These rotations are propagated forward. Consequently, the control bits for a stage, obtained by a LROTC of the one string by the count of “1”s in the right half of the local bit mask, are further modified by a LROTC operation by the count of “1”s in the right half of the next larger local bit mask, and so on. The result is a single LROTC operation of the one string by count of “1”s in the right half the local bit mask through bit 0, the least significant bit. Overall, the counts are needed of the k rightmost bits, for k=0 to n−2—the set of prefix population counts.
The counting of the number of “1”s is done in parallel by the Parallel Prefix Population Count operation, while the rotation is done by the LROTC operation at each stage. The full decoding algorithm (which could be performed in hardware or software) is given below:













 Algorithm 1:
To generate the nlg(n)/2 inverse butterfly (or butterfly) 



control bits from the n-bit mask.


 Input: 
mask; the pex (or pdep) bitmask


 Output:
ibcb; the lg(n) × n/2 matrix containing the inverse 



butterfly control bits



bcb; the lg(n) × n/2 matrix containing the 



butterfly control bits







 Let x∥y indicate the concatenation of bit patterns x and y. 


PP_POPCNT(a) is the parallel prefix population count of “1”s 


in bitfield a. mask{h:v} is the bitfield from bit h to bit v of the mask. 


1k indicates a bit-string of k ones. LROTC(a, rot) is a “left rotate and 


complement on wrap” operation, where a is the input and rot is the 


rotation amount.


 1. Calculate the prefix population counts:


  For i = 1, 2, . . . , n − 2


   pc[i] = PP_POPCNT(mask{i:0})


 2. Calculate the inverse butterfly (and butterfly) control bits for


  each stage by performing LROTC(0k, pc[m]), where k is the size 


  of the local R and m is the set of the leftmost bit positions of 


  the local R's:


  ibcb = bcb = { }








  For i = 1, . . . , lg(n)
//for each stage


   k = n/2i
//number of bits in local R


   For j = 1, 3, 5, . . . 2i − 1
//for each local R










m = j × k − 1
//the leftmost bit position of the local R









temp = LROTC(1k, pc[m])










ibcb[lg(n) − i + 1] = 
//for inverse butterfly datapath



temp ∥ ibcb[lg(n) − i + 1]




bcb[i] = temp ∥ bcb[i]
//for butterfly datapath









FIG. 16 is a block diagram showing the parallel extract decoder in accordance with the present invention, indicated generally at 70. The decoder 70 includes a parallel prefix population counter 72, thirty-two 1-bit LROTC operation module 73, sixteen 2-bit LROTC operation module 74, eight 4-bit LROTC operation module 76, four 8-bit LROTC operation module 78, two 16-bit LROTC operation module 80, and one 32-bit LROTC operation muddle 82. The decoder 70 operates in accordance with Algorithm 1. The decoder 70 can be used for pdep, except that the ordering of the resulting sets of n/2 control bits for the lg(n) stages is reversed.
It is noted that three classes of parallel extract and parallel deposit instructions can be handled by the present invention. The first consists of static versions of these instructions, where software or the compiler “pre-decodes” the mask in the second source register into control bits for the datapath, and moves the control bits into the Application Registers (ARs), or any registers that may be used to control the ibfly circuit. This uses the mov instruction in Table 1, followed by the pex or pdep instructions. The second class is dynamic mask decoding by a hardware implementation of the decoder of FIG. 16. This uses the pex.v or pdep.v instructions in Table 1. The third class is loop-invariant pex and pdep. Here, the mask is known only at runtime but remains fixed for a long input stream. The hardware decoder of FIG. 16 can output the control bits to the application registers once, and subsequently the static versions of pex and pdep are used. This uses the setib and setb instructions in Table 1, followed by static pex or pdep instructions.
FIG. 17A is a block diagram showing a shift-permute functional unit 90 in accordance with the present invention. The unit 90 supports instructions of existing microprocessors, such as the instructions listed in the top-half of Table 1 above. The unit 90 includes an n-bit inverse butterfly circuit 96 (n being the desired bit width), n 2:1 multiplexers 98, a control bit generator 100 (which contains the control circuit discussed above in connection with FIG. 13), and a masked merge unit 102 (which generates the merge bits and mask control for the extra multiplexer stage). Processing results are transmitted to a microprocessor using a result bus 108.
FIG. 17B is a block diagram showing another embodiment of the shift-permute functional unit of the present invention, indicated generally at 110. The unit 110 includes the same n-bit inverse butterfly circuit 96, n 2:1 multiplexers 98 and 104, and masked merge unit 102 as the unit 90 shown in FIG. 17A, in addition to n 2:1 multiplexers 92, AND gate 94, a modified control bit generator 101, and an n-bit butterfly circuit 106. A pex/pdep decoder (shown in FIG. 18A, discussed below) is provided, within the control bit generator 101. The shift-permute functional unit 110 can support all the instructions listed above in connection with Table 1. For the grp instruction to also be supported, a second inverse butterfly circuit and a second decoder would be required. However, the bfly and ibfly instructions can be used to achieve permutations and pex can be used to emulate grp, thereby obviating the need for a second inverse butterfly circuit and decoder. The last 4 instructions in Table 1 are needed only if dynamic and loop-invariant variants of the pex and pdep instructions are implemented. Note that the control bits fed to the butterfly circuit 106 are reversed left-to-right and also reversed top to bottom in terms of the order of the control bits for the stages. Also note that the butterfly circuit 106 is considered optional (and shown in phantom) as the functionality can be emulated using the inverse butterfly circuit at the cost of some performance. One pass of the butterfly circuit can be emulated with at most lg(n) passes of the inverse butterfly circuit. Also, the latency of the control bit generation is serialized with respect to the latency of the butterfly circuit, since the control bits that take longest to generate are needed to control the first stage of the butterfly circuit, which is the last stage of the inverse butterfly circuit. Thus, the inverse butterfly datapath is faster, since its control bit generation latency is overlapped with its datapath latency.
FIG. 18A is a diagram showing the control bit generator 100 of FIG. 17A in greater detail. The control bits are provided by a rotation control bit generator 126 (see FIG. 13), which is controlled by a 2:1 multiplexer 130.
FIG. 18B is a diagram showing the control bit generator 101 of FIG. 17B in greater detail. The source of the control bits can be from the rotation control bit generator 126 (see FIG. 13), a pex/pdep decoder 122 (see FIG. 16), or application registers 128. The pex/pdep decoder 122 supplies the bits for the dynamic pex and pdep operations. This block is consider optional, as the pex/pdep decoder 122 is large and has long latency (2 cycles), and is only needed for variable pex.v or pdep.v instructions which are rarely used. Hence, it is shown in phantom. The rotation control bit generator 126 is extended to produce cblg(n). The shift amount is s for right rotates, right shifts, mix_left (the left subwords are shifted right in the second operand) and extracts; it is n−s for left rotates, left shifts, mix_right and deposits. Also, output is f(s, lg(n)) to the masked-merge block for use in computing the masked-merge controls. The final source of the control bits is from the application registers for use in the bfly and ibfly permutation instructions or static pex and pdep instructions. Multiplexers 124 and 130 are also provided.
The merge and mask control bits implemented by masked merge unit 102 of FIGS. 17A and 17B include those summarized in Table 2 above. The merge bits can be:

    
    
        the zero string for unsigned right shift, left shift, unsigned extract, deposit-and-zero, and parallel deposit;
        the sign bit for arithmetic right shift;
        the sign bit of the extracted field (bit pos+len−1 of the source operand) for signed extract; or
        the second source operand r3 for deposit-and-merge and mix.

The mask control bits are “0” when selecting the rotated bits output from the butterfly or inverse butterfly circuit and “1” when selecting the merge bits. The patterns are:

        the zero string for right and left rotate, bfly and ibfly permutation instructions and parallel extract (which do not merge bits);
        the second source operand r3 for parallel deposit; or
        various strings of “1”s and “0”s for shifts, extract, deposit and mix.
    
    


Table 3 below presents a high level comparison of the present invention to known barrel and log shifter designs:











TABLE 3







Barrel Shifter
Log Shifter
Our IBFLY Shifter



















# Elements
n2
n × lg(n) or
n × lg(n)




n × log4(n)


# Control
n
lg(n)
n/2 × lg(n)


Lines


Gate delay
1
lg(n) or
lg(n)


(Datapath)

log4(n)


Mux width
n
2 or 4
2


(Capacitance)









The first two lines of Table 3 contain the components that contribute to circuit area. Both the log shifter and the inverse butterfly version of the present invention have n×lg(n) elements, while the barrel shifter has n2 elements. The log shifter also has the fewest control lines (lg(n)) while the present invention has the most as each switch, or pair of elements, requires an independent control bit. The next two lines pertain to latency. The datapath of the barrel shifter has a single gate delay while the log shifter and the present invention have lg(n) gate delay. However, both the log shifter and the present invention utilize narrow multiplexers with lower capacitance at output nodes.
The method of logical effort was first used to compare the delay along the critical paths for the barrel shifter, the log shifter, and the inverse butterfly shifter. This estimated the critical path in terms of FO4 gate equivalents, which is the delay of an inverter driving 4 similar inverters. The latency of only the basic shifter operations on these datapaths was compared. As the 64-bit barrel shifter is impractical due to the capacitance on the output lines, a 64-bit shifter was implemented as an 8-byte barrel shifter followed by an 8-bit barrel shifter, which limits the number of transmission gates tied together to 8. The delay only from the input to the decoder through the two shifter levels for the barrel shifter and through the three shifter levels for the log shifter was considered.
For the present invention, the delay from the input to the control bit generator (i.e., the rotation control bit generator of FIG. 13) through the output of the inverse butterfly circuit was considered. According to the logical effort calculations, the delay for the barrel shifter is 15.1 FO4 and the delay for the log shifter is 13.0 FO4, while the delay for inverse butterfly shifter is 15.5 FO4. Thus, the delay along the critical path for the barrel shifter and the present invention is comparable, and the present invention is 19% slower than a log shifter. Note that this is only a rough estimation of delay along the critical path without circuit optimization. Custom circuit design of the present invention will result in a much faster circuit.
Since the log shifter is the faster and more compact of the two current shifter designs, it was implemented for testing purposes along with the present invention, using a standard cell library. All designs were synthesized to gate level, optimizing for shortest latency, using Design Compiler mapping to a TSMC 90 nm standard cell library. The results are summarized in Tables 4-6 below.











TABLE 4





Functional
Latency
Relative
Area
Relative


Unit
(ns)
Latency
(NAND gates)
Area



















Log Shifter
0.30
1
6.2K
1


Our
0.35
1.18
4.3K
0.69


IBFLY shifter


ALU
0.38
1.27
8.2K
1.31









Table 4 shows the result of a basic shifter that only implements shift and rotate instructions. For the log shifter, parallel datapaths were implemented for left and right shifts. The present invention has 1.18×the latency of the log shifter, which is similar to the logical effort calculation. The present invention is also smaller than the log shifter, at approximately 70% of the area (note that a single datapath log shifter would have smaller area; additionally, accounting for the wires will increase the area for the ibfly-based shifter relative to the log shifter, as mentioned). For comparison, we also implemented an ALU (supporting add, subtract, and, or, not, xor with register or immediate operands) synthesized using the same standard cell library. The present invention is faster (92% latency) and smaller (52% area) than this ALU.











TABLE 5





Functional
Latency
Relative
Area
Relative


Unit
(ns)
Latency
(NAND gates)
Area



















Log Shifter
0.41
1
6.2K
1


Our
0.42
1.03
5.3K
0.83


IBFLY shifter


ALU
0.40
0.99
6.6K
1.03









Table 5 shows the result when both shifter architectures are enhanced to support extract, deposit, and mix instructions. The critical path of the log shifter is now through the extract sign bit propagation, so the latency is now comparable to that of the inverse butterfly-based shifter of the present invention. The present invention is still only 83% of the area of the log shifter. The results for an ALU of similar latency are also included (which has a comparable circuit area, in NAND gate equivalents).











TABLE 6





Functional
Latency
Relative
Area
Relative


Unit
(ns)
Latency
(NAND gates)
Area



















Log Shifter
0.41
1
6.4K
1


ibfly, pex
0.48
1.18
8.2K
1.29





(1.2K for ARs)


ibfly, bfly,
0.49
1.20
11.9K
1.87


pex, pdep


(2.5K for ARs)


bfly, pdep
0.48
1.19
3.6K
0.57


(no snifter)


(1.5K for ARs)


ALU
0.49
1.20
5.3K
0.83









Table 6 shows the results when support is added to the present invention for advanced bit manipulation operations, but not to the log-shifter. The first line in table 6 represents the log shifter circuit from Table 5, included as the baseline. The second line is a unit that supports the ibfly and static pex instructions. The functionality of the butterfly circuit can be emulated using inverse butterfly, albeit with a multi-cycle penalty. The latency increases are due to extra multiplexing for the control bits and output. The area increases due to the ARs, the extra multiplexers, and the pex masking. This unit has 1.18× the latency and 1.29× the area of the log shifter. The third line in Table 6 is a unit that also supports butterfly and static pdep. The latency increases slightly due to output multiplexing and the area increases due to the second (butterfly) datapath and second set of three ARs. This unit has 1.20× the latency and 1.87× the area of the log shifter. Alternatively, a separate unit can be added to perform just bfly and pdep (line 4 in Table 6), thereby enabling simultaneous superscalar execution with the ibfly-pex-shifter unit (line 2 in Table 6). It can be seen that the shift-permute unit of the present invention (line 3 in Table 6) can be split into two units at no additional increase in area. The results for an ALU of similar latency are also included, wherein the ALU is smaller than the log shifter due to the relaxed latency constraint. The shift-permute unit (line 3) now has 2.25× the area of the ALU, but smaller sizes are possible.
FIGS. 19A-31 are diagrams showing implementation of a parallel deposit (pdep) operation using the butterfly circuit embodiment of the shifter circuit of the present invention. As illustrated in FIGS. 19A-30, a control bit of “0” indicates that a “swap” function is performed (i.e., a bit of information at a given position in one stage shifts to a different position at a subsequent stage), and a control bit of “1” indicates that a “pass-through” function is performed (i.e., a bit of information at a given position in one stage passes through to the same position at a subsequent stage). Of course, this could be reversed as desired (with appropriate changes to the underlying gate logic of the circuits), without departing from the spirit or scope of the present invention. For example, as shown in FIG. 10 discussed above, a control bit value of “1” corresponds to a swap function, while a control bit value of “0” corresponds to a pass-through function.
FIG. 19A illustrates left half (L) and right half (R) swapping procedures capable of being implemented by the present invention, at each stage of the butterfly circuit, as well as hierarchical subscript notation utilized for indicating respective swapping halves through the various circuit stages of a butterfly circuit. FIG. 19B shows an example pdep operation with mask=10101101. FIG. 20 shows this pdep operation broken down into steps on the butterfly circuit. In the first stage, we transfer from the right (R) to the left half (L) the bits whose destination is in L, namely bits d and e. Prior to stage 2, we right rotate e00d by 3, the number of bits that stayed in R, to right justify the bits in their original order, 00de, in the L half. Note that bits that stay in the right half, R, are already right-justified.
In each half of stage 2 we transfer from the local R to the local L the bits whose final destination is in the local L. So in R, we transfer g to RL and in L we transfer d to LL. Prior to stage 3, we right rotate the bits to right justify them in their original order in their new subnetworks. So d0 is right rotated by 1, the number of bits that stayed in LR, to yield 0d, and gf is right rotated by 1, the number of bits that stayed in RR, to yield fg.
In each subnetwork of stage 3 we again transfer from the local R to the local L the bits whose final destination is in the local L. So in LL we transfer d and in LR we transfer e. After stage 3 we have transferred each bit to its correct final destination: d0e0fg0h. Note that we use a control bit of “0” to indicate a swap, and a control bit of “1” to indicate a pass through operation. Rather than explicitly right rotating the data bits in the L half after each stage, we can compensate by modifying the control bits. This is shown in FIG. 21.
Provided below is an explanation as to how the pdep operation can be mapped to the butterfly circuit:
Fact 3: Any single data bit can be moved to any result position by moving it to the correct half of the intermediate result at every stage of the butterfly circuit.
This can be proved by induction on the number of stages. At stage 1, the data bit is moved within n/2 positions of its final position. At stage 2, it is moved within n/4 positions of its final result, and so on. At stage lg(n), it is moved within n/2lg(n)=1 position of its final result, which is its final result position. Referring back to FIG. 20, Fact 3 is utilized to decide which bits to keep in R and which to transfer from R to L at each stage.
Fact 4: If the mask has k “1”s in it, the k rightmost data bits are selected and moved, i.e., the selected data bits are contiguous. They never cross each other in the final result.
This fact is by definition of the pdep instruction. See the example of FIG. 19, where there are 5 “1”s in the mask and the selected data bits are the 5 rightmost bits, defgh; these bits are spread out to the left maintaining their original order, and thus never crossing each other in the result.
Fact 5: If a data bit in the right half (R) is swapped with its paired bit in the left half (L), then all selected data bits to the left of it will also be swapped to L (if they are in R) or stay in L (if they are in L).
Since the selected data bits never cross each other in the final result (Fact 4), once a bit swaps to L, the selected bits to the left of it must also go to L. Hence, if there is one “1” in the mask, the one selected data bit, d0, can go to R or L. If there are two “1”s in the mask, the two selected data bits, d1d0, can go to RR or LR or LL. That is, if the data bit on the right stays in R, then the next data bit can go to R or L, but if the data bit on the right goes to L, the next data bit must also go to L. If there are three “1”s, the three selected data bits, d2d1d0, can go to RRR, LRR, LLR or LLL. For example, in stage 1 of FIG. 20, the five bits have the pattern LLRRR as e is transferred to L and d must then stay in L.
Fact 6: The selected data bits that have been swapped from R to L, or stayed in L, are all contiguous mod n/2 in L.
From Fact 5, the destinations of the k selected data bits dk-1 . . . d0 must be of the form L . . . LR . . . R, a string of zero or more L's followed by zero or more R's. Define X as the bits staying in R, Y as the bits going to L that start in R and Z as the bits going to L that start in L. It is possible that:

    
    
        i. X alone exists—when there are no selected data bits that go to L,
        ii. Y alone exists—when all bits that start in R go to L and there are no selected data bits that start in L and,
        iii. X and Y exist—when some bits that start in R stay in R and some go to L and there are no selected data bits that start in L and,
        iv. X and Z exist—when all the bits in R are going to R, and all bits going to L start in L, or
        v. X, Y and Z exist.
    
    


When X alone exists (i), there are no bits that go to L, so Fact 6 is irrelevant.
The structure of the butterfly circuit requires that when bits are moved in a stage, they all move by the same amount. Fact 4 states that the selected data bits are contiguous. Together these imply that when Y alone exists or X and Y exist (ii and iii), Y is moved as a contiguous block from R to L and Fact 6 is trivially true.
When X and Z exist (iv), Z is a contiguous block of bits that does not move so again Fact 6 is trivially true.
When X, Y and Z exist (v), Y comprises the leftmost bits of R, and Z the rightmost bits in L since they are contiguous across the midpoint of the stage (Fact 4). When Y is swapped to L, since the butterfly circuit moves the bits by an amount equal to the size of L or R in a given stage, Y becomes the leftmost bits of L. Thus Y and Z are now contiguous mod n/2, i.e., wrapped around, in L, as shown in FIG. 22. Thus, Fact 6 is true in all cases.
For example, in FIG. 20 at the input to stage 1, X is bits fgh, Y is bit e and Z is bit d. Y is the leftmost bit in R and Z is the rightmost bit in L. After stage 1, Y is the leftmost bit in L and is contiguous with Z mod 4, within L, i.e., de is contiguous mod 4 in e00d.
Fact 7: The selected data bits in L can be rotated so that they are the rightmost bits of L, and in their original order.
From Fact 6, the selected data bits are contiguous mod n/2 in L. At the output of stage 1 in FIG. 22, these bits are offset to the left by the size of X (the number of bits that stayed in R), denoted by |X|. Thus, if we explicitly rotate right the bits by |X|, the selected data bits in L are now the rightmost bits of L in their original order (see FIG. 22). In FIG. 20, Fact 7 was utilized prior to stages 2 and 3.
At the end of this step, we have two half-sized butterfly circuits, L and R, with the selected data bits right-aligned and in order in each of L and R (last row of FIG. 22). The above can now be repeated recursively for the half-sized butterfly circuits, L and R, until each L and R is a single bit. This is achieved after lg(n) stages of the butterfly circuit (see the final output in FIG. 20).
The selected data bits emerge from stage 1 in FIG. 22 rotated to the left by |X|. In Fact 7, the selected data are explicitly rotated bits back to the right by |X|. Instead, we can compensate for the rotation by modifying the control bits of the subsequent stages to limit the rotation within each subnetwork. For example, if the n-bit input to stage 1 is rotated by k positions, the two n/2-bit inputs to the L and R subnetworks are rotated by k (mod n/2) within each subnetwork. At the output of stage lg(n), the subnetworks are 1-bit wide so the rotations are absorbed.
Fact 8: If the data bits are rotated by x positions left (or right) at the input to a stage of a butterfly circuit, then at the output of that stage we can obtain a rotation left (or right) by x positions of each half of the output bits by rotating left (or right) the control bits by x positions and complementing upon wrap around.
Consider again the example of FIG. 20. The selected data bits emerge from stage 1 left rotated by 3 bits, i.e., L is e00d, left rotated by 3 positions from 00de. In FIG. 20, we explicitly rotated the data bits back to the right by 3. Instead, we can compensate for this left rotation by left rotating and complementing upon wrap around by 3 positions the control bits of the subsequent stages. This is shown in FIG. 23. For stage 2, the control bit pattern of L, after left rotate and complement by 3, becomes 01→11→10→00. The rotation by 3 is limited to a rotation by 3 mod 2=1 within each half of the output of L of stage 2. In FIG. 23, we show the explicit rotation of the output of stage 2 before it is input to stage 3 to transform from d0,0e in FIG. 20 to 0d,e0. For stage 3, the rotation and complement by 3 of the two single control bits in L become three successive complements: 0→1→0→1, and the left rotation of L is absorbed as the overall output is still d0e0. Hence, FIG. 23 shows how the control bits in stages 2 and 3 compensate for the left rotate by 3 bits at the output of stage 1 (compare with FIG. 20).
FIG. 21 shows the control bits after also compensating for the left rotate by 1 bit of RL and LL, prior to stage 3 in FIG. 23. The explicit right rotation prior to stage 3 is eliminated. Instead, the two control bits in RL and LL transform from 1→0 to absorb the rotation. The overall result in FIG. 21 remains the same as in FIG. 20, by compensating for the explicit data rotations in FIG. 20 with rotations of the control bits instead, complementing them on wraparound.
An explanation is now provided as to why the control bits are complemented when they wrap around. The goal is to keep the data bits in the half they were originally routed to at each stage of the butterfly circuit, in spite of the rotation of the input. FIG. 24 shows a pair of bits, a and b, that were originally passed through. It is desired to route a to L and b to R in spite of any rotation. As the bits are rotated (see FIG. 25), the control bit is rotated with them, keeping a in L and b in R, as desired. When the bits wrap around, (see FIG. 26), a wraps to R and b crosses the midpoint to L. If the control bit is simply rotated with the paired bits, then a is now passed through to R and b is passed through to L, which is contrary to the originally desired behavior. If instead the control bit is complemented when it wraps around (see FIG. 27), then a is swapped back to L and b is swapped back to R, as is desired.
Similarly, if a and b were originally swapped (see FIG. 28), a should be routed to R and b to L. As the bits rotate (see FIG. 29), we simply rotate the control bit with them. When the bits wrap around (see FIG. 30), input a wraps to R and b crosses to L. When they are swapped, a is routed to L and b to R, contrary to their original destinations. If the control bit is complemented on wraparound, a is passed through to R and b is passed through to L, conforming to the originally desired behavior.
Thus, complementing the control bit when it wraps (see FIG. 31) causes each of the pair of bits to stay in the half it was originally routed to despite the rotation of the input pushing each bit to the other half. This limits the rotation of the input to be within each half of the output and not across the entire output.
Provided below is a theorem to formalize the overall result:
Theorem 2: Any parallel deposit instruction on n bits can be implemented with one pass through a butterfly circuit of lg(n) stages without path conflicts (with the bits that are not selected zeroed out externally).
Proof: Assume there are k “1”s in the right half of the bit mask. Then, based on Fact 3, the k rightmost data bits (block X) must be kept in the right half (R) of the butterfly circuit and the remaining contiguous selected data bits must be swapped (block Y) or passed through (block Z) to the left half (L). This can be accomplished in stage 1 of the butterfly circuit by setting the k rightmost configuration bits to “1” (to pass through X and Z), and the configuration bits of the remaining selected bits to “0” (to swap Y).
At this point, the selected data bits in the right subnetwork (R) are right-aligned but those in the left subnetwork (L) are contiguous mod n/2, but not right aligned (Fact 4, FIG. 22); they are rotated left by the size of block X or the number of bits kept in R. We can compensate for the left rotation of the bits in L and determine the control bits for subsequent stages as if the bits in L were right aligned. This is accomplished by left rotating and complementing upon wraparound the control bits in the subsequent stages of L by the number of bits kept in R (once these control bits are determined pretending that the data bits in L are right aligned). Modifying the control bits in this manner will limit the rotation to be within each half of the output until the rotation is absorbed after the final stage (Fact 8).
Now the process above can be repeated on the left and right subnets, which are themselves butterfly networks: count the number of “1”s in the local right half of the mask and then keep that many bits in the right half of the subnetwork, and swap the remaining selected data bits to the left half Account for the rotation of the left half by modifying subsequent control bits. This can be repeated for each subnetwork in each subsequent stage until the final stage is reached, where the final parallel deposit result will have been achieved (see FIG. 21).
Various functional units can be constructed in accordance with the present invention, for implementing any desired combinations of parallel extract, parallel deposit, butterfly permutations, and inverse butterfly permutations. Examples of such functional units will now be discussed with reference to FIGS. 32-37.
FIG. 32 is a diagram showing a functional unit 140 in accordance with the present invention, which supports parallel deposit and butterfly permutation instructions. The unit 140 includes a butterfly circuit 146 and a masking stage (multiplexer 142 and AND gates 148) and extra register storage (registers 144) to hold the configuration for the butterfly circuit (FIG. 16 shows the control generation for a 64-bit functional unit with 6 stages). The masking stage zeroes the bits not selected in the pdep operation. For bfly, we use a mask of all “1”s. The extra registers 144 are associated with the functional unit and hold the control bits for the butterfly circuit. Some ISAs have pre-defined application registers that can be used as these extra registers: they are called special function registers in PA-RISC or application registers (ARs) in the Intel Itanium ISA. The functional unit 140 supports butterfly permutations since the application registers 144 can be explicitly loaded with the configuration for some permutation. Parallel deposit is also supported. The ARs 144 can be loaded with this configuration and then the input is permuted through the butterfly circuit 146; the bits that are not needed are then masked out using the bit mask that defines the desired parallel deposit operation.
FIG. 33 is a diagram showing another functional unit 150 in accordance with the present invention, based upon an inverse butterfly circuit. The functional unit 150 contains a masking stage (multiplexer 152 and AND gate 154) followed by an inverse butterfly circuit 158 and a set of application registers 156 to hold the configuration. The ARs 156 are loaded with the configuration for some inverse butterfly permutation or a parallel extract operation. For parallel extract we mask out the undesired bits with the bit mask and then we permute through the inverse butterfly circuit.
FIG. 34 is a diagram showing another functional unit 160 in accordance with the present invention, which includes butterfly and inverse butterfly circuits. The unit 160 can handle parallel extract, parallel deposit, butterfly permutations, and inverse butterfly permutations, and includes multiplexers 162 and 176, AND gates 164 and 174, application registers 166 and 172, inverse butterfly circuit 168, and butterfly circuit 170.
FIG. 35 is a diagram showing another functional unit 180 in accordance with the present invention, which is similar in construction to the functional unit 160 of FIG. 34 and includes a decoder 182 and associated multiplexers 190 and 198. Similar to the functional unit 160 of FIG. 34, the unit 180 includes multiplexers 184 and 194, AND gates 186 and 200, application registers 188 and 202, inverse butterfly circuit 192, and butterfly circuit 196. The unit 160 allows for static parallel deposit or parallel extract operations (i.e., operations where the control bits are calculated a priori by a programmer or a compiler). The unit 180 further allows for variable parallel deposit or parallel extract operations (i.e., where the control bits for the butterfly or inverse butterfly are calculated by the hardware decoder 182, dynamically during the program's execution, and not statically by the programmer or compiler). The input of the decoder 182 is the n-bit mask and the output is the set of n/2×lg(n) control bits for pdep or pex.
The decoder circuit 182 can be used for both pex and pdep with the caveat that the ordering of the stages that control bits are routed to is reversed (the circular arrow in FIG. 35 indicates reversing the stages).
FIG. 36 is a diagram showing another functional unit 210 in accordance with the present invention, which handles loop invariants. In loop invariant conditions, the configuration is only known at runtime but it is unchanging across many iterations of a loop. Similar to the functional unit 180 shown in FIG. 35, a decoder circuit 212 and associated multiplexers 220 and 232 are provided. Additional multiplexers 216 and 236 are provided, which allow for selective loading of a configuration for pex or pdep operations into the application registers 218 and 234. This has the advantage of removing the decoder from the critical path, thus decreasing latency for the subsequent pex or pdep instructions, and also possibly conserving power by shutting down the decoder circuitry. The other components of the functional unit 210 are similar to the functional units discussed above, and include multiplexers 214 and 226, AND gates 222 and 230, inverse butterfly circuit 224, and butterfly circuit 228.
FIG. 37 is a diagram showing another functional unit 240 in accordance with the present invention, which supports the grp permutation instruction. The grp permutation instruction is equivalent to a standard parallel extract ORed with a “parallel extract to the left” of the bits selected with “0”s. To provide this functionality, an additional decoder 242 is provided, as well as an additional AND gate 264 an OR gate 262, a secondary inverse butterfly circuit 266, and an additional multiplexer 258. The remaining components (i.e., decoder 244, multiplexers 246 and 260, AND gates 256 and 268, multiplexers 248, 252, 272, and 276, application registers 250 and 274, inverse butterfly circuit 254, and butterfly circuit 270) are identical to the components of the functional unit 210 shown in FIG. 36.
The various functional units discussed above in connection with FIGS. 32-37 can implement a wide variety of advanced bit manipulation instructions. Table 7 below summarizes these instructions, as well as the processor cycles required for each instruction. Note that Table 7 is similar to the bottom half of Table 1, with the addition of the grp instruction and associated cycle counts. A 64-bit word size, without loss of generality, is assumed:









TABLE 7





Instruction
Description
Cycles







bfly r1 = r2, ar.b1, ar.b2, ar.b3
Perform Butterfly permutation of data bits using controls in associated ARs
1


ibfly r1 = r2, ar.ib1, ar.ib2, ar.ib3
Perform Inverse Butterfly permutation of data bits using controls in associated ARs
1


pex r1 = r2, r3, ar.ib1, ar.ib2, ar.ib3
Parallel extract, static: Data bits in r2 selected by a mask r3 are extracted,
1



compressed and right-aligned in the result r1, using datapath controls which have



been pre-decoded from the mask and placed in the associated ARs


pdep r1 = r2, r3, ar.b1, ar.b2, ar.b3
Parallel deposit, static: Right-aligned data bits in r2 are deposited, in order, in result
1



r1 in bit positions marked with a “1” in the mask r3, which has been pre-decoded to



give datapath controls placed in the associated ARs.


mov ar.x = r2, r3
Move values from GRs to ARs, to set datapath controls (calculated by software) for
1



pex, pdep, bfly or ibfly


pex.v r1 = r2, r3
Parallel extract, variable: Data bits in r2 selected by a dynamically-decoded mask
3



r3 are extracted, compressed and right-aligned in the result r1.


pdep.v r1 = r2, r3
Parallel deposit, variable: Right-aligned data bits in r2 are deposited, in order, in
3



result r1 in bit positions marked with a “1” in the dynamically-decoded mask r3.


setib ar.ib1, ar.ib2, ar.ib3 = r3
Set inverse butterfly datapath controls in the associated ARs, using hardware
2



decoder to translate the mask r3 to inverse butterfly controls.


setb ar.b1, ar.b2, ar.b3 = r3
Set butterfly datapath controls in the associated ARs, using hardware decoder to
2



translate the mask r3 to butterfly controls.


grp r1 = r2, r3
Perform Group permutation (variable): Data bits in r2 corresponding to “1”s in r3
3



are grouped to the right, while those corresponding to “0”s are grouped to the left.









For bfly and ibfly, the data bits in GR r2 are permuted and placed in the destination register GR r1. Application registers ar.bi and ar.ibi, i=1, 2, 3, are used to hold the configuration bits for the butterfly or inverse butterfly datapath, respectively, and these registers must first be loaded by the mov_ar instruction. The mov_ar instruction in Table 7 is used to move the contents of two general-purpose registers to the application registers. The sub-opcode, x, indicates which application register, or pair of application registers, are written.
Static versions of pex and pdep are used when desired mask patterns are known at compile time. In the static version of the pex instruction, GR r2 is and'ed with mask GR r3, then permuted using inverse butterfly application registers ar.ib1-3, with the result placed in GR r1. For static pdep, GR r2 is permuted using butterfly application registers ar.b1-3, then and'ed with mask GR r3, with the result placed in GR r1.
Dynamic or variable versions of pex and pdep are used when desired mask patterns are only known at runtime. In the pex.v instruction, the data bits in GR r2 selected by the “1” bits in the mask GR r3 are placed, in the same order, in GR r1. In the pdep.v instruction, the right justified bits in GR r2 are placed in the same order in GR r1, in the positions selected by “1”s in mask GR r3. For both instructions, the mask r3 is translated dynamically by a decoder into control bits for an inverse butterfly or butterfly circuit.
Suppose the particular pattern of bit scatter or gather is determined at execution time, but this pattern remains the same over many iterations of a loop. This is referred to as a loop-invariant pex or pdep operation. The setib and setb instructions invoke a hardware decoder to dynamically translate the bitmask GR r3 to control bits for the datapath stages; these control bits are written to the inverse butterfly or butterfly application registers, respectively, for later use in static pex and pdep instructions. Table 7 also shows the grp instruction which can perform arbitrary n-bit permutations. It is noted that the grp instruction can be emulated by a short sequence of pex and Boolean instructions.
The last column of Table 7 shows the expected number of cycles taken for the execution of the instruction. All static instructions (with pre-loaded ARs) take a single cycle, comparable to the time taken for an add instruction. The hardware decoder takes about 2 cycles, hence the setib and setb instructions take 2 cycles each. The variable pex.v and pdep.v and grp instructions each take up to 3 cycles each because they have to go through the hardware decoder first and then incur some additional datapath latency through the inverse butterfly or butterfly circuits and the output multiplexers. It is noted that the cycle counts depend on what a given processor uses to determine the cycle time. Here, it is assumed, without loss of generality, that the latency of an ALU is used to determine the cycle time. Also, it is noted that these cycle counts can change depending on the circuit optimization performed.
Table 8 summarizes applications in which the present invention can be implemented. Check marks indicate definite usage, check marks in parenthesis indicate usage in alternative algorithms and question marks indicate potential usage. The use of the mov ar instruction is assumed (but not shown in Table 8) whenever the bfly, ibfly, or static pex and pdep instructions are used. Note that these are just representative applications and do not constrain the use of the proposed instructions and shifter circuits in other applications or in different ways in these applications.









TABLE 8









Instruction










bfly and
















Application
ibfly
pex
setib
pdep
setb
pex.v
pdep.v
grp


















Cryptology
✓
?
?
?
?
?
?
(✓)


Binary Compression

✓


Binary Decompression/Expansion



✓
















LSB Steganography
Encoding



✓
✓






Decoding

✓
✓















Binary Image Morphology

✓



(✓)


















Transfer Coding
Encoding



✓







Decoding

✓


Bioinformatics
Compression

✓



Reversal
✓



Translation



✓



Alignment

✓


Compressed Integers
Encoding



✓



Decoding

✓















Random Number Generation





✓









Table 8 shows that static pex and pdep are the most frequently used. The variable pdep.v is not used at all, and the variable pex.v is only used twice. The loop-invariant pex and pdep instructions, indicated by the use of setib and setb instructions, are only used for the LSB Steganography application. The grp instruction is only used in a block cipher.
FIG. 38 is a diagram showing a bit compression procedure capable of being carried out by the present invention. The ITANIUM IA-64 and IA-32 parallel compare instructions produce subword masks—the subwords for which the relationship is false contain all zeros and for which the relationship is true contain all ones. This representation is convenient for subsequent subword masking or merging. The SPARC VIS parallel compare instruction produces a bit mask of the results of the comparisons. This representation is convenient if some decision must be made based on the outcome of the multiple comparisons. Converting from the subword representation to the bitmask representation for k subwords requires k extract instructions to extract a bit from each subword and k−1 deposit instructions to concatenate the bits; a single static pex instruction accomplishes the same thing.
The SSE instruction pmovmskb serves a similar purpose; it creates an 8- or 16-bit mask from the most significant bit from each byte of a MMX or SSE register and stores the result in a general purpose register. However, pex offers greater flexibility than the fixed pmovmskb, allowing the mask, for example, to be derived from larger subwords, or from subwords of different sizes packed in the same register.
Similarly, binary image compression performed by MATLAB's bwpack function benefits from pex. Binary images in MATLAB are typically represented and processed as byte arrays—a byte represents a pixel and has permissible values 0x00 and 0x01. However, certain optimized algorithms are implemented for a bitmap representation, in which a single bit represents a pixel.
To produce one 64-bit output word requires only 8 static pex instructions to extract 8 bits in parallel from 8 bytes and 7 dep instructions to pack these eight 8-bit chunks into one output word (see FIG. 38). For decompression, as with the bwunpack function, only 7 extra instructions are required to pull out each byte and only 8 pdep instructions to scatter the bits of each byte to byte boundaries.
FIG. 39 shows a steganography procedure capable of being carried out by the present invention. Steganography refers to the hiding of a secret message by embedding it in a larger, innocuous cover message. A simple type of steganography is least significant bit (LSB) steganography in which the least significant bits of the color values of pixels in an image, or the intensity values of samples in a sound file, are replaced by secret message bits. LSB steganography encoding can use a pdep instruction to expand the secret message bits and place them at the least significant bit positions of every subword. Decoding uses a pex instruction to extract the least significant bits from each subword and reconstruct the secret message.
LSB steganography is an example of an application that utilizes the loop-invariant versions of the pex and pdep instructions. The sample size and the number of bits replaced are not known at compile time, but they are constant across a single message. FIG. 39 depicts an example LSB steganography encoding operation in which the 4 least significant bits from each 16-bit sample of PCM encoded audio is replaced with secret message bits.
FIG. 40 shows a binary image morphology procedure capable of being carried out by the present invention. Binary image morphology is a collection of techniques for binary image processing such as erosion, dilation, opening, closing, thickening, thinning, etc. The bwmorph function in MATLAB implements these techniques primarily through one or more table lookups applied to the 3×3 neighborhood surrounding each pixel (i.e. the value of 9 pixels is used as index into a 512 entry table). In its current implementation, bwmorph processes byte array binary images, not bitmap images, possibly due to the difficulty in extracting the neighborhoods in the bitmap form.
If the images are processed in bitmap form, a single pex instruction extracts the entire index at once (assuming a 64-bit word contains an 8×8 block of 1-bit pixels, illustrated at 290 in FIG. 40). As the algorithm steps through the pixels, the neighborhood moves (illustrated at 292 in FIG. 40). This means that the bitmask for extracting the neighborhood is shifted and a dynamic pex.v instruction may be needed. Alternatively, the data might be shifted, rather than the mask, such that the desired neighborhood always exists in a particular set of bit positions. In this case, the mask is fixed, and only a static pex is needed. Table 8 indicates the latter—with pex indicated by a check mark and pex.v in parenthesis for the alternative algorithm.
FIG. 41 shows a transfer coding procedure capable of being carried out by the present invention. Transfer coding is the term applied when arbitrary binary data is transformed to a text string for safe transmission using a protocol that expects only text as its payload. Uuencoding is one such encoding originally used for transferring binary data over email or usenet. In uuencoding, each set of 6 bits is aligned on a byte boundary and 32 is added to each value to ensure the result is in the range of the ASCII printable characters. Without pdep, each field is individually extracted and has the value 32 added to it. With pdep, 8 fields are aligned at once and a parallel add instruction adds 32 to each byte simultaneously (FIG. 41 shows 4 parallel fields). Similarly, for decoding, a parallel subtract instruct deducts 32 from each byte and then a single pex compresses eight 6-bit fields.
FIGS. 42-44 show sample bioinformatics operations which are capable of being carried out by the present invention. Pattern matching and bit scatter/gather operations are also found in bioinformatics—the field of analysis of genetic information. DNA, the genetic code contained within the nucleus of each cell, is a strand of the nucleotide bases adenine, cytosine, guanine, and thymine. These bases are typically represented by an ASCII string using the 8-bit characters A, C, G and T. However, a 2-bit encoding of the nucleotides is more efficient and can significantly increase performance of matching and searching operations on large genomic sequences (the human genome contains 3.2 billion nucleotides). The ASCII codes for the characters A, C, G and T differ in bit positions 2 and 1 (A: 00, C: 01, G: 11, T: 10) and these two bits can be used to encode each nucleotide. Thus, a fourfold compression of a genomic sequence simply requires a single pex instruction to select bits 2 and 1 of each byte of a word (see FIG. 42).
A strand of DNA is a double helix—there are really two strands with the complementary nucleotides, A⇄T and C⇄G, aligned. When performing analysis on a DNA string, often the complementary string is analyzed as well. To obtain the complementary string, the bases are complemented and the entire string is reversed, as the complement string is read from the other end. The reversal of the DNA string amounts to a reversal of the ordering of the pairs of bits in a word. This is a straightforward bfly or ibfly permutation.
The DNA sequence is transcribed by the cell into a sequence of amino acids or a protein. Often, the analysis of the genetic data is more accurate when performed on a protein basis, such as is done by the BLASTX program. A set of three bases, or 6 bits of data, corresponds to a protein codon. Translating the nucleotides to a codon requires a table lookup operation using each set of 6 bits as an index. An efficient algorithm can use pdep to distribute eight 6-bit fields on byte boundaries, and then use the result as a set of table indices for a parallel table lookup (ptlu) instruction to translate the bytes, as shown in FIG. 43. A parallel table lookup instruction takes as input a word consisting of packed indices, each index being used to read out an entry of a table. For example, with a 32 bit register word, and tables each of which have 256 entries, 8 bit indices can be packed into the word to read out 4 different tables in parallel. These 4 results can be used immediately as in FIG. 43, or they can be combined by combinatorial logic to provide one result word which can then be stored back into the processor's register file. The pdep instruction of the present invention is used in FIG. 43 to expand bits from a bit string into the 8 bit indices used for the parallel table lookup. Also, the pex instruction of the present invention could be utilized to implement retrieving the packed indices for the operand input for such a parallel table lookup instruction.
For example, to match a pattern comprising many features where “1” indicates a match and “0” indicates no match, arbitrary subsets of the binary “1's” can be efficiently collected and compressed with this parallel extract instruction. The resulting compressed bits can be used as indices into the parallel table lookup instruction. This enables very fast action depending on which patterns are matched.
When aligning two DNA sequences, certain algorithms such as the known BLASTZ program use a “spaced seed” as the basis of the comparisons. This means that n out of m nucleotides are used to start a comparison rather than a string of n consecutive nucleotides. The remaining slots effectively function as wild cards, often causing the comparison to yield better results. For example, BLASTZ uses 12 of 19 (or 14 of 22 nucleotides) as the seed for comparison. The program compresses the 12 bases and uses the seed as an index into a hash table. This compression is a pex operation selecting 24 of 38 bits, as illustrated in FIG. 44.
FIG. 45 shows an integer compression technique capable of being carried out by the present invention. Internet search engine databases, such as Google's, consist of lists of integers describing frequency and positions of query terms. These databases are compressed to minimize storage space, memory bus traffic and cache usage. To support fast random access into these databases, integer compression—using less than four bytes to represent an integer—is utilized. One integer compression scheme is a variable byte encoding in which each byte contains 7 data bits and a flag bit indicating whether the current byte is an intermediate part of the current integer (flag=“0”) or ends the current integer (flag=“1”). Pex can accelerate the decoding of integers by compacting 7-bit fields from each byte (FIG. 45), and pdep can speedup encoding by placing consecutive 7-bit chunks of an integer on byte boundaries.
The present invention can also be used in random number generation and cryptology applications. Random numbers are very important in cryptographic computations for generating nonces, keys, random values, etc. Random number generators contain a source of randomness (such as a thermal noise generator) and a randomness extractor that transforms the randomness so that it has a uniform distribution. The INTEL random number generator uses a von Neumann extractor. This extractor breaks the input random bits, X=x1x2x3 . . . , into a sequence of pairs. If the bits in the pair differ, the first bit is output. If the bits are the same, nothing is output. This operation is equivalent to using a pex.v instruction on each word X from the randomness pool with the mask:

Mask=x1⊕x2∥0∥x3⊕x4∥0∥  (21)

or equivalently,

Mask=(X⊕(X<<1))& 0xAAA . . . A.  (22)

A number of popular ciphers, such as DES, have permutations as primitive operations. Inclusion of permutation instructions such as bfly, ibfly (or grp) can greatly improve the performance of the inner loop of these functions. Also, these instructions can be used as powerful primitive operations in the design of the next generation of ciphers and hash functions (especially for the Cryptographic Hash Algorithm Competition (SHA-3)). Since all the pex and pdep instructions—static, loop-invariant and variable—are also very likely to be useful for cryptanalysis algorithms, they are indicated as “?” in Table 8.
Kernels for the above binary compression and decompression, steganography, transfer coding, bioinformatics translate, integer compression, and random number generation applications were coded and simulated using the SimpleScalar Alpha simulator enhanced to recognize our new instructions. The latencies of the instructions in the simulator are as given in Table 7. FIG. 46 shows performance results, normalized to the baseline Alpha ISA cycle counts. The processor with pex and pdep instructions exhibits speedups over the base ISA ranging from 1.13× to 10.04×, with an average of 2.29×(1.94× excluding the mg benchmark).
Random number generation exhibited the greatest speedup due to the fact that a variable pex.v operation is performed. A single pex.v instruction replaces a very long sequence of instructions that loops through the data and mask and conditionally shifts each bit of the input to the correct position of the output based on whether the corresponding bit of the mask is ‘0’ or ‘1’. Of the benchmarks for static pex and pdep, the simple bit compression and decompression functions exhibited the greatest speedup as these operations combine many basic instructions into one pex or pdep. The speedup is lower in the steganography encoding case because there are only 4 fields per word, and also in the uudecode and BLASTX translate case because there are fewer fields overall. The lowest speedups were for integer compression cases as a smaller fraction of the runtime is spent on compression or decompressing bit fields.
To evaluate the cost of implementing the advanced bit manipulation functional units described above in connection with FIGS. 32-37, it is necessary to understand the implementation of the major components in such a functional unit. The most complex component is the hardware decoder that takes a register value (representing a bitmask) and turns it into the control bits of the stages of the butterfly or inverse butterfly datapath. Therefore, in order to evaluate the functional unit circuit latency and area, we must first define what is contained within the hardware decoder component. Provided below is an algorithm to obtain the n/2×lg(n) butterfly or inverse butterfly control bits from the n-bit pdep or pex bitmask. A hardware decoder circuit can then be constructed which implements this algorithm. In the case of static pex or pdep instructions, the algorithm can be used by the compiler to generate the control bits for the inverse butterfly or butterfly datapath. In the case of dynamic or loop-invariant pex and pdep instructions, the hardware decoder is used.
The steps in the proof to Theorem 2 give an outline for how to decode the n-bit bitmask into controls for each stage of a butterfly datapath. For each right half of a stage of a subnetwork, we count the number of “1”s in that local right half of the mask, say k “1”s, and then set the k rightmost control bits to “1”s and the remaining bits to “0”s. This serves to keep block X in the local. R half and export Y to the local L half We then assume that we explicitly rotate Y and Z to be the rightmost bits in order in the local L half. Then, we iterate through the stages and come up with an initial set of control bits. After this, we eliminate the need for explicit rotations of Y and Z by modifying the control bits instead. This is accomplished by a left rotate and complement upon wrap around (LROTC) operation, rotating the control bits by the same amount obtained when assuming explicit rotations.
This process can be considerably simplified, as follows. First, note that when we modify control bits to compensate for a rotation in a given stage, we do so by propagating the rotation through all the subsequent stages. This means that when the control bits of a local L are modified, they are rotated and complemented upon wrap around by the number of “1”s in the local R, and by the number of “1”s in the local R of the preceding stage, and by the number of “1”s in all the local R′s of all preceding stages up to the R in the first stage. In other words, the control bits of the local L are rotated by the total number of “1”s to its right in the bitmask.
Consider the example of FIG. 20. The control bit in stage 3 in the LL subnetwork is initially a “0” when we assumed explicit rotations. We first rotated and complemented this bit by 3, the number of “1”s in R of the bitmask: 0→1→0→1 (FIG. 23). We then rotated and complemented this bit by another 1 position, the number of “1”s in LR of the bitmask: 1→0. This yielded the final control bit in FIG. 21. Overall we rotated this bit by 4, the total number of “1”s to the right of LL or to the right of bit position 6. This is a Parallel Prefix Population Count (PP_PP_POPCNT) of the bitstring from the rightmost bit to bit position 6.
Second, it is necessary to produce a string of k “1”s from a count (in binary) of k, to derive the initial control bits assuming explicit rotations. This can also be done with a LROTC operation, as illustrated in FIG. 47. We start with a zero string of the correct length and then for every position in the rotation, and we wrap around a “0” from the left and complement it to get a “1” on the right. The end result, after a LROTC by k bits, is a string of the correct length with k rightmost bits set to “1” and the rest set to “0”.
It is possible to combine these two facts: the initial control bits are obtained by a LROTC of a zero string the length of the local R by the PP_POPCNT of the bits in the bitmask in the local R and all bits to the right of it. We denote a string of k “0”s as 0k. We specify a bitfield from bit h to bit v as {h:v}, where v is to the right of h. So,

    
    
        for stage 1, we calculate the control bits as LROTC(0n/2, PP_POPCNT(mask{n/2-1:0})),
        for stage 2, we calculate the control bits as LROTC(0n/4, PP_POPCNT(mask{3n/4-1:0})) for L and LROTC(0n/4, PP_POPCNT(mask{n/4-1:0})) for R,
        for stage 3, we calculate the control bits as LROTC(0n/8, PP_POPCNT(mask{7n/8-1:0})) for LL, LROTC(0n/8, PP_POPCNT(mask{5n/8-1:0})) for LR, LROTC(0n/8, PP_POPCNT(mask{3n/8-1:0})) for RL and LROTC(0n/8, PP_POPCNT(mask{n/8-1:01})) for RR,

and so on for the later stages.

    
    


Verification of the correctness of this approach is provided with reference to FIG. 21 as follows:

    
    
        for stage 1, the control bits are LROTC(04, PP_POPCNT(“1101”))=LROTC(04, 3)=0111,
        for stage 2, the control bits of L are LROTC(02, PP_POPCNT(“101101”))=LROTC(02, 4)=00 and
        the control bits of R are LROTC(02, PP_POPCNT(“01”))=LROTC(02, 1)=01,
        for stage 3, the control bit of LL are LROTC(01, PPPOPCNT(“0101101”))=LROTC(01, 4)=0,
        the control bit of LR is LROTC(01, PP_POPCNT(“01101”))=LROTC(01, 3)=1,
        the control bit of RL is LROTC(01, PP_POPCNT(“101”))=LROTC(01, 2)=0 and
        the control bit of RR is LROTC(01, PP_POPCNT(“1”))=LROTC(01, 1)=1.

This agrees with the result shown in FIG. 21.

    
    


One interesting point is that, for stage 1, the population count of the odd multiples of n/21 bits is needed, for stage 2 the population counts of the odd multiples of n/22 bits is needed, for stage 3 the population counts of the odd multiples of n/23 bits is needed, and so on. Overall, the counts are needed of the k rightmost bits, for k=0 to n−2. Such counts can be provided using the prefix population counter of the present invention, discussed above.
The control bits for the inverse butterfly for a pdep or a pex operation can be obtained using Algorithm 1, with the one caveat that the controls for stage i of the butterfly datapath are routed to stage lg(n)−i+1 in the inverse butterfly datapath. This can be shown using an approach similar to that shown earlier, except for working backwards from the final stage. Algorithm 1 decites the n mask bits into the nlg(n)/2 control bits for pdep and pex.
The execution time of Algorithm 1 in software is approximately 1200 cycles on an Intel Pentium-D processor. This software routine is useful for static pex or pdep operations and perhaps for loop invariant pex or pdep if the amount of processing in the loop dwarfs the 1200 cycle execution time. However, for dynamic pex.v and pdep.v a hardware decoder is required which implements Algorithm 1 in order to achieve a high performance. Fortunately, Algorithm 1 just contains two basic operations, population_count and LROTC, both of which have straightforward hardware implementations.
The first stage of the decoder is the parallel prefix population counter, discussed above. This is a circuit that computes in parallel all the population counts of step 1 of Algorithm 1. The circuit is a parallel prefix network with each node performing carry-save addition (i.e. a set of full adders). The counters resemble carry shower counters in which the inputs are grouped into sets of three lines which are input into full adders. The sum and carry outputs of the full adders are each grouped into sets of three lines which are input to another stage of full adders and so on. The parallel prefix architecture resembles radix-3 Han-Carlson, a parallel prefix look-ahead carry adder that has lg(n)+1 stages with carries propagated to the odd positions in the extra final stage. The radix-3 nature stems from the carry shower counter design, as we group 3 lines to input to a full adder at each level. The similarity to Han-Carlson is due to the 1- and 2-bit counts being deferred to the end, similar to odd carries being deferred in the Han-Carlson adder. Thus, the counter has log3(n)+2 stages. FIG. 48 depicts a dot diagram of the parallel prefix network.
One simplification of the counter is based on the properties of rotations—that they are invariant when the rotation amount differs by the period of rotation. Thus, for the ith stage of the butterfly network, the PP_POPCNTs are only computed mod n/2i-1. For example, for the 64-bit hardware decoder, for the 32 butterfly stage 6 PP_POPCNTs corresponding to the odd multiples of n/64, it is necessary only compute the PP_POPCNTs mod 2—only the least significant bit; for the 16 butterfly stage 5 PP_POPCNTs, we need only compute the PP_POPCNTs mod 4—the two least significant bits; and so on. Only the PP_POPCNT of 32 bits for stage 1 requires the full lg(n)-bit PP_POPCNT.
FIGS. 49-50 are circuit diagrams showing Left Rotate and Complement (LROTC) circuits according to the present invention. The outputs from the population counter control the LROTC circuits, one for each local R of each stage. Each LROTC circuit is realized as a barrel rotator modified to complement the bits that wrap around (see FIG. 49). However, while a standard 2m-bit rotator has m stages and control bits, this rotator has m+1 stages and control bits. As shown in FIG. 49, the final stage selects between its input and the complement, as the bits wrap 2m positions. Propagating the constants at the input greatly simplifies the circuit as shown in FIG. 50 (see Algorithm 1—it is possible to calculate LROTC(1k, count)).
The outputs from the decoders shown in FIGS. 49-50 can be routed to the butterfly circuit and its application registers, and can be used for controls for butterfly circuit to perform the pdep instruction. Additionally, the outputs are routed to the inverse butterfly circuit and its application registers, reversing the order of the stages, to be used for the pex instruction.
The functional units shown in FIGS. 34, 36, and 37 were tested for timing and circuit area. These functional units support static pex and pdep only (FIG. 34), loop invariant and dynamic pex.v and pdep.v as well (FIG. 36), and grp as well (FIG. 37). All three also support bfly and ibfly permutation instructions. The circuits in FIGS. 36-37 are implemented with a 3-stage pipeline. The hardware decoder occupies the first 2 pipeline stages due to its slow parallel prefix population counter. The butterfly (or inverse butterfly) circuit is in the third stage.
The various functional units were coded in Verilog and synthesized using Synopsys Design Compiler mapping to a TSMC 90 nm standard cell library. The designs were compiled to optimize timing. The decoder circuit was initially compiled as one stage and then Design Compiler automatically pipelined the subcircuit. Timing and area figures are as reported by Design Compiler. We also synthesized a reference ALU using the same technology library as a reference for latency and area comparisons.
Table 9 below summarizes the timing and area for the circuits. This shows that the 64-bit functional unit in FIG. 16 supporting static pex and pdep has a shorter latency than that of a 64-bit ALU and about 90% of its area (in NAND-gate equivalents). However, to support variable and loop-invariant pex and pdep (as in FIG. 36), which requires a hardware decoder (as described in detail above), the advanced bit manipulation functional unit will be 16% slower than an ALU and 2.25× larger. To also support a fast implementation of the grp instruction, the proposed new unit will be 23% slower than an ALU and about 3.2× larger in area.











TABLE 9






Cycle
Relative
Area (NAND
Relative


Unit
time
cycle time
gate equiv.)
Area



















ALU
0.50 ns
1
 7.5K
1


FIG. 34:
0.48 as
0.95
 6.8K
0.90


pex, pdep


FIG. 36:
0.58 ns
1.16
16.9K
2.25


pex.v, pdep.v


FIG. 37: grp
0.62 ns
1.23
24.2K
3.22









Table 10 shows the number of different circuit types, to give a sense for why the functional units supporting variable pex.v, pdep.v and grp are so much larger. It shows that supporting variable operations comes at a high price. The added complexity is due to the complex decoder combinational logic and to the additional pipeline registers and multiplexer logic. This explains why in Table 10, the variable circuits (FIGS. 36-37) have approximately 22-29% longer cycle time latencies compared to the static case (FIG. 34), due to the decoder complexity and pipeline overhead. They are also 2.5 to 3.6 times larger than the static case.











TABLE 10







Butterfly and





Pipeline
Inverse Butterfly


Unit
Registers
Circuits
Decoders
MUXes



















FIG. 34
0
2
0
1


FIG. 36
~9.25
2
1
13


FIG. 37
~14.5
3
2
14









FIG. 51 is a circuit diagram showing a 64-bit-wide inverse butterfly circuit implemented in accordance with the present invention, indicated generally at 300. The circuit 300 can be implemented in a shifter circuit of a processor to perform the complex bit manipulation procedures discussed herein.
FIG. 52 is a block diagram showing a sample microprocessor architecture, indicated generally at 310, in which the present invention could be implemented. The microprocessor 310 includes a register file 320, an arithmetic-logic unit (ALU) 322, and a shifter unit 324. The shifter unit 324 corresponds to one or more of the shifter circuits of the present invention.
Having thus described the invention in detail, it is to be understood that the foregoing description is not intended to limit the spirit or scope thereof. What is desired to be protected is set forth in the following claims.

## Claims

1. A shifter circuit for a processor, comprising:
means for obtaining a word in a processor;
an inverse butterfly circuit connected to said means for obtaining the word, the inverse butterfly circuit including a plurality of circuit stages, each of the circuit stages including a plurality of multiplexers;
a control circuit in communication with the inverse butterfly circuit for selectively controlling the plurality of multiplexers of the inverse butterfly circuit to perform a bit manipulation operation on the word to produce a processed word, the control circuit configured to cause the plurality of multiplexers of the inverse butterfly circuit to perform at least one of a shift operation or a rotate operation on bits of the word; and
means for supplying the processed word to the processor.

2. The shifter circuit of claim 1, wherein the control circuit causes the inverse butterfly circuit to perform a logical shift right, a signed shift right, or a shift left instruction.

3. The shifter circuit of claim 1, wherein the control circuit causes the inverse butterfly circuit to perform a rotate left or a rotate right instruction.

4. The shifter circuit of claim 1, wherein the control circuit causes the inverse butterfly circuit to perform at least one of an extract operation or a deposit operation.

5. The shifter circuit of claim 4, wherein the control circuit causes the inverse butterfly circuit to perform a multimedia mix operation.

6. The shifter circuit of claim 1, wherein the control circuit causes the inverse butterfly circuit to perform a multimedia mix operation.

7. The shifter circuit of claim 1, wherein the control circuit causes the inverse butterfly circuit to perform a parallel extract operation.

8. The shifter circuit of claim 1, wherein the control circuit causes the inverse butterfly circuit to perform a group operation on bits of the word.

9. The shifter circuit of claim 1, wherein the control circuit causes the inverse butterfly circuit to perform a permutation operation on bits of the word.

10. The shifter circuit of claim 1, wherein the control circuit causes the inverse butterfly circuit to perform an inverse butterfly operation.

11. The shifter circuit of claim 1, wherein the control circuit further comprises a decoder.

12. The shifter circuit of claim 11, wherein the decoder further comprises a parallel prefix counter and a plurality of left rotate and complement modules.

13. The shifter circuit of claim 1, wherein the plurality of stages of the inverse butterfly circuit comprises a first stage having first pairs of bits which are spaced 1 bit apart from each other, each of the first pairs being provided as inputs to a switch.

14. The shifter circuit of claim 13, wherein the plurality of stages of the inverse butterfly circuit comprises a second stage having second pairs of bits which are spaced 2 bits apart from each other, each of which second pairs being provided as inputs to a switch.

15. The shifter circuit of claim 13, wherein the plurality of stages of the inverse butterfly circuit comprises a log(n) stage having third pairs of bits which are spaced n/2 bits apart from each other.

16. The shifter circuit of claim 1, wherein the control circuit generates control bits for the inverse butterfly circuit using a recursive algorithm.

17. The shifter circuit of claim 1, further comprising a masked merge unit in communication with the control circuit for generating merge bits.

18. The shifter circuit of claim 1, wherein the control unit obtains control bits for controlling the shifter from one or more registers of the processor.

19. The shifter circuit of claim 1, further comprising a butterfly circuit in communication with the control circuit.

20. The shifter circuit of claim 1, further comprising a second inverse butterfly circuit in communication with the control circuit for performing a group operation.

21. The shifter circuit of claim 1, wherein the plurality of stages of the inverse butterfly circuit comprises a first stage having first pairs of inputs which are spaced 1 unit apart from each other.

22. The shifter circuit of claim 21, wherein the plurality of stages of the inverse butterfly circuit comprises a second stage having second pairs of inputs which are spaced 2 units apart from each other.

23. The shifter circuit of claim 22, wherein the plurality of stages of the inverse butterfly circuit comprises a log(n) stage having third pairs of inputs which are spaced n/2 units apart from each other.

24. A shifter circuit for a processor, comprising:
means for obtaining a word in a processor;
a butterfly circuit connected to said means for obtaining the word, the butterfly circuit including a plurality of circuit stages, each of the circuit stages including a plurality of multiplexers;
a control circuit in communication with the butterfly circuit for selectively controlling the plurality of multiplexers of the butterfly circuit to perform a bit manipulation operation on the word to produce a processed word, the control circuit configured to cause the plurality of multiplexers of the butterfly circuit to perform at least one of a shift operation or a rotate operation on bits of the word; and
means for supplying the processed word to the processor.

25. The shifter circuit of claim 24, wherein the control circuit causes the butterfly circuit to perform a logical shift right, a signed shift right, or a shift left instruction.

26. The shifter circuit of claim 24, wherein the control circuit causes the butterfly circuit to perform at least one of a rotate left or a rotate right instruction.

27. The shifter circuit of claim 24, wherein the control circuit causes the butterfly circuit to perform an extract or a deposit operation.

28. The shifter circuit of claim 27, wherein the control circuit causes the butterfly circuit to perform a multimedia mix operation.

29. The shifter circuit of claim 24, wherein the control circuit causes the butterfly circuit to perform a multimedia mix operation.

30. The shifter circuit of claim 24, wherein the control circuit causes the butterfly circuit to perform a parallel deposit operation.

31. The shifter circuit of claim 24, wherein the control circuit causes the butterfly circuit to perform a permutation operation on bits of the word.

32. The shifter circuit of claim 24, wherein the control circuit causes the butterfly circuit to perform a butterfly operation.

33. The shifter circuit of claim 24, wherein the control circuit further comprises a decoder.

34. The shifter circuit of claim 33, wherein the decoder further comprises a parallel prefix counter and a plurality of left rotate and complement modules.

35. The shifter circuit of claim 24, wherein the plurality of stages of the butterfly circuit comprises a first stage having first pairs of bits which are spaced n/2 bits apart from each other, each of the first pairs being provided as inputs to a switch.

36. The shifter circuit of claim 35, wherein the plurality of stages of the butterfly circuit comprises a second stage having second pairs of bits which are spaced n/4 bits apart from each other, each of which second pairs being provided as inputs to a switch.

37. The shifter circuit of claim 36, wherein the plurality of stages of the butterfly circuit comprises a log(n) stage having third pairs of bits which are spaced 1 bit apart from each other.

38. The shifter circuit of claim 24, wherein the control circuit generates control bits for the butterfly circuit using a recursive algorithm.

39. The shifter circuit of claim 24, further comprising a masked merge unit in communication with the control circuit for generating merge bits.

40. The shifter circuit of claim 24, wherein the control circuit obtains control bits for controlling the shifter from one or more registers of the processor.

41. The shifter circuit of claim 24, further comprising an inverse butterfly circuit in communication with the control circuit.

42. The shifter circuit of claim 41, further comprising a second inverse butterfly circuit in communication with the control circuit for performing a group operation.

43. The shifter circuit of claim 24, wherein the plurality of stages of the butterfly circuit comprises a first stage having first pairs of inputs which are spaced 1 unit apart from each other.

44. The shifter circuit of claim 43, wherein the plurality of stages of the butterfly circuit comprises a second stage having second pairs of inputs which are spaced 2 units apart from each other.

45. The shifter circuit of claim 44, wherein the plurality of stages of the butterfly circuit comprises a log(n) stage having third pairs of inputs which are spaced n/2 units apart from each other.