METHOD AND APPARATUS FOR SHUFFLING DATAThis patent application is a Continuation In Part of U.S. patent application Ser. No. 09/952,891, entitled “An Apparatus And Method For Efficient Filtering And Convolution Of Content Data”, filed Oct. 29, 2001.[0001]
The patent application is related to the following: co-pending U.S. patent application No. ______, entitled “Method And Apparatus For Parallel Table Lookup Using SIMD Instructions” filed on Jun. 30, 2003; and co-pending U.S. patent application Ser. No. ______, entitled “Method And Apparatus For Rearranging Data Between Multiple Registers” filed on Jun. 30, 2003.[0002]
FIELD OF THE INVENTIONThe present invention relates generally to the field of microprocessors and computer systems. More particularly, the present invention relates to a method and apparatus for shuffling data.[0003]
BACKGROUND OF THE INVENTIONComputer systems have become increasingly pervasive in our society. The processing capabilities of computers have increased the efficiency and productivity of workers in a wide spectrum of professions. As the costs of purchasing and owning a computer continues to drop, more and more consumers have been able to take advantage of newer and faster machines. Furthermore, many people enjoy the use of notebook computers because of the freedom. Mobile computers allow users to easily transport their data and work with them as they leave the office or travel. This scenario is quite familiar with marketing staff, corporate executives, and even students.[0004]
As processor technology advances, newer software code is also being generated to run on machines with these processors. Users generally expect and demand higher performance from their computers regardless of the type of software being used. One such issue can arise from the kinds of instructions and operations that are actually being performed within the processor. Certain types of operations require more time to complete based on the complexity of the operations and/or type of circuitry needed. This provides an opportunity to optimize the way certain complex operations are executed inside the processor.[0005]
Media applications have been driving microprocessor development for more than a decade. In fact, most computing upgrades in recent years have been driven by media applications. These upgrades have predominantly occurred within consumer segments, although significant advances have also been seen in enterprise segments for entertainment enhanced education and communication purposes. Nevertheless, future media applications will require even higher computational requirements. As a result, tomorrow's personal computing experience will be even richer in audio-visual effects, as well as being easier to use, and more importantly, computing will merge with communications.[0006]
Accordingly, the display of images, as well as playback of audio and video data, which is collectively referred to as content, have become increasingly popular applications for current computing devices. Filtering and convolution operations are some of the most common operations performed on content data, such as image audio and video data. Such operations are computationally intensive, but offer a high level of data parallelism that can be exploited through an efficient implementation using various data storage devices, such as for example, single instruction multiple data (SIMD) registers. A number of current architectures also require unnecessary data type changes which minimizes instruction throughput and significantly increases the number of clock cycles required to order data for arithmetic operations.[0007]
BRIEF DESCRIPTION OF THE DRAWINGSThe present invention is illustrated by way of example and not limitations in the figures of the accompanying drawings, in which like references indicate similar elements, and in which:[0008]
FIG. 1A is a block diagram of a computer system formed with a processor that includes execution units to execute an instruction for shuffling data in accordance with one embodiment of the present invention;[0009]
FIG. 1B is a block diagram of another exemplary computer system in accordance with an alternative embodiment of the present invention;[0010]
FIG. 1C is a block diagram of yet another exemplary computer system in accordance with another alternative embodiment of the present invention;[0011]
FIG. 2 is a block diagram of the micro-architecture for a processor of one embodiment that includes logic circuits to perform data shuffle operations in accordance with the present invention;[0012]
FIGS.[0013]3A-C are illustrations of shuffle masks according to various embodiments of the present invention;
FIG. 4A is an illustration of various packed data type representations in multimedia registers according to one embodiment of the present invention;[0014]
FIG. 4B illustrates packed data-types in accordance with an alternative embodiment;[0015]
FIG. 4C illustrates one embodiment of an operation encoding (opcode) format for a shuffle instruction;[0016]
FIG. 4D illustrates an alternative operation encoding format;[0017]
FIG. 4E illustrates yet another alternative operation encoding format;[0018]
FIG. 5 is a block diagram of one embodiment of logic to perform a shuffle operation on a data operand based on a shuffle mask in accordance with the present invention;[0019]
FIG. 6 is a block diagram of one embodiment of a circuit for performing a data shuffling operation in accordance with the present invention;[0020]
FIG. 7 illustrates the operation of a data shuffle on byte wide data elements in accordance with one embodiment of the present invention;[0021]
FIG. 8 illustrates the operation of a data shuffle operation on word wide data elements in accordance with another embodiment of the present invention;[0022]
FIG. 9 is a flow chart illustrating one embodiment of a method to shuffle data;[0023]
FIGS.[0024]10A-H illustrate the operation of a parallel table lookup algorithm using SIMD instructions;
FIG. 11 is a flow chart illustrating one embodiment of a method to perform a table lookup using SIMD instructions;[0025]
FIG. 12 is a flow chart illustrating another embodiment of a method to perform a table lookup;[0026]
FIGS.[0027]13A-C illustrates an algorithm for rearranging data between multiple registers;
FIG. 14 is a flow chart illustrating one embodiment of a method to rearrange data between multiple registers;[0028]
FIGS.[0029]15A-K illustrates an algorithm for shuffling data between multiple registers to generate interleaved data; and
FIG. 16 is a flow chart illustrating one embodiment of a method to shuffle data between multiple registers to generate interleaved data.[0030]
DETAILED DESCRIPTIONA method and apparatus for shuffling data is disclosed. A method and apparatus for parallel table lookup using SIMD instructions are also described. A method and apparatus for rearranging data between multiple registers is also disclosed. The embodiments described herein are described in the context of a microprocessor, but are not so limited. Although the following embodiments are described with reference to a processor, other embodiments are applicable to other types of integrated circuits and logic devices. The same techniques and teachings of the present invention can easily be applied to other types of circuits or semiconductor devices that can benefit from higher pipeline throughput and improved performance. The teachings of the present invention are applicable to any processor or machine that performs data manipulations. However, the present invention is not limited to processors or machines that perform 256 bit, 128 bit, 64 bit, 32 bit, or 16 bit data operations and can be applied to any processor and machine in which shuffling of data is needed.[0031]
In the following description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the present invention. One of ordinary skill in the art, however, will appreciate that these specific details are not necessary in order to practice the present invention. In other instances, well known electrical structures and circuits have not been set forth in particular detail in order to not necessarily obscure the present invention. In addition, the following description provides examples, and the accompanying drawings show various examples for the purposes of illustration. However, these examples should not be construed in a limiting sense as they are merely intended to provide examples of the present invention rather than to provide an exhaustive list of all possible implementations of the present invention.[0032]
In an embodiment, the methods of the present invention are embodied in machine-executable instructions. The instructions can be used to cause a general-purpose or special-purpose processor that is programmed with the instructions to perform the steps of the present invention. Alternatively, the steps of the present invention might be performed by specific hardware components that contain hardwired logic for performing the steps, or by any combination of programmed computer components and custom hardware components.[0033]
Although the below examples describe instruction handling and distribution in the context of execution units and logic circuits, other embodiments of the present invention can be accomplished by way of software. The present invention may be provided as a computer program product or software which may include a machine or computer-readable medium having stored thereon instructions which may be used to program a computer (or other electronic devices) to perform a process according to the present invention. Such software can be stored within a memory in the system. Similarly, the code can be distributed via a network or by way of other computer readable media. Thus a machine-readable medium may include any mechanism for storing or transmitting information in a form readable by a machine (e.g., a computer), but is not limited to, floppy diskettes, optical disks, Compact Disc, Read-Only Memory (CD-ROMs), and magneto-optical disks, Read-Only Memory (ROMs), Random Access Memory (RAM), Erasable Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), magnetic or optical cards, flash memory, a transmission over the Internet, electrical, optical, acoustical or other forms of propagated signals (e.g., carrier waves, infrared signals, digital signals, etc.) or the like.[0034]
Accordingly, the computer-readable medium includes any type of media/machine-readable medium suitable for storing or transmitting electronic instructions or information in a form readable by a machine (e.g., a computer). Moreover, the present invention may also be downloaded as a computer program product. As such, the program may be transferred from a remote computer (e.g., a server) to a requesting computer (e.g., a client). The transfer of the program may be by way of electrical, optical, acoustical, or other forms of data signals embodied in a carrier wave or other propagation medium via a communication link (e.g., a modem, network connection or the like).[0035]
Furthermore, embodiments of integrated circuit designs in accordance with the present inventions can be communicated or transferred in electronic form as a database on a tape or other machine readable media. For example, the electronic form of an integrated circuit design of a processor in one embodiment can be processed or manufactured via a fab to obtain a computer component. In another instance, an integrated circuit design in electronic form can be processed by a machine to simulate a computer component. Thus the circuit layout plans and/or designs of processors in some embodiments can be distributed via machine readable mediums or embodied thereon for fabrication into a circuit or for simulation of an integrated circuit which, when processed by a machine, simulates a processor. A machine readable medium is also capable of storing data representing predetermined functions in accordance with the present invention in other embodiments.[0036]
In modem processors, a number of different execution units are used to process and execute a variety of code and instructions. Not all instructions are created equal as some are quicker to complete while others can take an enormous number of clock cycles. The faster the throughput of instructions, the better the overall performance of the processor. Thus it would be advantageous to have as many instructions execute as fast as possible. However, there are certain instructions that have greater complexity and require more in terms of execution time and processor resources. For example, there are floating point instructions, load/store operations, data moves, etc.[0037]
As more and more computer systems are used in internet and multimedia applications, additional processor support has been introduced over time. For instance, Single Instruction, Multiple Data (SIMD) integer/floating point instructions and Streaming SIMD Extensions (SSE) are instructions that reduce the overall number of instructions required to execute a particular program task. These instructions can speed up software performance by operating on multiple data elements in parallel. As a result, performance gains can be achieved in a wide range of applications including video, speech, and image/photo processing. The implementation of SIMD instructions in microprocessors and similar types of logic circuit usually involve a number of issues. Furthermore, the complexity of SIMD operations often leads to a need for additional circuitry in order to correctly process and manipulate the data.[0038]
Embodiments of the present invention provide a way to implement a packed byte shuffle instruction with a flush to zero capability as an algorithm that makes use of SIMD related hardware. For one embodiment, the algorithm is based on the concept of shuffling data from a particular register or memory location based on the values of a control mask for each data element position. Embodiments of a packed byte shuffle can be used to reduce the number of instructions required in many different applications that rearrange data. A packed byte shuffle instruction can also be used for any application with unaligned loads. Embodiments of this shuffle instruction can be used for filtering to arrange data for efficient multiply-accumulate operations. Similarly, a packed shuffle instruction can be used in video and encryption applications for ordering data and small lookup tables. This instruction can be used to mix data from two or more registers. Thus embodiments of a packed shuffle with a flush to zero capability algorithm in accordance with the present invention can be implemented in a processor to support SIMD operations efficiently without seriously compromising overall performance.[0039]
Embodiments of the present invention provide a packed data shuffle instruction (PSHUFB) with a flush to zero capability for efficiently ordering and arranging data of any size. In one embodiment, data is shuffled or rearranged in a register with byte granularity. The byte shuffle operation orders data sizes, which are larger than bytes, by maintaining the relative position of bytes within the larger data during the shuffle operation. In addition, the byte shuffle operation can change the relative position of data in an SIMD register and can also duplicate data. This PSHUFB instruction shuffles bytes from a first source register in accordance to the contents of shuffle control bytes in a second source register. Although the instruction permutes the data, the shuffle mask is left unaffected and unchanged during this shuffle operation of this embodiment. The mnemonic for the one implementation is “[0040]PSHUFB register1, register2/ memory”, wherein the first and second operands are SIMD registers. However, the register of the second operand can also be replaced with a memory location. The first operand includes the source data for shuffling. For this embodiment, the register for the first operand is also the destination register. Embodiments in accordance to the present invention also include a capability of setting selected bytes to zero in addition to changing their position.
The second operand includes the set of shuffle control mask bytes to designate the shuffle pattern. The number of bits used to select a source data element is log
[0041]2of the number of data elements in the source operand. For instance, the number of bytes in a 128 bit register embodiment is sixteen. The log
2of sixteen is four. Thus four bits, or a nibble, is needed. The [
3:
0] index in the code below refers to the four bits. If the most significant bit (MSB),
bit7 in this embodiment, of the shuffle control byte is set, a constant zero is written in the result byte. If the least significant nibble of byte I of the second operand, the mask set, contains the integer J, then the shuffle instruction causes the j
thbyte of the first source register to be copied to the I
thbyte position of the destination register. Below is example pseudo-code for one embodiment of a packed byte shuffle operation on 128 bit operands:
| DEST[(i*8)+7...(i*8)+0] 0 |
| index[3:0] SRC2[(i*8)+3 ... SRC2(i*8)+0] |
| DEST[(i*8)+7...(i*8)+0] SRC1/DEST[(index*8+7)... (index*8+0)] |
Similarly, this is example pseudo-code for another embodiment of a packed byte shuffle operation on 64 bit operands:
[0042] | if (SRC2[(i * 8)+7] ═ 1 ) |
| DEST[(i*8)+7...(i*8)+0] 0 |
| index[2:0] SRC2[(i*8)+2 ... SRC2(i*8)+0] |
| DEST[(i*8)+7...(i*8)+0] SRC1/DEST[(index*8+7)... (index*8+0)] |
Note that in this 64 bit register embodiment, the lower three bits of the mask are used as there are eight bytes in a 64 bit register. The log[0043]2of eight is three. The [2:0] index in the code above refers to the three bits. In alternative embodiments, the number of bits in a mask can vary to accommodate the number of data elements available in the source data. For example, a mask with lower five bits is needed to select a data element in a 256 bit register.
Presently, it is somewhat difficult and tedious to rearrange data in a SIMD register. Some algorithms require more instructions to arrange data for arithmetic operations than the actual number of instructions to execute those operations. By implementing embodiments of a packed byte shuffle instruction in accordance with the present invention, the number of instructions needed to achieve data rearrangement can be drastically reduced. For example, one embodiment of a packed byte shuffle instruction can broadcast a byte of data to all positions of a 128 bit register. Broadcasting data in a register is often used in filtering applications where a single data item is multiplied by many coefficients. Without this instruction, the data byte would have to be filtered from its source and shifted to the lowest byte position. Then, that single byte would have to be duplicated first as a byte, then that those two bytes duplicated again to form a doubleword, and that doubleword duplicated to finally form a quadword. All these operations can be replaced with a single packed shuffle instruction.[0044]
Similarly, the reversing of all the bytes in a 128 bit register, such as in changing between big endian and little endian formats, can be easily performed with a single packed shuffle instruction. Whereas even these fairly simple patterns require a number of instructions if a packed shuffle instruction were not used, complex or random patterns require even more inefficient instruction routines. The most straight forward solution to rearrange random bytes in a SIMD register is to write them to a buffer and then use integer byte reads/writes to rearrange them and read them back into a SIMD register. All these data processing would require a lengthy code sequence, while a single packed shuffle instructions can suffice. By reducing the number of instructions required, the number of clock cycles needed to produce the same result is greatly reduced. Embodiments of the present invention also use shuffle instructions to access multiple values in a table with a SIMD instructions. Even in the case where the a table is twice the size of a register, algorithms in accordance with the present invention allow for accesses to data elements at a faster rate than the one data element per instruction as with integer operations.[0045]
FIG. 1A is a block diagram of an exemplary computer system formed with a processor that includes execution units to execute an instruction for shuffling data in accordance with one embodiment of the present invention.[0046]System100 includes a component, such as aprocessor102 to employ execution units including logic to perform algorithms for shuffling data, in accordance with the present invention, such as in the embodiment described herein.System100 is representative of processing systems based on the PENTIUM® III,PENTIUM®4, Celeron®, Xeon™, Itanium®, XScale™ and/or StrongARM™ microprocessors available from Intel Corporation of Santa Clara, Calif., although other systems (including PCs having other microprocessors, engineering workstations, set-top boxes and the like) may also be used. In one embodiment,sample system100 may execute a version of the WINDOWS™ operating system available from Microsoft Corporation of Redmond, Washington, although other operating systems (UNIX and Linux for example), embedded software, and/or graphical user interfaces, may also be used. Thus, the present invention is not limited to any specific combination of hardware circuitry and software.
The present enhancement is not limited to computer systems. Alternative embodiments of the present invention can be used in other devices such as handheld devices and embedded applications. Some examples of handheld devices include cellular phones, Internet Protocol devices, digital cameras, personal digital assistants (PDAs), and handheld PCs. Embedded applications can include a micro controller, a digital signal processor (DSP), system on a chip, network computers (NetPC), set-top boxes, network hubs, wide area network (WAN) switches, or any other system that performs integer shuffle operations on operands. Furthermore, some architectures have been implemented to enable instructions to operate on several data simultaneously to improve the efficiency of multimedia applications. As the type and volume of data increases, computers and their processors have to be enhanced to manipulate data in more efficient methods.[0047]
FIG. 1A is a block diagram of a[0048]computer system100 formed with aprocessor102 that includes one ormore execution units108 to perform a data shuffle algorithm in accordance with the present invention. The present embodiment is described in the context of a single processor desktop or server system, but alternative embodiments can be included in a multiprocessor system.System100 is an example of a hub architecture. Thecomputer system100 includes aprocessor102 to process data signals. Theprocessor102 can be a complex instruction set computer (CISC) microprocessor, a reduced instruction set computing (RISC) microprocessor, a very long instruction word (VLIW) microprocessor, a processor implementing a combination of instruction sets, or any other processor device, such as a digital signal processor, for example. Theprocessor102 is coupled to aprocessor bus110 that can transmit data signals between theprocessor102 and other components in thesystem100. The elements ofsystem100 perform their conventional functions that are well known to those familiar with the art.
In one embodiment, the[0049]processor102 includes a Level1 (L1)internal cache memory104. Depending on the architecture, theprocessor102 can have a single internal cache or multiple levels of internal cache. Alternatively, in another embodiment, the cache memory can reside external to theprocessor102. Other embodiments can also include a combination of both internal and external caches depending on the particular implementation and needs.Register file106 can store different types of data in various registers including integer registers, floating point registers, status registers, and instruction pointer register.
[0050]Execution unit108, including logic to perform integer and floating point operations, also resides in theprocessor102. Theprocessor102 also includes a microcode (ucode) ROM that stores microcode for certain macroinstructions. For this embodiment,execution unit108 includes logic to handle a packedinstruction set109. In one embodiment, the packedinstruction set109 includes a packed shuffle instruction for organizing data. By including the packedinstruction set109 in the instruction set of a general-purpose processor102, along with associated circuitry to execute the instructions, the operations used by many multimedia applications may be performed using packed data in a general-purpose processor102. Thus, many multimedia applications can be accelerated and executed more efficiently by using the full width of a processor's data bus for performing operations on packed data. This can eliminate the need to transfer smaller units of data across the processor's data bus to perform one or more operations one data element at a time.
Alternate embodiments of an[0051]execution unit108 can also be used in micro controllers, embedded processors, graphics devices, DSPs, and other types of logic circuits.System100 includes amemory120.Memory120 can be a dynamic random access memory (DRAM) device, a static random access memory (SRAM) device, flash memory device, or other memory device.Memory120 can store instructions and/or data represented by data signals that can be executed by theprocessor102.
A[0052]system logic chip116 is coupled to theprocessor bus110 andmemory120. Thesystem logic chip116 in the illustrated embodiment is a memory controller hub (MCH). Theprocessor102 can communicate to theMCH116 via aprocessor bus110. TheMCH116 provides a highbandwidth memory path118 tomemory120 for instruction and data storage and for storage of graphics commands, data and textures. TheMCH116 is to direct data signals between theprocessor102,memory120, and other components in thesystem100 and to bridge the data signals betweenprocessor bus110,memory120, and system I/O122. In some embodiments, thesystem logic chip116 can provide a graphics port for coupling to agraphics controller112. TheMCH116 is coupled tomemory120 through amemory interface118. Thegraphics card112 is coupled to theMCH116 through an Accelerated Graphics Port (AGP)interconnect114.
[0053]System100 uses a proprietaryhub interface bus122 to couple theMCH116 to the I/O controller hub (ICH)130. TheICH130 provides direct connections to some I/O devices via a local I/O bus. The local I/O bus is a high-speed I/O bus for connecting peripherals to thememory120, chipset, andprocessor102. Some examples are the audio controller, firmware hub (flash BIOS)128,wireless transceiver126,data storage124, legacy I/O controller containing user input and keyboard interfaces, a serial expansion port such as Universal Serial Bus (USB), and anetwork controller134. Thedata storage device124 can comprise a hard disk drive, a floppy disk drive, a CD-ROM device, a flash memory device, or other mass storage device.
For another embodiment of a system, an execution unit to execute an algorithm with a shuffle instruction can be used with a system on a chip. One embodiment of a system on a chip comprises of a processor and a memory. The memory for one such system is a flash memory. The flash memory can be located on the same die as the processor and other system components. Additionally, other logic blocks such as a memory controller or graphics controller can also be located on a system on a chip.[0054]
FIG. 1B illustrates an alternative embodiment of a[0055]data processing system140 which implements the principles of the present invention. One embodiment ofdata processing system140 is an Intel® Personal Internet Client Architecture (Intel® PCA) applications processors with Intel XScale™ technology (as described on the world-wide web at developer.intel.com). It will be readily appreciated by one of skill in the art that the embodiments described herein can be used with alternative processing systems without departure from the scope of the invention.
[0056]Computer system140 comprises aprocessing core159 capable of performing SIMD operations including a shuffle. For one embodiment, processingcore159 represents a processing unit of any type of architecture, including but not limited to a CISC, a RISC or a VLIW type architecture. Processingcore159 may also be suitable for manufacture in one or more process technologies and by being represented on a machine readable media in sufficient detail, may be suitable to facilitate said manufacture.
[0057]Processing core159 comprises anexecution unit142, a set of register file(s)145, and adecoder144. Processingcore159 also includes additional circuitry (not shown) which is not necessary to the understanding of the present invention.Execution unit142 is used for executing instructions received by processingcore159. In addition to recognizing typical processor instructions,execution unit142 can recognize instructions in packedinstruction set143 for performing operations on packed data formats.Packed instruction set143 includes instructions for supporting shuffle operations, and may also include other packed instructions.Execution unit142 is coupled to register file145 by an internal bus.Register file145 represents a storage area onprocessing core159 for storing information, including data. As previously mentioned, it is understood that the storage area used for storing the packed data is not critical.Execution unit142 is coupled todecoder144.Decoder144 is used for decoding instructions received by processingcore159 into control signals and/or microcode entry points. In response to these control signals and/or microcode entry points,execution unit142 performs the appropriate operations.
[0058]Processing core159 is coupled withbus141 for communicating with various other system devices, which may include but are not limited to, for example, synchronous dynamic random access memory (SDRAM)control146, static random access memory (SRAM)control147, burstflash memory interface148; personal computer memory card international association (PCMCIA)/compact flash (CF)card control149, liquid crystal display (LCD)control150, direct memory access (DMA)controller151, and alternativebus master interface152. In one embodiment,data processing system140 may also comprise an I/O bridge154 for communicating with various I/O devices via an I/O bus153. Such I/O devices may include but are not limited to, for example, universal asynchronous receiver/transmitter (UART)155, universal serial bus (USB)156,Bluetooth wireless UART157 and I/O expansion interface158.
One embodiment of[0059]data processing system140 provides for mobile, network and/or wireless communications and aprocessing core159 capable of performing SIMD operations including a shuffle operation. Processingcore159 may be programmed with various audio, video, imaging and communications algorithms including discrete transformations such as a Walsh-Hadamard transform, a fast Fourier transform (FFT), a discrete cosine transform (DCT), and their respective inverse transforms; compression/decompression techniques such as color space transformation, video encode motion estimation or video decode motion compensation; and modulation/demodulation (MODEM) functions such as pulse coded modulation (PCM).
FIG. 1C illustrates yet alternative embodiments of a data processing system capable of performing SIMD shuffle operations. In accordance with one alternative embodiment,[0060]data processing system160 may include amain processor166, aSIMD coprocessor161, acache memory167, and an input/output system168. The input/output system168 may optionally be coupled to awireless interface169.SIMD coprocessor161 is capable of performing SIMD operations including data shuffles. Processingcore170 may be suitable for manufacture in one or more process technologies and by being represented on a machine readable media in sufficient detail, may be suitable to facilitate the manufacture of all or part ofdata processing system160 includingprocessing core170.
For one embodiment,[0061]SIMD coprocessor161 comprises anexecution unit162 and a set of register file(s)164. One embodiment ofmain processor165 comprises adecoder165 to recognize instructions ofinstruction set163 including SIMD shuffle instructions for execution byexecution unit162. For alternative embodiments,SIMD coprocessor161 also comprises at least part ofdecoder165B to decode instructions ofinstruction set163. Processingcore170 also includes additional circuitry (not shown) which is not necessary to the understanding of the present invention.
In operation, the[0062]main processor166 executes a stream of data processing instructions that control data processing operations of a general type including interactions with thecache memory167, and the input/output system168. Embedded within the stream of data processing instructions are SIMD coprocessor instructions. Thedecoder165 ofmain processor166 recognizes these SIMD coprocessor instructions as being of a type that should be executed by an attachedSIMD coprocessor161. Accordingly, themain processor166 issues these SIMD coprocessor instructions (or control signals representing SIMD coprocessor instructions) on thecoprocessor bus166 where from they are received by any attached SIMD coprocessors. In this case, theSIMD coprocessor161 will accept and execute any received SIMD coprocessor instructions intended for it.
Data may be received via[0063]wireless interface169 for processing by the SIMD coprocessor instructions. For one example, voice communication may be received in the form of a digital signal, which may be processed by the SIMD coprocessor instructions to regenerate digital audio samples representative of the voice communications. For another example, compressed audio and/or video may be received in the form of a digital bit stream, which may be processed by the SIMD coprocessor instructions to regenerate digital audio samples and/or motion video frames. For one embodiment ofprocessing core170,main processor166, and aSIMD coprocessor161 are integrated into asingle processing core170 comprising anexecution unit162, a set of register file(s)164, and adecoder165 to recognize instructions ofinstruction set163 including SIMD shuffle instructions.
FIG. 2 is a block diagram of the micro-architecture for a[0064]processor200 of one embodiment that includes logic circuits to perform shuffle operations in accordance with the present invention. The shuffle operation may also be referred to as a packed data shuffle operation and packed shuffle instruction as in the discussion above. For one embodiment of the shuffle instruction, the instruction can shuffle packed data with a byte granularity. That instruction can also be referred to as PSHUFB or packed shuffle byte. In other embodiments, the shuffle instruction can also be implemented to operate on data elements having sizes of word, doubleword, quadword, etc. The in-orderfront end201 is the part of theprocessor200 that fetches the macro-instructions to be executed and prepares them to be used later in the processor pipeline. Thefront end201 of this embodiment includes several units. Theinstruction prefetcher226 fetches macro-instructions from memory and feeds them to aninstruction decoder228 which in turn decodes them into primitives called micro-instructions or micro-operations (also called micro op or uops) that the machine know how to execute. Thetrace cache230 takes decoded uops and assembles them into program ordered sequences or traces in theuop queue234 for execution. When thetrace cache230 encounters a complex macro-instruction, themicrocode ROM232 provides the uops needed to complete the operation.
Many macro-instructions are converted into a single micro-op, and others need several micro-ops to complete the full operation. In this embodiment, if more than four micro-ops are needed to complete a macro-instruction, the[0065]decoder228 accesses themicrocode ROM232 to do the macro-instruction. For one embodiment, a packed shuffle instruction can be decoded into a small number of micro ops for processing at theinstruction decoder228. In another embodiment, an instruction for a packed data shuffle algorithm can be stored within themicrocode ROM232 should a number of micro-ops be needed to accomplish the operation. Thetrace cache230 refers to a entry point programmable logic array (PLA) to determine a correct micro-instruction pointer for reading the micro-code sequences for the shuffle algorithms in themicro-code ROM232. After themicrocode ROM232 finishes sequencing micro-ops for the current macro-instruction, thefront end201 of the machine resumes fetching micro-ops from thetrace cache230.
Some SIMD and other multimedia types of instructions are considered complex instructions. Most floating point related instructions are also complex instructions. As such, when the[0066]instruction decoder228 encounters a complex macro-instruction, themicrocode ROM232 is accessed at the appropriate location to retrieve the microcode sequence for that macro-instruction. The various micro-ops needed for performing that macro-instruction are communicated to the out-of-order execution engine203 for execution at the appropriate integer and floating point execution units.
The out-of-[0067]order execution engine203 is where the micro-instructions are prepared for execution. The out-of-order execution logic has a number of buffers to smooth out and re-order the flow of micro-instructions to optimize performance as they go down the pipeline and get scheduled for execution. The allocator logic allocates the machine buffers and resources that each uop needs in order to execute. The register renaming logic renames logic registers onto entries in a register file. The allocator also allocates an entry for each uop in one of the two uop queues, one for memory operations and one for non-memory operations, in front of the instruction schedulers: memory scheduler,fast scheduler202, slow/general floatingpoint scheduler204, and simple floatingpoint scheduler206. Theuop schedulers202,204,206, determine when a uop is ready to execute based on the readiness of their dependent input register operand sources and the availability of the execution resources the uops need to complete their operation. Thefast scheduler202 of this embodiment can schedule on each half of the main clock cycle while the other schedulers can only schedule once per main processor clock cycle. The schedulers arbitrate for the dispatch ports to schedule uops for execution.
Register files[0068]208,210, sit between theschedulers202,204,206, and theexecution units212,214,216,218,220,222,224 in theexecution block211. There is aseparate register file208,210, for integer and floating point operations, respectively. Eachregister file208,210, of this embodiment also includes a bypass network that can bypass or forward just completed results that have not yet been written into the register file to new dependent uops. Theinteger register file208 and the floatingpoint register file210 are also capable of communicating data with the other. For one embodiment, theinteger register file208 is split into two separate register files, one register file for thelow order 32 bits of data and a second register file for thehigh order 32 bits of data. The floatingpoint register file210 of one embodiment has 128 bit wide entries because floating point instructions typically have operands from 64 to 128 bits in width.
The[0069]execution block211 contains theexecution units212,214,216,218,220,222,224, where the instructions are actually executed. This section includes the register files208,210, that store the integer and floating point data operand values that the micro-instructions need to execute. Theprocessor200 of this embodiment is comprised of a number of execution units: address generation unit (AGU)212,AGU214,fast ALU216,fast ALU218,slow ALU220, floatingpoint ALU222, floatingpoint move unit224. For this embodiment, the floating point execution blocks222,224, execute floating point, MMX, SIMD, and SSE operations. The floatingpoint ALU222 of this embodiment includes a floating point divider to execute divide, square root, and remainder micro-ops. For embodiments of the present invention, any act involving a floating point value occurs with the floating point hardware. For example, conversions between integer format and floating point format involve a floating point register file. Similarly, a floating point divide operation happens at a floating point divider. On the other hand, non-floating point numbers and integer type are handled with integer hardware resources. The simple, very frequent ALU operations go to the high-speedALU execution units216,218. Thefast ALUs216,218, of this embodiment can execute fast operations with an effective latency of half a clock cycle. For one embodiment, most complex integer operations go to theslow ALU220 as theslow ALU220 includes integer execution hardware for long latency type of operations, such as a multiplier, shifts, flag logic, and branch processing. Memory load/store operations are executed by theAGUs212,214. For this embodiment, theinteger ALUs216,218,220, are described in the context of performing integer operations on 64 bit data operands. In alternative embodiments, theALUs216,218,220, can be implemented to support a variety of data bits including 16, 32, 128, 256, etc. Similarly, the floatingpoint units222,224, can be implemented to support a range of operands having bits of various widths. For one embodiment, the floatingpoint units222,224, can operate on 128 bits wide packed data operands in conjunction with SIMD and multimedia instructions.
In this embodiment, the[0070]uops schedulers202,204,206, dispatch dependent operations before the parent load has finished executing. As uops are speculatively scheduled and executed inprocessor200, theprocessor200 also includes logic to handle memory misses. If a data load misses in the data cache, there can be dependent operations in flight in the pipeline that have left the scheduler with temporarily incorrect data. A replay mechanism tracks and re-executes instructions that use incorrect data. Only the dependent operations need to be replayed and the independent ones are allowed to complete. The schedulers and replay mechanism of one embodiment of a processor are also designed to catch instruction sequences for shuffle operations.
The term “registers” is used herein to refer to the on-board processor storage locations that are used as part of macro-instructions to identify operands. In other words, the registers referred to herein are those that are visible from the outside of the processor (from a programmer's perspective). However, the registers of an embodiment should not be limited in meaning to a particular type of circuit. Rather, a register of an embodiment need only be capable of storing and providing data, and performing the functions described herein. The registers described herein can be implemented by circuitry within a processor using any number of different techniques, such as dedicated physical registers, dynamically allocated physical registers using register renaming, combinations of dedicated and dynamically allocated physical registers, etc. In one embodiment, integer registers[0071]store 32 bit integer data. A register file of one embodiment also contains eight multimedia SIMD registers for packed data. For the discussions below, the registers are understood to be data registers designed to hold packed data, such as 64 bits wide MMX™ registers (also referred to as ‘mm’ registers in some instances) in microprocessors enabled with MMX technology from Intel Corporation of Santa Clara, Calif. These MMX registers, available in both integer and floating point forms, can operated with packed data elements that accompany SIMD and SSE instructions. Similarly, 128 bits wide XMM registers relating to SSE2 technology can also be used to hold such packed data operands. In this embodiment, in storing packed data and integer data, the registers do not need to differentiate between the two data types.
In the examples of the following figures, a number of data operands are described. For simplicity, the initial source data segments are labeled from letter A onwards alphabetically, wherein A is located at the lowest address and Z would be located at the highest address. Thus, A may initially be at[0072]address0, B ataddress1, C ataddress3, and so on. Conceptually, a shuffle operation, as in the packed byte shuffle for one embodiment, entails shuffling data segments from a first operand and rearranging one or more of the source data elements into a pattern specified by a set of masks in a second operand. Thus, a shuffle can rotate or completely rearrange a portion of or all of the data elements into any desired order. Furthermore, any particular data element or number of data elements can be duplicated or broadcasted in the resultant. Embodiments of the shuffle instruction in accordance with the present invention include a flush to zero functionality wherein the mask for each particular data element can cause that data element position to be zeroed out in the resultant.
FIGS.[0073]3A-C are illustrations of shuffle masks according to various embodiments of the present invention. A packeddata operand310 comprised of a plurality ofindividual data elements311,312,313,314, is shown in this example. The packedoperand310 of this example is described in the context of a packed data operand for containing a set of masks to indicate a shuffle pattern for corresponding packed data elements of another operand. Thus, the mask in each of thedata elements311,312,313,314, of packedoperand310 designates the contents in the corresponding data element position of the resultant. For example,data element311 is in the leftmost data element position. The mask indata element311 is to designate what data should be shuffled or placed in the leftmost data element position of the resultant for the shuffle operation. Similarly,data element312 is the second leftmost data element position. The mask indata element312 is to designate what data should be placed in the second leftmost data element position of the resultant. For this embodiment, each of the data elements in the packed operand containing the shuffle masks has a one to one correspondence to a data element position in the packed resultant.
In FIG. 3A,[0074]data element312 used to describe the contents of an example shuffle mask for one embodiment. Theshuffle mask318 for one embodiment is comprised of three portions: a ‘set to zero flag’field315, a ‘reserved’field316, and a ‘selections bits’field317. The ‘set to zero flag’field315 is to indicate whether the resultant data element position designated by the present mask should be zeroed out, or in other words, replaced with a value of zero (‘0’). In one embodiment, the ‘set to zero flag’ field is dominant wherein if the ‘set to zero flag’field315 is set, the rest of the fields in themask318 are ignored and the resultant data element position is filled with ‘0’. The ‘reserved’field316 includes one or more bits that may or may not be used in alternative embodiments or may have been reserved for future or special use. The ‘selection bits’field317 of thisshuffle mask318 is to designate the source of the data for the corresponding data element position in the packed resultant.
For one embodiment of a packed data shuffle instruction, one operand is comprised of a set of masks and another operand is comprised of a set of packed data elements. Both operands are of the same size. Depending on the number of the data elements in the operands, a varying number of selection bits are needed to select an individual data element from the second packed data operand for placement in the packed resultant. For example, with a 128 bit source operand of packed bytes, at least four selection bits are needed as sixteen byte data elements are available for selection. Based on the value indicated by the selection bits of the mask, the appropriate data element from the source data operand is placed in the corresponding data element position for that mask. For example, the[0075]mask318 ofdata element312 corresponds to the second leftmost data element position. If theselection bits317 of thismask318 contain a value of ‘X’, the data element from data element position ‘X’ in the source data operand is shuffled into the second leftmost data element position in the resultant. But if the ‘set to zero flag’field315 is set, the second leftmost data element position in the resultant is replaced with ‘0’ and the designation of theselection bits317 ignored.
FIG. 3B illustrates the structure of a[0076]mask328 for one embodiment that operates with byte size data elements and 128 bit wide packed operands. For this embodiment, the ‘set to zero’field325 is comprised ofbit7 and the ‘selection’field327 is comprised ofbits3 through0 as there are sixteen possible data element selections.Bits6 through4 are not used in this embodiment and reside in the ‘reserved’field326. In another embodiment, the number of bits used in the ‘selection’field327 can be increased or decreased as needed in order to accommodate the number of possible data element selections available in the source data operand.
FIG. 3C illustrates the structure of a[0077]mask338 for another embodiment that operates with byte size data elements and 128 bit wide packed operands, but with multiple data element sources. In this embodiment, themask338 is comprised of a ‘set to zero’field335, a ‘source (src) select’field336, and a ‘selection’field337. The ‘set to zero’field335 and ‘selection’field337 function similar to the descriptions above. The ‘source select’field336 of this embodiment is to indicate from which data source the data operand specified by the selection bits should be obtained. For example, the same set of masks may be used with multiple data sources such as a plurality of multimedia registers. Each source multimedia register is assigned a numeric value and the value in the ‘source select’field336 points to one of these source registers. Depending on the contents of the ‘source select’field336, the selected data element is selected from the appropriate data source for placement at that corresponding data element position in the packed resultant.
FIG. 4A is an illustration of various packed data type representations in multimedia registers according to one embodiment of the present invention. FIG. 4A illustrates a data types for packed[0078]byte410, packedword420, and a packed doubleword (dword)430 for 128 bits wide operands. The packedbyte format410 of this example is 128 bits long and contains sixteen packed byte data elements. A byte is defined here as 8 bits of data. Information for each byte data element is stored inbit7 throughbit0 forbyte0,bit15 throughbit8 forbyte1,bit23 throughbit16 forbyte2, and finally bit120 throughbit127 forbyte15. Thus, all available bits are used in the register. This storage arrangement increases the storage efficiency of the processor. As well, with sixteen data elements accessed, one operation can now be performed on sixteen data elements in parallel.
Generally, a data element is an individual piece of data that is stored in a operand (single register or memory location) with other data elements of the same length. In packed data sequences relating to SSE[0079]2 technology, the number of data elements stored in an operand (XMM register or memory location) is 128 bits divided by the length in bits of an individual data element. Similarly, in packed data sequences relating to MMX and SSE technology, the number of data elements stored in an operand (MMX register or memory location) is 64 bits divided by the length in bits of an individual data element. The packedword format420 of this example is 128 bits long and contains eight packed word data elements. Each packed word contains sixteen bits of information. The packeddoubleword format430 of FIG. 4A is 128 bits long and contains four packed doubleword data elements. Each packed doubleword data element contains thirty two bits of information. A packed quadword is 128 bits long and contains two packed quadword data elements.
FIG. 4B illustrates alternative in-register data storage formats. Each packed data can include more than one independent data element. Three packed data formats are illustrated; packed[0080]half441, packed single442, and packed double443. One embodiment of packedhalf441, packed single442, and packed double443 contain fixed-point data elements. For an alternative embodiment one or more of packedhalf441, packed single442, and packed double443 may contain floating-point data elements. One alternative embodiment of packedhalf441 is one hundred twenty-eight bits long containing eight 16-bit data elements. One embodiment of packed single442 is one hundred twenty-eight bits long and contains four 32-bit data elements. One embodiment of packed double443 is one hundred twenty-eight bits long and contains two 64-bit data elements. It will be appreciated that such packed data formats may be further extended to other register lengths, for example, to 96-bits, 160-bits, 192-bits, 224-bits, 256-bits or more.
FIG. 4C is a depiction of one embodiment of an operation encoding (opcode)[0081]format460, having thirty-two or more bits, and register/memory operand addressing modes corresponding with a type of opcode format described in the “IA-32 Intel Architecture Software Developer's Manual Volume 2: Instruction Set Reference,” which is which is available from Intel Corporation, Santa Clara, Calif. on the world-wide-web (www) at intel.com/design/litcentr. The type of shuffle operation, may be encoded by one or more of fields461 and462. Up to two operand locations per instruction may be identified, including up to two source operand identifiers464 and465. For one embodiment of a shuffle instruction,destination operand identifier466 is the same as source operand identifier464. For an alternative embodiment,destination operand identifier466 is the same as source operand identifier465. Therefore, for embodiments of a shuffle operation, one of the source operands identified by source operand identifiers464 and465 is overwritten by the results of the shuffle operations. For one embodiment of the shuffle instruction, operand identifiers464 and465 may be used to identify 64-bit source and destination operands.
FIG. 4D is a depiction of another alternative operation encoding (opcode)[0082]format470, having forty or more bits.Opcode format470 corresponds withopcode format460 and comprises an optional prefix byte478. The type of shuffle operation, may be encoded by one or more of fields478,471, and472. Up to two operand locations per instruction may be identified by source operand identifiers474 and475 and by prefix byte478. For one embodiment of the shuffle instruction, prefix byte478 may be used to identify 128-bit source and destination operands. For one embodiment of the shuffle instruction,destination operand identifier476 is the same as source operand identifier474. For an alternative embodiment,destination operand identifier476 is the same as source operand identifier475. Therefore, for embodiments of shuffle operations, one of the source operands identified by source operand identifiers474 and475 is overwritten by the results of the shuffle operations. Opcode formats460 and470 allow register to register, memory to register, register by memory, register by register, register by immediate, register to memory addressing specified in part by MOD fields463 and473 and by optional scale-index-base and displacement bytes.
Turning next to FIG. 4E, in some alternative embodiments, 64 bit single instruction multiple data (SIMED) arithmetic operations may be performed through a coprocessor data processing (CDP) instruction. Operation encoding (opcode)[0083]format480 depicts one such CDP instruction having CDP opcode fields482 and489. The type of CDP instruction, for alternative embodiments of shuffle operations, may be encoded by one or more of fields483,484,487, and488. Up to three operand locations per instruction may be identified, including up to two source operand identifiers485 and490 and one destination operand identifier486. One embodiment of the coprocessor can operate on 8, 16, 32, and 64 bit values. For one embodiment, the shuffle operation is performed on fixed-point or integer data elements. In some embodiments, a shuffle instruction may be executed conditionally, using condition field481. For some shuffle instructions source data sizes may be encoded by field483. In some embodiments of a shuffle instruction, Zero (Z), negative (N), carry (C), and overflow (V) detection can be done on SIMD fields. For some instructions, the type of saturation may be encoded by field484.
FIG. 5 is a block diagram of one embodiment of logic to perform a shuffle operation on a data operand based on a shuffle mask in accordance with the present invention. The instruction (PSHUFB) for shuffle operation with a set to zero capability of this embodiment begins with two pieces of information a first (mask)[0084]operand510 and a second (data)operand520. For the following discussions, MASK, DATA, and RESULTANT are generally referred to as operands or data blocks, but not restricted as such, and also include registers, register files, and memory locations. In one embodiment, the shuffle PSHUFB instruction is decoded into one micro-operation. In an alternative embodiment, the instruction may be decoded into a various number of micro-ops to perform the shuffle operation on the data operands. For this example, theoperands510,520, are 128 bit wide pieces of information stored in a source register/memory having byte wide data elements. In one embodiment, theoperands510,520, are held in 128 bit long SIMD registers, such as 128 bit SSE2 XMM registers. However, one or both of theoperands510,520, can also be loaded from a memory location. For one embodiment, theRESULTANT540 is also a MMX or XMM data register. Furthermore,RESULTANT540 may also be the same register or memory location as one of the source operands. Depending on the particular implementation, the operands and registers can be other widths such as 32, 64, and 256 bits, and have word, doubleword, or quadword sized data elements. Thefirst operand510 in this example is comprised of a set of sixteen masks (in hexadecimal format): 0x0E, 0x0A, 0x09, 0x8F, 0x02, 0x0E, 0x06, 0x06, 0x06, 0xF0, 0x04, 0x08, 0x08, 0x06, 0x0D, and 0x00. Each individual mask is to specify the contents of its corresponding data element position in the resultant540.
The[0085]second operand520 is comprised of sixteen data segments: P, O, N, M, L, K, J, I, H, G, F, E, D, C, B, and A. Each data segment in thesecond operand520 is also labeled with a data element position value in hex format. The data segments here are of equal length and each comprise of a single byte (8 bits) of data. If each data element was a word (16 bits), doubleword (32 bits), or a quadword (64 bits), the 128 bit operands would have eight word wide, four doubleword wide, or two quadword wide data elements, respectively. However, another embodiment of the present invention can operate with other sizes of operands and data segments. Embodiments of the present invention are not restricted to particular length data operands, data segments, or shift counts, and can be sized appropriately for each implementation.
The[0086]operands510,520, can reside either in a register or a memory location or a register file or a mix. The data operands510,520, are sent to theshuffle logic530 of an execution unit in the processor along with a shuffle instruction. By the time the shuffle instruction reaches the execution unit, the instruction should have been decoded earlier in the processor pipeline. Thus the shuffle instruction can be in the form of a micro operation (uop) or some other decoded format. For this embodiment, the twodata operands510,520, are received atshuffle logic530. Theshuffle logic530 selects data elements from thesource data operand520 based on the values in themask operand510 and arranges/shuffles the selected data elements into the appropriate positions in the resultant540. Theshuffle logic530 also zeroes out the given data element positions in the resultant540 as specified. Here, the resultant540 is comprised of sixteen data segments: O, K, J, ‘0’, C, O, G, G, F, ‘0’, E, I, I, G, N, and A.
The operation of the[0087]shuffle logic530 is described here with a couple few of the data elements. The shuffle mask for the leftmost data element position in themask operand510 is 0x0E. Theshuffle logic530 interprets the various fields of the mask described as above in FIGS.3A-C. In this case, the ‘set to zero’ field is not set. The selection field, comprising the lower four bits or nibble, has a hex value of ‘E’. Theshuffle logic530 shuffles the data, O, in the data element position ‘0xE’ of thedata operand520 to the leftmost data element position of the resultant540. Similarly, the mask at the second leftmost data element position in themask operand510 is 0x0A. Theshuffle logic530 interprets the mask for that position. This selection field has a hex value of ‘A’. Theshuffle logic530 copies the data, K, in the data element position ‘0xA’ of thedata operand520 to the second leftmost data element position of the resultant540.
The[0088]shuffle logic530 of this embodiment also supports the flush to zero function of the shuffle instruction. The shuffle mask at the fourth data element position from the left for themask operand510 is 0x8F. Theshuffle logic510 recognizes that the ‘set to zero’ field is set as indicated by a ‘1’ atbit 8 of the mask. In response, the flush to zero directive trumps the selection field and theshuffle logic510 ignores the hex value ‘F’ in the selection field of that mask. A ‘0’ is placed in the corresponding fourth data element position from the left in the resultant540. For this embodiment, theshuffle logic530 evaluates the ‘set to zero’ and selection fields for each mask and does not care about the other bits that may exist outside of those fields in the mask, such as reserved bits or a source select field. This processing of the shuffle masks and data shuffling is repeated for the entire set of masks in themask operand510. For one embodiment, the masks are all processed in parallel. In another embodiment, a certain portion of the mask set and data elements can be processed together at a time.
With embodiments of the present shuffle instruction, data elements in an operand can be rearranged in various ways. Furthermore, certain data from particular data element can be repeated at multiple data element positions or even broadcasted to every position. For instance, the fourth and fifth masks both have a hex value of 0x08. As a result, the data, I, at data element position 0x8 of the[0089]data operand520 is shuffled into both the fourth and fifth data element positions from the right side of the resultant540. With the set to zero functionality, embodiments of the shuffle instruction can force any of the data element positions in the resultant540 to ‘0’.
Depending on the particular implementation, each shuffle mask can be used to designate the content of a single data element position in the resultant. As in this example, each individual byte wide shuffle mask corresponds to a byte wide data element position in the resultant[0090]540. In another embodiment, combinations of multiple masks can be used to designate blocks of data elements together. For example, two byte wide masks can be used together to designate a word wide data element. Shuffle masks are not restricted to being byte wide and can be any other size needed in that particular implementation. Similarly, data elements and data element positions can possess other granularities other than bytes.
FIG. 6 is a block diagram of one embodiment of a[0091]circuit600 for performing a data shuffling operation in accordance with the present invention. The circuit of this embodiment comprises a multiplexing structure to select the correct result byte from the first source operand based on decoding shuffle mask of the second operand. The source data operand here is comprised of the upper packed data elements and the lower packed data elements. The multiplexing structure of this embodiment is relatively simpler than other multiplexing structures used to implement other packed instructions. As a result, the multiplexing structure of this embodiment does not introduce any new critical timing path. Thecircuit600 of this embodiment includes a shuffle mask block, blocks to hold lower/upper packed data elements from source operands, a first plurality of eight to one (8:1) muxes for initial selection of data elements, another plurality of three to one (3:1) muxes for selection of upper and lower data elements, mux select & zero logic and a multitude of control signals. For simplicity, a limited number of the 8:1 and 3:1 muxes are shown in FIG. 6 and represented by dots. However, their function is similar to those illustrated and can be understood from the description below.
During a shuffle operation in this example, two operands are received at this shuffle handling circuit[0092]600: a first operand with a set of packed data elements and a second operand with a set of shuffle masks. The shuffle masks are propagated to shufflemask block602. The set of shuffle masks are decoded at the mux select and zerologic block604 to generate a variety of select signals (SELECT A606,SELECT B608, SELECT C610) and a set to zero signal (ZERO)611. These signals are used to control the operation of the muxes in piecing together the resultant632.
For this example, the mask operand and data operand are both 128 bits long and each are packed with of sixteen byte size data segments. The value N as shown on various signals is sixteen in this case. In this embodiment, the data elements are separated into a set of lower and upper packed data elements, each set having eight data elements. This allows for the use of smaller[0093]8:1 muxes during the data element selection rather than 16:1 muxes. These lower and upper sets of packed data elements are held at lower andupper storage areas612,622, respectively. Starting with the lower data set, each of the eight data elements are sent to the first set of sixteen individual 8:1muxes618A-D via a set of lines such as routing lines614. Each of the sixteen 8:1muxes618A-D are controlled with one of the N SELECT A signals606. Depending on the value of itsSELECT A606, that mux is to output one of the eightlower data elements614 for further processing. There are sixteen 8:1 muxes for the set of lower packed data elements as it is possible to shuffle any of the lower data elements into any of the sixteen resultant data element positions. Each of the sixteen 8:1 muxes is for one of the sixteen resultant data element positions. Similarly, sixteen 8:1 muxes are present for the upper packed data elements. The eight upper data elements are sent to each of the second set of sixteen 8:1muxes624A-D. Each of the sixteen 8:1muxes624A-D are controlled with one of the N SELECT B signals608. Based on the values of itsSELECT B608, that 8:1 mux is to output one of the eightupper data elements616 for further processing.
Each of the sixteen 3:1[0094]muxes628A-D corresponds to a data element position in the resultant632. The sixteenoutputs620A-D from the sixteen lower data muxes618A-D are routed to a set of sixteen 3:1 upper/lower selection muxes628A-D as are theoutputs626A-D from the upper data muxes624A-D. Each of these 3:1 selection muxes628D-D receives its ownSELECT C610 and a ZERO611 signals from the mux select & zerologic604. The value on theSELECT C610 for that 3:1 mux is to indicate whether the mux is to output the selected data operand from the lower data set or from the upper data set. The control signal ZERO611 to each 3:1 mux is to indicate whether that mux should force its output to zero (‘0’). For this embodiment, the control signal ZERO611 supercedes the selection onSELECT C610 and forces the output for that data element position to ‘0’ in the resultant632.
For example, 3:1[0095]mux628A receives the selectedlower data element620A from 8:1mux618A and the selectedupper data element626A from 8:1mux624A for that data element position.SELECT C610 controls which of the data elements to shuffle at itsoutput630A into the data element position it manages in the resultant632. However, if signal ZERO611 to themux628A is active, indicated that the shuffle mask for that data element position states that a ‘0’ is desired, themux output630A is ‘0’ and neither of thedata element inputs620A,626A, are used. The resultant632 of the shuffle operation is composed of theoutputs630A-D from the sixteen 3:1muxes628A-D, wherein each output corresponds to a specific data element position and is either a data element or a ‘0’. In this example, each 3:1 mux output is a byte wide and the resultant is a data block composed of sixteen packed bytes of data.
FIG. 7 illustrates the operation of a data shuffle on byte wide data elements in accordance with one embodiment of the present invention. This is an example of the instruction “PSHUFB DATA, MASK”. Note that the most significant bit of shuffle masks for byte positions 0x6 and 0xC of[0096]MASK701 are set so the result in resultant741 for those positions are zero. In this example, source data is organized into a destinationdata storage device721, which in one embodiment is also the sourcedata storage device721, in view of a set ofmasks701 that specify the address wherein respective data elements from thesource operand721 are to be stored in thedestination register741. The two source operands,mask701 anddata721, each comprise of sixteen packed data elements in this example, as does the resultant741. In this embodiment, each of the data elements involved is a eight bits or a byte wide. Thus mask701,data721, and resultant741 data blocks are each 128 bits long. Furthermore, these data blocks can reside in memory or registers. For one embodiment, the arrangement of the masks is based on the desired data processing operation, which may include for example, a filtering operation or a convolution operation.
As shown in FIG. 7,[0097]mask operand701 includes data elements with shuffle masks of:0x0E702,0x0A703, 0x09704,0x8F705,0x02706,0x0E707,0x06708,0x06709,0x05710,0xF0711,0x04712,0x08713,0x08714,0x06715,0x0D716,0x00717. Similarly,data operand721 includes source data elements of:P722,O723,N724,M725,L726,K727,J728, I729,H730,G731,F732,E733,D734,C735,B736, A737. In the representations of data segments of FIG. 7, the data element position is also noted under the data as a hex value. Accordingly, a packed shuffle operation is performed with themask701 anddata721. Using the set ofshuffle masks701, processing of thedata721 can be performed in parallel.
As each of the data element shuffle masks are evaluated, the appropriate data from the designated data element or a ‘0’ is shuffled to the corresponding data element position for that particular shuffle mask. For instance, the right[0098]most shuffle mask717 has a value 0x00, which is decoded to designate data from position 0x0 of the source data operand. In response, data A from data position 0x0 is copied to the right most position of the resultant741. Similarly, thesecond shuffle mask716 from the right has a value of 0x0D, which is decoded to be 0xD. Thus data N from data position 0xD is copied to the second position from the right in the resultant741.
The fourth data element position from the left in the resultant[0099]741 is a ‘0’. This is attributed to the value of 0x8F in the shuffle mask for that data element position. In this embodiment,bit7 of the shuffle mask byte is a ‘set to zero’ or ‘flush to zero’ indicator. If this field is set, the corresponding data element position in the resultant is filled with a ‘0’ value instead of data from thesource data operand721. Similarly, the seventh position from the right in the resultant741 has a value of ‘0’. This is due to the shuffle mask value of 0xF0 for that data element position in themask701. Note that not all bits in the shuffle mask may be used in certain embodiments. In this embodiment, the lower nibble, or four bits, of a shuffle mask is sufficient to select any of the sixteen possible data elements in thesource data operand721. Asbit7 is the ‘set to zero’ field, three other bits remain unused and can be reserved or ignored in certain embodiments. For this embodiment, the ‘set to zero’ field controls and overrides the data element selection as indicated in the lower nibble of the shuffle mask. In both of these instances, the fourth data element position from the left and the seventh position from the right, a shuffle mask value of 0x80 wherein the ‘flush to zero’ flag is set at bit seven can also cause the corresponding resultant data element position to be filled with a ‘0’. As shown in FIG. 7, the arrows illustrate the shuffling of the data elements per the shuffle masks inmask701. Depending on the particular set of shuffle masks, one or more of the source data elements may not appear in the resultant741. In some instances, one or more ‘0’ s can also appear at various data element positions in the resultant741. If the shuffle masks are configured to broadcast one or a particular group of data elements, the data for those data elements may be repeated as a chosen pattern in the resultant. Embodiments of the present invention are not restricted to any particular arrangements or shuffle patterns.
As noted above, the source data register is also utilized as the destination data storage register in this embodiment, thereby reducing the number of registers needed. Although the[0100]source data721 is thus overridden, the set of shuffle masks701 is not altered and is available for future reference. Overwritten data within the source data storage device can be reloaded from memory or another register. In another embodiment, multiple registers can be used as the source data storage device, with their respective data organized within the destination data storage device as desired.
FIG. 8 illustrates the operation of a data shuffle operation on word wide data elements in accordance with another embodiment of the present invention. The general discussion of this example is somewhat similar to that of FIG. 7. In this scenario, however, the data elements of the[0101]data operand821 and resultant831 are word length. For this embodiment, the data element words are handled as pairs of data element bytes as the shuffle masks in themask operand801 are byte size. Thus a pair of shuffle mask bytes are used to define each data element word position. But for another embodiment, the shuffle masks can also have word granularity and describe word sized data element positions in the resultant.
The[0102]mask operand801 of this example includes byte wide data elements with shuffle masks of:0x03802,0x02803,0x0F804,0x0E805,0x83806,0x82807,0x0D808,0x0C809,0x05810,0x04811,0x0B812,0x0A813,0x0D814,0x0C815,0x01816,0x00817. Thedata operand821 includes source data elements of:H822,G823,F824,E835,D836,C827,B828, A829. In the representations of data segments of FIG. 8, the data element position is also noted under the data as a hex value. As shown in FIG. 8, each of the word size data elements in thedata operand821 have data position addresses it occupies two byte size positions. For example,data H822 takes up byte size data element positions 0xF and 0xE.
A packed shuffle operation is performed with the[0103]mask801 anddata821. The arrows in FIG. 8 illustrate the shuffling of the data elements per the shuffle masks inmask801. As each of the data element shuffle masks are evaluated, the appropriate data from the designated data element position of thedata operand821 or a ‘0’ is shuffled to the corresponding data element position in the resultant831 for that particular shuffle mask. In this embodiment, the byte size shuffle masks operate in pairs in order to designate word size data elements. For example, the two leftmost shuffle masks 0x03802,0x02803, in themask operand801 together correspond to the leftmost word widedata element position832 of the resultant831. During the shuffle operation, the two data bytes, or single data word, at data element byte positions 0x03 and 0x02, which in this case isdata B828, is arranged into the two leftmost byte size data element positions832 in the resultant831.
Furthermore, the shuffle masks can also be configured to force a word size data element to ‘0’ in the resultant as shown with shuffle masks 0x83[0104]806 and0x82807 for the third word sizedata element position834 in the resultant831. Shuffle masks 0x83806 and0x82807 have their ‘set to zero’ fields set. Although two shuffle mask bytes are paired together here, different pairings can also be implemented to arrange four bytes together as a quadword or eight bytes together to form a double quadword, for example. Similarly, the pairings are not restricted to consecutive shuffle masks or particular bytes. In another embodiment, word size shuffle masks can be used to designate word size data elements.
FIG. 9 is a[0105]flow chart900 illustrating one embodiment of a method to shuffle data. The length value of L is generally used here to represent the width of the operands and data blocks. Depending on the particular embodiment, L can be used to designate the width in terms of number of data segments, bits, bytes, words, etc. Atblock910, a first length L packed data operand is received for use with a shuffle operation. A length L set of M length shuffle masks designating a shuffle pattern is received atblock920. In this example, L is 128 bits and M is 8 bits or a byte. In another embodiment, L and M can also be other values, such as 256 and 16, respectively. Atblock930, the shuffle operation is performed wherein data elements from the data operand are shuffled arranged into a resultant in accordance to the shuffle pattern.
The details of the shuffle at[0106]block930 of this embodiment is further described in terms of what occurs for each data element position. For one embodiment, the shuffling for all of the packed resultant data element positions are processed in parallel. In another embodiment, a certain portion of the masks may be processed together at a time. Atblock932, a check is made to determine whether a zero flag is set. This zero flag refers to the set/flush to zero field of each shuffle mask. If the zero flag is determined as set atblock932, the entry at the resultant data element position corresponding to that particular shuffle mask is set to ‘0’. If the zero flag is found not set atblock932, the data from the source data element designated by the shuffle mask is arranged into the destination data element position of the resultant corresponding to that shuffle mask.
Currently, table lookups using integer instructions requires a large number of instructions. An even greater number of instructions are needed per lookup if integer operations are used to access data for algorithms implemented with SIMD instructions. But by using embodiments of a packed byte shuffle instruction, the instruction count and execution time is drastically reduced. For instance, sixteen data bytes can be accessed during a table lookup with a single instruction if the table size is sixteen bytes or less. Eleven SIMD instructions can be used to lookup table data if the table size is between seventeen and thirty two bytes. Twenty three SIMD instructions are needed if the table size is between thirty three and sixty four bytes.[0107]
There are some applications with data parallelism that cannot be implemented with SIMD instructions due to their use of lookup tables. The quantization and deblocking algorithms of the video compression method H.26L is an example of an algorithm that uses small lookup tables that may not fit into a 128 bit register. In some cases, the lookup tables used by these algorithms are small. If the table can fit in a single register, the table lookup operation can be accomplished with one packed shuffle instruction. But if the memory space requirement of the table exceeds the size of a single register, embodiments of a packed shuffle instruction can still work via a different algorithm. One embodiment of a method for handling oversized tables divides a table into sections, each equal to the capacity of a register, and accesses each of these table sections with a shuffle instruction. The shuffle instruction uses the same shuffle control sequence to access each section of the table. As a result, a parallel table lookup can be implemented in these cases with the packed byte shuffle instruction, thus permitting the use of SIMD instructions to improve algorithm performance. Embodiments of the present invention can help improve performance and reduce the number of memory accesses needed for algorithms that use small lookup tables. Other embodiments also permit access of multiple lookup table elements using SIMD instructions. A packed byte shuffle instruction in accordance to the present invention permits efficient SIMD instruction implementation instead of less efficient integer implantation of algorithms that use small lookup tables. This embodiment of the present invention demonstrates how to access data from a table that requires memory space larger than a single register. In this example, the registers contain different segments of the table.[0108]
FIGS.[0109]10A-H illustrate the operation of a parallel table lookup algorithm using SIMD instructions. The example described in FIGS.10A-H involves the lookup of data from multiple tables and wherein certain selected data elements as specified in a set of masks are shuffled from these multiple tables into a merged block of resultant data. The discussion below is explained in the context of packed operations, especially a packed shuffle instruction as disclosed in the earlier above text. The shuffle operation of this example overwrites the source table data in the register. If the table is to be reused following the lookup operation, the table data should be copied to another register before the operation is executed so that another load is not needed. In an alternative embodiment, the shuffle operation makes use of three separate registers or memory locations: two source and one destination. The destination in an alternative embodiment is a register or memory location that is different from either of the source operands. Thus, the source table data is not overridden and can be reused. In this example, the table data is treated as coming from different portions of a larger table. For example,LOW TABLE DATA1021 is from a lower address region of the table andHIGH TABLE DATA1051 is from a higher address region of the table. Embodiments of the present invention are not restrictive as to where the table data can originates. The data blocks1021,1051, can be adjacent, far apart, or even overlapping. Similarly, table data can also be from different data tables or different memory sources. It is also envisioned that such a table lookup and data merging can be performed on data from multiple tables. For instance, instead of coming from different parts of the same table,LOW TABLE DATA1021 can be from a first table andHIGH TABLE DATA1051 can be from a second table.
FIG. 10A illustrates a packed data shuffle of a first set of data elements from a table based on a set of shuffle masks. This first set of data elements is grouped as an operand named[0110]LOW TABLE DATA1021.MASK1001 andLOW TABLE DATA1021 are each comprised of sixteen elements in this example. A shuffle operation ofMASK1001 andLOW TABLE DATA1021 yields a resultantTEMP RESULTANT A1041. The lower portion of a shuffle control mask selects the data element in the register. The number of bits needed to select a data element is the number of register data elements in log2. For example, if the register capacity is 128 bits and the data type is bytes, the number of register data elements is sixteen. In this case, four bits are need to select a data element. FIG. 10B illustrates a packed data shuffle of a second set of data elements from a table based on the same set of shuffle masks of FIG. 10A. This second set of data elements is grouped as an operand namedHIGH TABLE DATA1051.HIGH TABLE DATA1051 is also comprised of sixteen elements in this example. A shuffle operation ofMASK1001 andHIGH TABLE DATA1051 yields a resultantTEMP RESULTANT B1042.
Because the same set of[0111]masks1001 were used with both theLOW TABLE DATA1021 andHIGH TABLE DATA1051, theirrespective resultants1041,1042, appear to have similarly positioned data, but from different source data. For example, the leftmost data position of bothresultants1041,1042, have data fromdata element 0xE1023,1053, of itsrespective data source1021,1051. FIG. 10C illustrates a logical packed AND operation involvingSELECT FILTER1043 and the set of shuffle masks MASK1001. SELECT FILTER in this case is a filter to distinguish which of the shuffle masks inMASK1001 are related to thefirst table data1021 and which to thesecond table data1051. The shuffle masks of this embodiment utilize the source select field,SRC SELECT336, as discussed previously in FIG. 3C. Lower bits of a shuffle control byte are used to select a data element position in a register and the upper bits, excluding the most significant bit, are used to select the segment of the table. For this embodiment, the bits immediately above and adjacent to those used to select the data select the section of the table.SELECT FILTER1043 applies 0x10 to all the shuffle masks inMASK1001 separate out the source select field from the shuffle masks. The packed AND operation yields a TABLESELECT MASK1044 that to indicate which data element position in the end resultant should be from thefirst data set1021 or thesecond data set1051.
The number of bits to select the table section is equal to the number of table sections in log[0112]2. For example, in the case of table sizes ranging from seventeen to thirty two bytes with sixteen byte registers, the lowest four bits select the data and the fifth bit selects the table section. Here, source select uses the lowest bit of the second nibble,bit4, of each shuffle mask to designate the data source as there are twodata sources1021,1051. The section of the table with indices between zero and fifteen is accessed with the packed shuffle instruction in FIG. 10A. The section of the table with indices between sixteen and thirty one is accessed with the packed shuffle instruction in FIG. 10B. The field that selects the section of the table is isolated from the shuffle control bytes/indices in FIG. 10C. In implementations with a larger number of data sources, additional bits may be needed the source select fields. In the case of a thirty two byte table, the shuffle control bytes 0x00 to 0x0F would select table elements zero through fifteen in the first table section and shuffle control bytes 0x10 to 0x1F would select table elements sixteen through thirty one in the second table section. For instance, consider a shuffle control byte specifies 0x19. The bit representation of 0x19 is 0001 1001. The lower four bits,1001, select the ninth byte (counting from 0) and the fifth bit, which is set to1, selects the second table of two tables. A fifth bit equal to 0 would select the first table.
A mask to selects data values accessed from the first table section with indices zero to fifteen is computed with a packed compare equal operation for this embodiment in FIG. 10D by selecting the shuffle control bytes whose fifth bit is a zero. FIG. 10D illustrates a packed “compare equal operation” of[0113]LOW FILTER1045 andTABLE SELECT MASK1044. The low table select mask produced in FIG. 10D for the first table section selects data elements accessed from the first table section with another packed shuffle operation.LOW FILTER1045 in this instance is a mask to pull out or highlight the data element positions indicated by the shuffle masks as coming from thefirst data set1021. If the source select field is ‘0’ in this embodiment, then the data source is to beLOW TABLE DATA1021. The compare equal operation yields a LOW TABLESELECT MASK1046 with 0xFF values for the data element positions that have a source select value of ‘0’.
A mask to selects data values accessed from the second table section with indices sixteen to thirty one is computed with a packed compare equal operation in FIG. 10E by selecting the shuffle control bytes whose fifth bit is a one. FIG. 10E illustrates a similar compare equal operation on[0114]HIGH FILTER1047 andTABLE SELECT MASK1044. The high table select mask produced in FIG. 10E for the second table section selects data elements accessed from the second table section with a packed shuffle operation.HIGH FILTER1047 is a mask to pull out the data element position indicated by the source select fields of the shuffle mask as coming from thesecond data set1051. If the source select field is ‘1’ in this embodiment, then the data source is to beHIGH TABLE DATA1051. The compare equal operation yields a HIGH TABLESELECT MASK1048 with 0xFF values for the data element position that have a source select value of ‘1’.
The data elements selected from the two table sections are merged at FIG. 10F. At FIG. 10F, a packed AND operation on LOW TABLE[0115]SELECT MASK1046 andTEMP RESULTANT A1041 is shown. This packed AND operation filters out the selected shuffled data elements from thefirst data set1021 per themask1046 that is based on the source select fields. For example, the source select field in theshuffle mask1002 for the leftmost data element position has a value of ‘0’ as shown inTABLE SELECT MASK1044. Accordingly, LOWTABLE SELECT MASK1046 has a 0xFF value in that position. The and operation here in FIG. 10F between that 0xFF and the data in the leftmost data element position causes the data O to transfer to SELECTEDLOW TABLE DATA1049. On the other hand, the source select field in theshuffle mask1004 for the third data element position from the left has a value of ‘1’ to indicate that the data is to come from a source other than thefirst data set1021. Accordingly, LOWTABLE SELECT MASK1046 has a 0x00 value in that position. The and operation here does not pass the data J to SELECTEDLOW TABLE DATA1049 and that position is left empty as 0x00.
A similar packed AND operation on HIGH TABLE[0116]SELECT MASK1048 andTEMP RESULTANT B1042 is shown in FIG. 10G. This packed AND operation filters out the selected shuffled data elements from thesecond data set1051 per themask1048. Unlike the packed AND operation described in FIG. 10F, themask1048 allows data designated by the source select fields as coming from the second set of data to pass to SELECTEDHIGH TABLE DATA1050 while the other data element positions are left empty.
FIG. 10H illustrates the merging of the selected data from the first data set and the second data set. A packed logical OR operation is performed on SELECTED[0117]LOW TABLE DATA1049 and SELECTEDHIGH TABLE DATA1050 to obtain MERGED SELECTEDTABLE DATA1070, which is the desired resultant of the parallel table lookup algorithm in this example. In an alternative embodiment, a packed addition operation to add together SELECTEDLOW TABLE DATA1049 and SELECTEDHIGH TABLE DATA1050 can also yield MERGEDSELECTED TABLE DATA1070. As shown in FIG. 10H, either SELECTEDLOW TABLE DATA1049 or SELECTEDHIGH TABLE DATA1050 has a 0x00 value for a given data position in this embodiment. This is because the other operand that does not have the 0x00 value is to contain the desired table data selected from the appropriate source. Here, the leftmost data element position in the resultant1070 is O, which is shuffleddata1041 from thefirst data set1021. Similarly, the third data element position from the left in the resultant1070 is Z, which is shuffleddata1042 from thesecond data set1051.
The method for looking up data in oversized tables in this example embodiment can be summarized generally with the following operations. First, copy or load the table data into registers. Table values from each table section are accessed with a packed shuffle operation. The source select fields that identify the table section are extracted from the shuffle masks. Compare-if-equal operations on the source select fields with the table section number to determine which table sections are the appropriate sources for the shuffled data elements. The compare-if-equal operations provides masks to further filter out the desired shuffled data elements for each table section. The desired data elements from the appropriate table sections are merged together to form the end table lookup resultant.[0118]
FIG. 11 is a flow chart illustrating one embodiment of a method to perform a table lookup using SIMD instructions. The flow described here generally follows the methodology of FIGS.[0119]10A-H, but is not restricted as such. Some of these operations can also be performed in different order or using various types of SIMD instructions. Atblock1102, a set of shuffle masks designating a shuffle pattern is received. These shuffle masks also include source fields to indicate from which table or source to shuffle data elements to obtain the desired resultant. Atblock1104, the data elements for a first portion of a table or a first data set is loaded. The first portion data elements are shuffled in accordance to the shuffle pattern ofblock1102 atblock1106. Data elements for a second portion of a table or a second data set is loaded atblock1108. The second portion data elements are shuffled in accordance to the shuffle pattern ofblock1102 atblock1110. Atblock1112, table selects are filtered out from the shuffle masks. The table selects of this embodiment involve the source select fields that designate where a data element is supposed to originate from. Atblock1114, a table select mask is generated for the shuffled data from the first portion of the table. A table select mask is generated for the shuffled data from the second portion of the table atblock1116. These table select masks are to filter out the desired shuffled data elements for specific data element positions from the appropriate table data source.
At[0120]block1118, data elements are selected from the shuffled data of the first table portion in accordance with a table select mask ofblock1114 for the first table portion. Data elements are selected atblock1120 from the shuffled data of the second table portion in accordance with the table select mask ofblock1116 for the second table portion. The shuffled data elements selected from the first table portion atblock1118 and from the second table portion atblock1120 are merged together atblock1122 to obtain merged table data. The merged table data of one embodiment includes data elements shuffled from both the first table data and the second table data. For another embodiment, the merged table data can include data looked up from more than two table sources or memory regions.
FIG. 12 is a flow chart illustrating another embodiment of a method to perform a table lookup. At[0121]block1202, a table having a plurality of data elements are loaded. A determination is made atblock1204 as to whether the table fits in a single register. If the table fits into a single register, the table lookup is performed with a shuffle operation atblock1216. If the data does not fit into a single register, table lookup is to be performed with shuffle operations for each relevant portion of the table atblock1206. A logical packed AND operation is performed to obtain the bits or field that select the table portion or data source. A “compare-if-equal” operation at block1210 creates a mask to select table data from the relevant portions of the table to be looked up. Atblock1212, a logical AND operation is used to look up and select data items from the table sections. A logical OR operation merges the selected data atblock1214 to obtain the desired table lookup data.
One embodiment of the packed shuffle instruction is implemented into an algorithm for rearranging data between multiple registers using the flush to zero capability. The objective of a mix operation is to merge the contents of two or more SIMD registers in a single SIMD register in a selected arrangement in which the positions of data in the resultant differ from their original position in the source operands. Selected data elements are first moved to desired result positions and unselected data elements are set to zero. The positions to which selected data elements were moved for one register are set to zero in other registers. Consequently, a single one of the result registers may contain a nonzero data item in a given data element position. The following general instruction sequence can be used to mix data from two operands:[0122]
packed byte shuffle DATA A, MASK A;[0123]
packed byte shuffle DATA B, MASK B;[0124]
packed logical OR RESULTANT A, RESULTANT B.[0125]
Operands DATA A and DATA B contain elements that are to be rearranged or set zero. Operands MASK A and MASK B contain shuffle control bytes that specify where data elements are to be moved and which data elements are to be set to zero. For this embodiment, data elements in destination positions not set to zero by MASK A are set to zero by MASK B and destination positions not set to zero by MASK B are set to zero by MASK A. FIGS.[0126]13A-C illustrates an algorithm for rearranging data between multiple registers. In this example, data elements from two data sources orregisters1304,1310, are shuffled together into an interleaveddata block1314. The datablocks including masks1302,1308,source data1304,1310, andresultants1306,1312,1314, of this example are each 128 bits long and composed of sixteen byte size data elements. However, alternative embodiments can include data blocks of other lengths having various sized data elements.
FIG. 13A illustrates a first packed data shuffle operation of a first mask,[0127]MASK A1302, on a first source data operand,DATA A1304. For this example, the desired interleaved resultant1314 is to include an interleaved pattern of one data element from afirst data source1304 and another data element from asecond data source1310. In this example, the fifth byte ofDATA A1304 is to be interleaved with the twelfth byte ofDATA B1310.MASK A1302 includes a repeated pattern of “0x80” and “0x05” in this embodiment. The 0x80 value in this embodiment has the set to zero field set, wherein the associated data element position is filled with ‘0’. The 0x05 value states that the associated data element position for that shuffle mask should be arranged with data F1from data element 0x5 ofDATA A1304. In essence, the shuffle pattern inMASK A1302 arranges and repeats data F1 at every other resultant data element position. Here, data F1 is the single piece of data to be shuffled fromDATA A1304. In alternative embodiments, data from various number of source data elements can be shuffled. Thus embodiments are not restricted to patterns involving a single piece of data or any particular pattern. The arrangement combinations for mask patterns are open to all kinds of possibilities. The arrows in FIG. 13A illustrate the shuffling of the data elements per the shuffle masks ofMASK A1302.RESULTANT A1306 of this shuffle operation is thus comprised of a pattern of ‘0’ and F1per themask pattern1302.
FIG. 13B illustrates a second packed data shuffle operation involving a second mask,[0128]MASK B1308, together with a second source data operand,DATA B1310.MASK B1308 includes a repeated pattern of “0x0C” and “0x80”. The 0x80 value causes the associated data position for that shuffle mask to receive ‘0’. The 0xC0 value causes the resultant data element position corresponding to that shuffle mask to be arranged with data M2from data element 0xC ofDATA B1310. The shuffle pattern ofMASK B1308 arranges data M2to every other resultant data element position. The arrows in FIG. 13B illustrate the shuffling of the data elements per the set of shuffle masks inMASK B1308.RESULTANT B1312 of this shuffle operation is thus comprised of a pattern of ‘0’ and M2per themask pattern1308.
FIG. 13C illustrates the merging of the shuffled data,[0129]RESULTANT A1306 andRESULTANT B1312 to achieveINTERLEAVED RESULTANT1314. The merging is accomplished with a packed logical OR operation. The pattern of ‘0’ values inRESULTANT A1306 andRESULTANT B1312 allow for the interleaving of the M2 and F1 data values1314. For example, at the leftmost data element position, the logical OR of ‘0’ and M2 results in M2 in the leftmost data element position of the resultant1314. Similarly, at the rightmost data element position, the logical OR of F1and ‘0’ results in F1in the rightmost data element position of the resultant1314. Thus data from multiple registers or memory locations can be rearranged into a desired pattern.
FIG. 14 is a flow chart illustrating one embodiment of a method to rearrange data between multiple registers. Data is loaded from a first register or memory location at[0130]block1402. The first register data is shuffled atblock1404 based on a first set of shuffle masks. Atblock1406, data is loaded from a second register or memory location. This second register data is shuffled atblock1408 in accordance with a second set of shuffle masks. The shuffled data from the first and second register shuffles are merged atblock1410 with a logical OR to arrive at an interleaved data block with data from the first and second register.
FIGS.[0131]15A-K illustrates an algorithm for shuffling data between multiple registers to generate interleaved data. This is an example of an application that interleaves planar color data. Image data is often processed in separate color planes and then these planes are later interleaved for display. The algorithm described below demonstrates interleaving for red plane, green plane, and blue plane data as used by image formats such as bitmaps. Numerous color spaces and interleave patterns are possible. As such, this approach can easily be extended to other color spaces and formats. This example implements an often used image processing data format process wherein red (R) plane, green (G) plane, and blue (B) plane data are interleaved into an RGB format. This example demonstrates how the flush to zero capability in accordance to the present invention significantly reduces memory accesses.
Data from three sources are combined together in an interleaved fashion. More particularly, the data relates to pixel color data. For example, color data for each pixel can include information from red (R), green (G), and blue (B) sources. By combining the color information, the red/green/blue (RGB) data can be evaluated to provide the desired color for that particular pixel. Here, the red data is held in[0132]operand DATA A1512, the green data in dataoperand DATA B1514, and the blue data inDATA C1516. This arrangement can exist in an graphics or memory system where data for each separate color is stored together or collected separately as in streaming data. In order to use this information in recreating or displaying the desired image, the pixel data has to be arranged into an RGB pattern wherein all the data for a particular pixel is grouped together.
For this embodiment, a set of masks having predefined patterns are used in interleaving together the RGB data. FIG. 15A illustrates as set of masks:[0133]MASK A1502 having a first pattern,MASK B1504 having a second pattern, andMASK C1506 having a third pattern. Data from each register is to be spaced three bytes apart so that it can be interleaved with data from the two other registers. Control bytes with hex values 0x80 have the most significant bit set so that the corresponding byte is flushed to zero by the packed byte shuffle instruction. In each of these masks, every third shuffle mask is enabled to select a data element for shuffling while the two intervening shuffle masks have values of 0x80. The 0x80 value indicates that the set to zero fields in the masks for those corresponding data element positions are set. Thus ‘0’s will be placed in the data element positions associated with that mask. In this example, the mask patterns are to basically separate out the data elements for each color in order to accomplish the interleaving. For example, whenMASK A1502 is applied to a data operand in a shuffle operation, theMASK A1502 causes six data elements (0x0, 0x1, 0x2, 0x3, 0x4, 0x5) to be shuffled apart with two data element spaces between each data element. Similarly,MASK B1504 is to shuffle apart data elements at 0x0, 0x1, 0x2, 0x3, 0x4.MASK C1506 is to shuffle apart data elements at 0x0, 0x1, 0x2, 0x3, 0x4.
Note that in this implementation, the shuffle mask for each particular overlapping data element position has two set to zero fields set and one shuffle mask designating a data element. For example, referring to the rightmost data element position for the three sets of[0134]masks1502,1504,1056, the shuffle mask values are 0x00, 0x80, and 0x80, forMASK A1502,MASK B1504, andMASK C1506, respectively. Thus only the shuffle mask 0x00 forMASK A1502 will specify data for this position. The masks in this embodiment are patterned so that the shuffled data can be easily merged to form the interleaved RGB data block.
FIG. 15B illustrates the blocks of data to be interleaved:[0135]DATA A1512,DATA B1514, andDATA C1516. For this embodiment, each set of data has an data entry with color information for sixteen pixel positions. Here, the subscript notion accompanying each color letter in a data element represents that pixel number. For instance, R0 is the red data forpixel0 and G15 is the green data forpixel15. The hex values at each data element illustrated is the number of that data element position. The color data (DATA A1512,DATA B1514, DATA C1516) may be copied into other registers so that the data is not overwritten by the shuffle operation and can be reused without another load operation. In the example of this embodiment, three passes with the threemasks1502,1504,1506, are needed to complete the pixel data interleaving. For alternate implementations and other amounts of data, the number of passes and shuffling operations can vary as needed.
FIG. 15C illustrates the resultant data block,[0136]MASKED DATA A1522, for a packed shuffle operation on red pixel data,DATA A1512, with the first shuffle pattern,MASK A1502. In response toMASK A1502, the red pixel data is arranged into every third data element position. Similarly, FIG. 15D illustrates the resultant data block, MASKEDDATA B1524 for a packed shuffle operation on green pixel data,DATA B1514, with the second shuffle pattern,MASK B1504. FIG. 15E illustrates the resultant data block,MASKED DATA C1526 for a shuffle operation on blue pixel data,DATA C1516, with a third shuffle pattern,MASK C1506. For the mask patterns of this embodiment, the resultant data blocks from these shuffle operations provide data elements that are staggered so that one of the data elements has data while two have ‘0’s. For instance, the leftmost data element position of theseresultants1522,1524,1526, contain R5, ‘0’, and ‘0’, respectively. At the next data element position, the pixel data for another one of the RGB colors is presented. Thus when merged together, a RGB type of grouping is achieved.
In this embodiment, the above shuffled data for the red data and the green data are first merged together with a packed logical OR operation. FIG. 15F illustrates the resultant data, INTERLEAVED A &[0137]B DATA1530, for the packed logical OR-ing ofMASKED DATA A1522 and MASKEDDATA B1524. The shuffled blue data is now merged together with the interleaved red and green data with another packed logical OR operation. FIG. 15G illustrates the new resultant, INTERLEAVED A, B, &C DATA1532, from the packed logic OR-ing ofMASKED DATA C1526 and MASKED DATA A &B1530. Thus the resultant data block of FIG. 15G contains the interleaved RGB data for the first five pixels and a portion of the sixth pixel. Subsequent iterations of the algorithm of this embodiment will yield the interleaved RGB data for the rest of the sixteen pixels.
At this point, one third of the data in[0138]DATA A1512,DATA B1514, andDATA C1516 has been interleaved. Two approaches can be used to process the remaining data in these registers. Another set of shuffle control bytes can be used to arrange the data to be interleaved or the data inDATA A1512,DATA B1514, andDATA C1516 can be shifted right so that theshuffle masks1502,1504,1506, can be used again. In the implementation shown here, data is shifted to avoid making the memory accesses required to load additional shuffle control bytes. Without these shifting operations, nine sets of control bytes would be needed in this embodiment instead of three (MASK A1502,MASK B1504, MASK C1506). This embodiment can also be applied in architectures where a limited number of registers are available and memory accesses are long.
In alternative embodiments where a large number of registers are available, keeping all or a large number of mask sets in registers so that shift operations are not necessary can be more efficient. Furthermore, in an architecture with many registers and execution units, all of the shuffle operations can be performed in parallel without having to wait for the shifting to occur. For instance, an out-of-order processor with nine shuffle units and nine mask sets can perform nine shuffle operations in parallel. In the embodiment above, the data has to be shifted before the masks are reapplied.[0139]
The data elements in the original color data of[0140]DATA A1512,DATA B1514, andDATA C1516, are shifted in accordance to the number of data elements already processed for that particular color. In this example, data for six pixels has been processed above for red, so the data elements for red dataoperand DATA A1512 is shifted to the right by six data element positions. Similarly, data for five pixels has been processed for both green and blue, so the data elements for green dataoperand DATA B1514 and for blue dataoperand DATA C1516 are shifted right by five data element positions each. The shifted source data is illustrated as DATA A′1546, DATA B′1542, and DATA C′1544, for the colors red, green, and blue, respectively, in FIG. 15H.
The shuffle and logical OR operations as discussed above with FIGS.[0141]15A-G are repeated with this shifted data. Subsequent packed shuffle operations on DATA B′1542, DATA C′1544, and DATA A′1546, together withMASK A1502,MASK B1504, andMASK C1506, respectively, in combination with packed logical OR operations on the three packed shuffle resultants, provides interleaved RGB data for another four pixels and parts of another two. This resultant data, INTERLEAVED A′, B′, AND C′DATA1548 is illustrated in FIG. 15I. Note that the rightmost two data elements relate to the sixth pixel, which already had its red data R5arranged with the first interleaveddata set1532. The raw pixel color data is shifted again by the appropriate number of places per the processing results of the second pass. Here, data for five additional pixels has been processed for red and blue, so the data elements for red data operand DATA A′1546 and for blue data operand DATA C′1544 are shifted to the right by five data element positions. Data for six pixels has been processed for green, so the data elements for green data operand DATA B′1542 is shifted to the right by six positions. The shifted data for this third pass is illustrated in FIG. 15J. A repeat of the packed shuffle and logical OR operations above are applied to DATA C″1552, DATA A″1554, and DATA B″1556. The resultant interleaved RGB data for the last of the sixteen pixels is illustrated in FIG. 15K as INTERLEAVED A′, B′DATA1558. The rightmost data element with B10 relates to the eleventh pixel, which already has its green data G10 and red data R10 arranged with the second interleaveddata set1548. Thus, by way of a series of packed shuffle with a set of mask patterns and packed logical OR operations, data frommultiple sources1512,1514,1516, can be merged and rearranged together in a desired fashion for further use or processing like theseresultants1532,1548,1558.
FIG. 16 is a flow chart illustrating one embodiment of a method to shuffle data between multiple registers to generate interleaved data. For example, embodiments of the present method can be applied to the generation of interleaved pixel data as discussed in FIGS.[0142]15A-K. Although the present embodiment is described in the context of three data sources or planes of data, other embodiments can operate with two or more planes of data. These planes of data can include color data for one or more image frames. Atblock1602, frame data for a first, second, and third plane are loaded. In this example, RGB color data for a plurality of pixels are available as individual colors from three different planes. The data in the first plane is for the color red, the data in the second plane is for green, and the data in the third plane is for blue. Atblock1604, a set of masks with shuffle control patterns (M1, M2, and M3) are loaded. These shuffle control patterns determine the shuffle patterns and arrangement of data in order to interleave the colors together. Depending on the implementation, any number of shuffle patterns can be employed in order to generate the desired data arrangement.
At[0143]block1606, an appropriate control pattern is selected for each plane of data. In this embodiment, the shuffle pattern is selected based on which order the color data is desired and which iteration is presently being executed. The frame data from the first data set, red, is shuffled with a first shuffle control pattern atblock1608 to obtain shuffled red data. The second data set, green, is shuffled atblock1610 with a second shuffle control pattern to obtain shuffled green data. Atblock1612, the third data set, blue, is shuffled with a third shuffle control pattern to achieve shuffled blue data. Although the three masks and their shuffle control patterns are different from each other in this embodiment, a mask and its shuffle pattern can be used on more than a single data set during each iteration. Furthermore, some masks may be used more often than others.
At[0144]block1614, the shuffled data ofblocks1608,1610,1612, for the three data sets are merged together to form the interleaved resultant for this pass. For example, the resultant of the first pass can look like the interleaveddata1532 of FIG. 15G, wherein the RGB data for each pixel is grouped together as a set. Atblock1616, a check is made to determine whether there is more frame data loaded in the registers to shuffling. If not, a check is made atblock1620 to determine whether there is more data from the three planes of data to be interleaved. If not, the method is done. If there is more plane data available atblock1620, the process proceeds back to block1602 to load more frame data for shuffling.
If the determination at[0145]block1616 is true, the frame data in each plane of color data is shifted by a predetermined count that corresponds to whichever mask pattern was applied to the data set for that particular color during the last pass. For example, in keeping with the first pass example from FIG. 15G, the red, green, and blue data in the first, second, and third planes are shifted six, five, and five positions, respectively. Depending on the implementation, the shuffle pattern selected for each color data may be different each pass or the same one reused. During the second pass for one embodiment, the three masks from the first iteration are rotated such that first plane data is now paired with the third mask, second plane data is paired with the first mask, and third plane data is paired with the third mask. This mask rotation allows for the proper continuity of interleaved RGB data from one pass to the next, as illustrated in FIGS. 15G and 15I. The shuffling and merging continues as in the first pass. Should a third or more iterations be desired, the shuffle mask patterns of this embodiment continue to be rotated among the different planes of data in order to generate more interleaved RGB data.
Embodiments of algorithms using packed shuffle instructions in accordance with the present invention can also improve processor and system performance with present hardware resources. But as technology continues to improve, embodiments of the present invention when combined with greater amounts of hardware resources and faster, more efficient logic circuits, can have an even more profound impact on improving performance. Thus, one efficient embodiment of a packed shuffle instruction having byte granularity and a flush to zero option can have different and greater impact across processor generations. Simply adding more resources in modem processor architectures alone does not guarantee better performance improvement. By also maintaining the efficiency of applications like one embodiment of the parallel table lookup and the packed byte shuffle instruction (PSHUFB), larger performance improvements can be possible.[0146]
Although the examples above are generally described in the context of 128 bits wide hardware/registers/operands to simplify the discussion, other embodiments employ 64 or 128 bits wide hardware/registers/operands to perform packed shuffle operations, parallel table lookups, and multiple register data rearrangement. Furthermore, embodiments of the present invention are not limited to specific hardware or technology types such as MMX/SSE/SSE[0147]2 technologies, and can be used with other SIMD implementations and other graphical data manipulating technologies.
In the foregoing specification, the invention has been described with reference to specific exemplary embodiments thereof. It will, however, be evident that various modifications and changes may be made thereof without departing from the broader spirit and scope of the invention as set forth in the appended claims. The specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense.[0148]