| |||||||||
AltiVec is a SIMD instruction set designed and owned by Apple Computer, IBM and Motorola, and implemented on versions of the PowerPC including Motorola's G4 and IBM's G5 processors. AltiVec is a tradename owned solely by Motorola, so the system is also referred to as Velocity Engine by Apple and VMX by IBM.
AltiVec is one of the most powerful SIMD systems in a desktop CPU. It is roughly comparable to SSE2, introduced into the IA-32 architecture by Intel with the Pentium 4; AltiVec preceded SSE2. Both AltiVec and SSE2 feature 128-bit vector registers that can represent sixteen 8-bit signed or unsigned chars, eight 16-bit signed or unsigned shorts, four 32-bit ints or four 32-bit floating point variables. Both provide cache-control instructions intended to minimize cache pollution when working on streams of data.
Unlike SSE2, Altivec supports a special RGB "pixel" data type, but it does not operate on 64-bit double precision floats, and there is no way to move data directly between scalar and vector registers; in keeping with the "load/store" model of the PowerPC's RISC design, the vector registers, like the scalar registers, can only be loaded from and stored to memory. However, Altivec provides a much more complete set of "horizontal" operations that work across all the elements of a vector; the allowable combinations of data type and operations are much more complete; 32 128-bit vector registers are provided, compared to 8 for SSE and SSE2; and most Altivec instructions take three register operands compared to only two register/register or register/memory operands on IA-32. These Altivec features tend to produce tighter, faster code than SSE2.
Recent versions of the GNU Compiler Collection, IBM Visual Age Compiler and other compilers provide intrinsics to access AltiVec instructions directly from C and C++ programs. The "vector" storage class is introduced to permit the declaration of native vector types, e.g., "vector unsigned char foo;" declares a 128-bit vector variable named "foo" containing sixteen 8-bit unsigned chars. Overloaded intrinsic functions such as "vec_add" emit the appropriate op code based on the type of the elements within the vector, and very strong type checking is enforced. In contrast, the Intel-defined data types for IA-32 SIMD registers declare only the size of the vector register (128 or 64 bits) and in the case of a 128-bit register, whether it contains integers or floating point values. The programmer must select the appropriate intrinsic for the data types in use, e.g., _mm_add_epi16(x,y) for adding two vectors containing eight 16-bit integers.
Like all SIMD systems however, AltiVec is not widely used. This is not much of a problem for the Apple Macintosh, where Apple's own libraries widely support it, and is used in applications like QuickTime and iTunes and image-processing programs such as Adobe Photoshop. For other users AltiVec is of limited use (although it is used in some embedded systems to provide extremely high-performance digital signal processing), and IBM has consistently left VMX out of their proprietary POWER systems. However, the most recent PowerPC 970 (dubbed the G5 by Apple) desktop CPU from IBM includes a high-performance AltiVec unit.