Technical: Hardware: G4
Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Support

Highlights and Examples

Example 1
Example 2
Example 3
Example 4

AltiVec is a Single Instruction Multiple Data (SIMD) machine comprised of

  • 32 x 128-bit "vector" registers
  • On older G4's (533 MHz or less), and the G5 there are two new fully pipelined processing units:
    • a vector permute unit
    • a vector ALU unit (simple & complex integer, and floating point)
  • On newer G4's (greater than 533 MHz), there are four:
    • a vector permute unit
    • a vector Simple Integer unit
    • a vector Complex Integer unit
    • a vector Floating Point unit
  • A streaming data prefetch engine
  • over 160 new opcodes
AltiVec Registers can hold either integers or single precision floating-point values. The table and figure below show the range of values that can be stored:

 

Each value within an AltiVec register is a vector that is made of elements. AltiVec instructions perform operations on all elements within an AltiVec vector register at once. AltiVec has the usual collection of operations that one has come to expect such as: add, subtract, multiply and multiply-add (a.k.a. multiply-add fused). In addition, a set of useful operations such as sum-across (sums all the elements in a vector) and multiply-sum (multiplies and sums elements in 3 vectors) have been added.The data manipulation instructions also have been augmented to include operations such as permute (fills a register with bytes from 2 other registers), merge (merges two vectors into one) and "splat" (duplicates data across elements in a vector).

The following are examples of two AltiVec instructions, which are similar to instructions in the PowerPC scalar units.

Example 1:

To add 16 bytes to another 16 bytes in one instruction we can use vaddubm:

vaddubm is the AltiVec analog of the add unsigned bytes modulo (or wrap) available in the PowerPC scalar instruction set.

Example 2:

To multiply 4 floats by 4 floats and then add the result to 4 more floats in one instruction and in one rounding, we can use vmaddfp:

vmaddfp is the AltiVec analog of the multiply-add fused available in the scalar floating-point instruction set.

The AltiVec unit on the PowerPC goes beyond the common general purpose microprocessor instructions. The following two examples illustrate how AltiVec has encapsulated in a single instruction (executing in 1 cycle) a large combination of several regular scalar operations.

Example 3:

The "permute" instruction fills a register with bytes from 2 other registers. The bytes can be specified in any order.

vperm uses the register permute as a sophisticated mask and assigns corresponding values of the operands data1 and data2 to the result register. For example, byte1 of data1 is mapped to byte0 of the result and byte14 of data2 is mapped into byte1 of the result. (values are in Hex).

Example 4:

The "splat" instruction is used to copy any element from one register into all of the elements of another register as shown in the diagram below.

vsplth refers to the half-word version of "splat" and vspltw is its word length counterpart. In the above example, vsplth duplicates the third half-word of the register data across the result register.

Table of ContentsNextPreviousTop of Page