Shift Processing Unit
The present invention is a technique to perform field operations. A shifter to shift an operand. A register stores the shifted operand. A shift post processor processes the shifted operand based on at least a control signal and an offset parameter.
This application is a continuation of U.S. patent application Ser. No. 09/933,786 to Sandbote, entitled “Shifter for Alignment with Bit Formatter Gating Bits from Shifted Operand, Shifted Carry Operand and Most Significant Bit” and filed Aug. 20, 2001, the entirety of which is incorporated by reference herein.
BACKGROUND OF THE INVENTION1. Field of the Invention
This invention relates to computer architecture. In particular, the invention relates to processing units.
2. Background Art
Digital processors are usually designed with a fixed word length to facilitate data handling and operation. The typical word length is a power of two and is compatible with memory data size. In many advanced processors, the word length is 32-bit, 64-bit, or 128-bit.
Although these traditional word lengths are useful for many scientific, data processing, business, medical, military, and commercial applications, they may not be convenient for applications where the word length may have any size depending on the type of information to be represented. Examples of such applications include network data processing and packet communications. In these applications, the data items may be represented by the minimum word size to optimize data transfers and switching. In addition, the word size may vary within the same processing unit. Furthermore, even when the data word sizes are comparable with the native word size of the processor, there are cases where blocks of data or long words are processed and these blocks of data may occupy at boundaries that are not aligned with the native word boundary.
Existing techniques to handle data with word sizes larger than the processor's native size are inefficient. These techniques involve execution of a large number of operations to shift and perform logical operations on the data items to be aligned or merged.
The features and advantages of the present invention will become apparent from the following detailed description of the present invention in which:
In the following description, for purposes of explanation, numerous details are set forth in order to provide a thorough understanding of the present invention. However, it will be apparent to one skilled in the art that these specific details are not required in order to practice the present invention. In other instances, well-known electrical structures and circuits are shown in block diagram form in order not to obscure the present invention.
The instruction memory 110 stores instructions to be fetched and executed by the processor core 120. The instruction memory 110 may be implemented by random access memory (RAM), such as static RAM (SRAM) or dynamic RAM (DRAM), or non-volatile memory such as read only memory (ROM), programmable ROM (PROM), erasable ROM (EROM), electrically erasable ROM (EEROM), flash memory, or any other storage media.
The processor core 120 is the core of a central processing unit (CPU) or a processor that can execute a program and/or instructions. The processor core 120 is interfaced to the instruction memory 110 either directly or indirectly through an interface circuit (not shown) such as a memory controller. The processor core 120 includes an instruction fetch unit 130, an instruction decoder 140, a register file 150, and a shift processing unit 160. The processor core 120 may contain other circuits or elements that are not necessary for an understanding of the invention. Examples of these elements include a branch prediction logic, an instruction buffer unit, a code cache, a data cache, and other functional units.
The instruction fetch unit 130 fetches the instructions from the instruction memory 130 and stores in an instruction register 132. The instruction register holds a copy of the instruction. The instruction fetch unit 130 may contain a program counter to store the address of the instruction.
The instruction decoder 140 decodes the instruction 135 stored in the instruction register 132. The instruction decoder 140 may have a number of decoder sections that decodes portions of the instruction. The format of the instruction 135 may have a number of forms depending on the instruction set architecture (ISA) employed by the processor core 120.
The register file 150 includes a number of registers that store temporary data to be operated on during the execution of the instruction 135. The register file may be read or written to the shift processing unit 160. The number of registers in the register file depends on the ISA and may be sixteen, thirty two, or any suitable number. The registers provide the source operands for the shift processing unit 160. In addition, the registers also provide the destination for the shift processing unit 160.
The shift processing unit 160 performs shifting operations including left and right shifts, left and right shifts with zero fill, right shift with sign fill, left and right shifts with register fill, left and right shifts through carry, etc. These shift operations are efficient in data re-alignment and data merging. Although the term “shifting” is used throughout this description, it is understood that it includes both shifting and rotation. As is known by one skilled in the art, a rotation operation is a circular shift operation.
A processor which operates on data taken from a network may be charged with the tasks of re-aligning data which begins at a given or byte-, bit offset in a starting address or register, and continues for several words. This requirement occurs frequently when a processor de-encapsulates packet data. This process involves the removal of several bytes from the beginning of a packet, possibly leaving the remaining data un-aligned to the processor's word boundary. Another situational example is the merging of data. These examples are illustrated in
The data block 210 contains five words of packet data before the data re-alignment. Typically the packet data is received from a transmitting source. This data block includes a header 230 and the packet data 240. The header 230 contains information regarding the packet data such as identification code, check sum, packet number, type of packet, etc. After this information is used for administrative, error checking, or book-keeping purposes, it is usually discarded or removed. The packet data 240 contain the actual data to be processed. To facilitate the processing, it is desired that the packet data 240 is aligned at the word boundary. To do so, a data re-alignment operation is performed.
The data block 220 represents the re-aligned packet data after the data re-alignment operation. The packet data 240 becomes the packet data 250. The header 230 is removed and the packet data 250 is shifted to start at the word boundary beginning from word 0. The header 230 may not be actually removed and the packet data 250 may overwrite the header 230. By re-aligning the packet data at word boundary, the data processing becomes more efficient. Subsequent operations may include data movement, comparisons, arithmetic and logical operations, or any other suitable operations.
The data block 260 contains five words of data before data merging. Typically this packet data is the data to be sent to a receiving source. The data block 260 includes a packet header 280 and an unaligned packet data 285. The packet header 280 and the unaligned packet data 285 are separated by unused portions. It is desired to merge the packet header 280 and the unaligned packet data 285 into a contiguous sequence of words. To do so, a data merge operation is performed.
The data block 270 contains a merged data 290. The merged data 290 forms a contiguous words by combining the packet header 280 and the unaligned packet data 285. The data merging operation is performed by shifting the unaligned packet data 285 to the end of the packet header 280.
As is known by one skilled in the art, the data re-alignment and data merge operations are not only useful for communication or network applications. They are also useful for traditional computer operations such as text manipulations, data movements, information processing, string operations, array manipulations, etc.
The barrel shifter 310 receives an operand 315 to be operated upon. The operand 315 may come from the register file 150 (
The SC register 330 stores the output of the barrel shifter 310. The SC register 330 has the same word size with the barrel shifter 310 and the register file 150 (
The shift post processor 340 performs a number of operations after the shifting by the barrel shifter 310. These post-shift operations may include replacing a portion of the shifted operand with zero, sign bits (e.g., sign extension), or a portion of the SC register 330. The output of the shift post processor 340 may be written to the register file 150 (
The operand 410 represents the input to the barrel shifter 310 (
The operand 425 is the result of the execution of the instruction LEFT ROTATE. In other words, the shift post processor 340 leaves the output of the barrel shifter 310 unchanged.
The operand 430 is the result of the execution of the instruction LEFT SHIFT ZERO-FILL which replaces the data element A with zeros. The operand 435 is the result of the execution of the instruction RIGHT SHIFT ZERO-FILL which replaces the data element B with zeros. The operand 440 is the result of the execution of the instruction RIGHT SHIFT SIGN-FILL which extends the sign bit of the data element A to occupy the entire word. The operand 445 is the result of the execution of the instruction LEFT SHIFT SC-FILL which replaces the data element A with the corresponding portion of the register 330 (
The operand 455 represents the contents of a register before the execution of the instruction MOVE SC TO REGISTER. The operand 460 represents the contents of the register after the execution of the instruction MOVE SC TO REGISTER. This instruction moves the contents of the SC register 330 to a specified register. The operand 465 represents the contents of a register before the execution of the instruction MOVE REGISTER TO SC. The operand 470 represents the contents of the SC register 330 after the execution of the instruction MOVE REGISTER TO SC. This instruction moves the contents of a specified register to the SC register 330. Normally, after the movement, the contents of the specified register remain unchanged.
In general, a long word having N words is shifted left by executing N left shift instructions. The shifting sequence starts with the least significant word, or the rightmost word in the long word operand. In this example, there are three left shifts. The first instruction is SHL word[0], offset. This instruction causes word[0] to be shifted left and zero's filled in the right to occupy the shifted bit positions. At the same time, the SC register 510 contains the left rotated data elements A. The SC register 510 stores ALO AHI as shown.
The second instruction is SHLC word[1], offset. This instruction causes a left shift of word[1] 530 through carry. The AHI portion in the SC register 510 is shifted to occupy the shifted bit positions of word[1] 530 from the right through carry. Word[1] 530 will become BLO AHI. At the same time, the SC register 510 contains the left rotated data elements B, or BLO BHI as shown. After this instruction is executed, it is seen that the data element A is shifted left to cross the boundary between A and B.
The third instruction is SHLC word[2], offset. As in the second instruction, this instruction causes a left shift of word[2] 540 through carry. The BHI portion in the SC register 510 is shifted to occupy the shifted bit positions of word[2] 540 from the right through carry. Word[2] 540 will become CLO BHI. At the same time, the SC register 510 contains the left rotated data elements C, or CLO CHI as shown. After this instruction is executed, it is seen that the data element B is shifted left to cross the boundary between B and C. In addition, the data element C is left shifted and the CHI portion is shifted out of word[2] 540. In the end, the long word operand is now shifted left with zero's filled in the shifted bit positions starting from the rightmost.
In general, a long word having N words is shifted right by executing N right shift instructions. The shifting sequence starts with the most significant word, or the leftmost word in the long word operand. In this example, there are three right shifts. The first instruction is SHR word[2], offset. This instruction causes word[2] 540 to be shifted right and zero's filled in from the left to occupy the shifted bit positions. At the same time, the register 510 contains the right rotated data elements C. The SC register 510 stores CLO CHI as shown.
The second instruction is SHRC word[1], offset. This instruction causes a right shift of word[1] 530 through carry. The CLO portion in the SC register 510 is shifted to occupy the shifted bit positions of word[1] 530 from the left through carry. Word[1] 530 will become CLO BHI. At the same time, the SC register 510 contains the right rotated data elements B, or BLO BHI as shown. After this instruction is executed, it is seen that the data element C is shifted right to cross the boundary between C and B.
The third instruction is SHRC word[0], offset. As in the second instruction, this instruction causes a right shift of word[0] 510 through carry. The BLO portion in the SC register 510 is shifted to occupy the shifted bit positions of word[0] 520 from the left through carry. Word[0] 520 will become BLO AHI. At the same time, the SC register 510 contains the right rotated data elements A, or ALO AHI as shown. After this instruction is executed, it is seen that the data element B is shifted right to cross the boundary between B and A. In addition, the data element A is right shifted and the ALO portion is shifted out of word[0] 520. In the end, the long word operand is now shifted right with zero's filled in the shifted bit positions starting from the leftmost.
The data blocks 610, 620, 630, and 640 contain the data items to be shifted for re-alignment. Each block has four words: word[0], word[1], word[2] and word[3]. Each block represents a step of a sequence of shifts and offset movements. The offset is the unaligned offset from the first word of the block, word[0]. Word[0] contains the offset and data item A. Word[1] contains data items B and C. Word[2] contains data item D and E. Word[3] contains data items F and an unused data portion. The operands 615, 625, 634, and 645 represent the contents of the SC register at each step of the sequence.
At step 1, the instruction SHL word[3] is executed and the offset is moved to word[3]. The operand 615 contains the left shifted word [3]. At step 2, word[3] contains unused data portion and zeros. Then, the instruction SHLC word[2] is executed. The operand 625 contains the left shifted word[2]. At the same time, a portion of the operand 625 is combined with a portion of the operand 615 such that the data item E is combined with the data item F. At step 3, word[2] contains the combined data items E and F. Then, the instruction SHLC word[1] is executed. The operand 635 contains the left shifted word[1]. At the same time, a portion of the operand 635 is combined with a portion of the operand 625 such that data item C is combined with data item B. At step 4, word[1] contains data items C and D. Then, the instruction SHLC word[0] is executed. At the same time, a portion of the operand 645 is combined with a portion of the operand 635 such that the data item A is combined with the data item B. Word[0] contains data items A and B. At the end of the sequence, the entire four words are properly aligned at the word boundary.
The operation described above performs the data re-alignment as shown in
The decoder 710 receives the OFFSET parameter and generates a shift field mask MASK [1 . . . N]. The shift field mask has N bits, mask(l) to mask (N), corresponding to N-bit word of the shifted operand. The shift mask field defines the bit positions that are affected by the post processing operations. In one embodiment, a logical one in the mask(k) indicates that the bit at the k-th position is affected by the post processing operation, and a logical zero allows the bit at the k-th position to pass through unmodified. The decoder essentially converts the OFFSET value into a bit pattern having a group of consecutive mask bits that corresponds to the portion of the operand to be operated upon.
Each of the bit for matters 7201 to 720N performs a bit post processing operation on each bit of the shifted output of the barrel shifter, shifted(l) to shifted(N). Each of the bit formatters receives the corresponding mask(k) bit and the SC(k) bit. In addition, all the bit formatters 7201 to 720N receive the same control bits MSB, ZERO_EXTEND, SIGN_EXTEND, and USE_SHIFT_CARRY. The bit formatters 7201 to 720N generate the N-bit output, y(1) to y(N).
The gating circuit 801 gates the ZERO_EXTEND, SIGN_EXTEND, and USE_SHIFT_CARRY signals by the mask(i) bit. In one embodiment, the gating circuit 801 includes NAND gate 810, AND gates 820, 830, and 840. When the mask(i) bit is logical zero, indicating that the shifted(i) bit is passed through unmodified, the NAND gate 810 gates the shifted(i) bit to the selector circuit 802. When the mask(i) bit is logical one, the shifted(i) bit is modified according to the ZERO_EXTEND, SIGN_EXTEND, and USE_SHIFT_CARRY control signals.
The selector circuit 802 selects the proper bit operand to generate the output bit y(i) according to the mask(i) bit and the ZERO_EXTEND, SIGN_EXTEND, and USE_SHIFT_CARRY control signals. In one embodiment, the selector circuit 802 includes two two-to-one multiplexers 850 and 860. Of course, the two multiplexers 850 and 860 may be combined into a single combinational logic circuit which operates the same way as two multiplexers connected in cascade.
The bit for matter 720i performs logic operations on the shifted(i) bit using the MSB and the SC(i) bits according to the control bits mask(i), ZERO_EXTEND, SIGN_EXTEND, and USE_SHIFT_CARRY control signals. Let m, sc, msk, ze, se, and u denote the MSB, SC(i), bits mask(i), ZERO_EXTEND, SIGN_EXTEND, and USE_SHIFT_CARRY control signals. Let shft and y denote the shifted(i) and y(i) signals. The bit formatter 720i essentially performs the logic operations according to the following truth table.
Note that ze and se are mutually exclusive. In other words, if zero extension is desired, then sign extension is not available. Similarly, if sign extension is desired, then zero extension is not available.
While this invention has been described with reference to illustrative embodiments, this description is not intended to be construed in a limiting sense. Various modifications of the illustrative embodiments, as well as other embodiments of the invention, which are apparent to persons skilled in the art to which the invention pertains are deemed to lie within the spirit and scope of the invention.
Claims
1. An apparatus for facilitating data processing, comprising:
- a barrel shifter configured to shift an operand during a shift cycle, whereby the barrel shifter successively provides an output operand for each shift cycle; and
- a shift post processor configured to perform one of a plurality of post processing operations on a portion of a current-output operand from the barrel shifter based on a control signal.
2. The apparatus of claim 1, wherein the shift post processor is configured to replace the portion of the current-output operand with one or more zero bits based on the control signal.
3. The apparatus of claim 1, wherein the shift post processor is configured to replace the portion of the current-output operand with one or more sign bits based on the control signal.
4. The apparatus of claim 1, further comprising:
- a shift carry register configured to store a current-output operand from a current shift cycle and to output a stored-output operand from a previous shift cycle.
5. The apparatus of claim 4, wherein the shift post processor is configured to replace the portion of the current-output operand with one or more bits of the stored-output operand based on the control signal.
6. A method for facilitating data processing, comprising:
- (a) shifting an operand during a shift cycle, thereby successively providing an output operand for each shift cycle; and
- (b) performing one of a plurality of post processing operations on a portion of a current-output operand based on a control signal.
7. The method of claim 6, wherein step (b) comprises:
- replacing the portion of the current-output operand with one or more zero bits based on the control signal.
8. The method of claim 6, wherein step (b) comprises:
- replacing the portion of the current-output operand with one or more sign bits based on the control signal.
9. The method of claim 6, further comprising:
- (c) outputting a stored-output operand from a previous shift cycle.
10. The method of claim 9, wherein step (b) comprises:
- replacing the portion of the current-output operand with one or more bits of the stored-output operand based on the control signal.
11. A processing unit comprising:
- a register file having a plurality of registers, each of the registers configured to store an operand;
- an instruction decoder to decode an instruction; and
- a shift processing unit coupled to the register file and the instruction decoder to perform an operation on the operand, the shift processing unit comprising: a barrel shifter configured to shift an operand during a shift cycle, whereby the barrel shifter successively provides an output operand for each shift cycle; and a shift post processor configured to perform one of a plurality of post processing operations on a portion of a current-output operand from the barrel shifter based on a control signal.
12. The processing unit of claim 11, wherein the shift post processor is configured to replace the portion of the current-output operand with one or more zero bits based on the control signal.
13. The processing unit of claim 11, wherein the shift post processor is configured to replace the portion of the current-output operand with one or more sign bits based on the control signal.
14. The processing unit of claim 11, further comprising:
- a shift carry register configured to store a current-output operand from a current shift cycle and to output a stored-output operand from a previous shift cycle.
15. The processing unit of claim 14, wherein the shift post processor is configured to replace the portion of the current-output operand with one or more bits of the stored-output operand based on the control signal.
16. The processing unit of claim 11, wherein the shift post processor is embodied in hardware description language software.
17. The processing unit of claim 16, wherein the shift post processor is embodied in one of Verilog hardware description language software, Verilog-A hardware description language software, and VHDL hardware description language software.
Type: Application
Filed: Feb 26, 2008
Publication Date: Jun 19, 2008
Inventor: Sam B. SANDBOTE (Reston, VA)
Application Number: 12/037,559
International Classification: G06F 9/315 (20060101); G06F 9/30 (20060101);