![]() |
![]() |
![]() |
|
![]() | |
![]() |
![]() |
![]() |
![]() |
![]() |
Log In | Not a Member? |
Support
![]() |
![]() |
Using AltiVecAs presented in The C Programming Model, you may program AltiVec from the higher level languages C, C++ and Objective C using the AltiVec C Programming Interface. The collection of intrinsic data types and C-style functions that use them will be familiar to developers who already know how to program in C. There are, however, some subtle differences between ordinary C and the AltiVec extension to C: Type ConversionsTypecasts are handled somewhat differently with vector types. Implied type conversions are not allowed. The compiler will reject the second line from the code sample below:
In this case, the implied type conversion between (vector unsigned long) and (vector float) in the assignment on the second line is not allowed. However, if you do an overt type coercion, then the code will compile:
However, unlike scalar type
coercions, vector type coercions do not change any bits
in the vector. This means that you have to be a little bit more careful with them because such a type coercion may cause the vector to be reinterpreted to have a different value. In this example, the type coercion shown above causes floatOne to emerge from the assignment holding
Why is type casting done this way?
Overt type coercions between vector types always have zero
cost. Since they never cause any bits to change, they never
compile into an AltiVec instruction. This is different from
similar appearing type coercions applied to standard scalar
C types. For example, for a scalar
Function OverloadingFunction overloading is a feature of C++ that is not a part of C per se. However, the AltiVec C Programming model makes use of it in C, C++ or Obj C for the new intrinsic functions that the C Programming Model defines. For each conceptual operation (e.g. addition with modulo overflow), there will be one function (e.g.
These 19 forms of The AltiVec C Programming model does not give you the ability to create your own overloaded functions in C. As always, functions you create with different argument types must be given different names. You can, of course, write your own overloaded functions using a C++ compiler -- C++ allows this feature with user defined functions. Note that because the vector data types are intrinsic, a C++ compiler will not allow you to create operator overloads for them.
C++ and Objective CYou can program in C++ and Objective C using the AltiVec C programming interface, in the same way that you can use ordinary C functions and data types in C++ and Objective C. With C++, some attention must be paid to performance when building abstraction. Wrapping a vector data type in a C++ object can have substantial negative performance implications if your compiler does not support passing class data by value in register. Passing small amounts of data by address causes a large amount of unnecessary load/store overhead. Typical slowdowns may be a factor of two. Be sure to check your compiler's output. Newer versions of popular C++ compilers for MacOS X support this feature. |