Log In | Not a Member? | Support | |
The C Programming ModelThe C programming model for AltiVec is designed to make programming for AltiVec in C as much like programming for any other data type as possible. It is described in detail in the AltiVecâ„¢ Technology Programming Interface Manual from Motorola.
AdvantagesThe C Programming Model is an extension to C (and C++ and Obj C) that enables facile use of AltiVec within any C, C++ or Obj C program. You may of course program the vector unit using assembly language, if you prefer. However, the advantages of the C Programming Model over assembly are many:
Developers who use the C Programming Model should find the AltiVec syntax and operation entirely familiar. Standard C programs should compile without modification on C compilers with the AltiVec C Programming Model enabled. New AltiVec-using functions and data structures may be then added and used just like other functions and data structures.
Data TypesThe C Programming Model adds new intrinsic vector data types that correspond with the classical scalar intrinsics such as float, char, int, etc. The new intrinsic vector data types represent 128 bit vectors holding different kinds of data (chars, shorts, floats, etc.) as a packed 128 bit array. Their names are based on the packed scalar type contained within the vector. As an example, a vector unsigned short is a 128 bit long packed array of 16-bit unsigned integers (8 unsigned shorts stuffed end to end in a 16 byte array). The new vector keyword must be used to denote that it is a vector type and not a simple scalar.
Vector types work just like other types. You can load and store them, apply functions to them, declare them on the stack, write new functions that use them, etc.
FunctionsIn addition, a series of C-style functions that use these vector types have been provided. With a few exceptions, these map 1:1 with the 160 AltiVec instructions, giving you detailed control over the code generation from your vector code. For example, to add two AltiVec vectors together, you would use the vec_add "function":
When you compile the application, the compiler will generate the following instruction:
(vadduwm is the AltiVec instruction for adding two vectors full of 32 bit ints to each other.) A complete list of AltiVec intrinsic functions appears in the Instruction Reference. |