I just started learning altivec. It's quite easy, actually easier than I expected, I can only recommend you to try.
What you need :
And voilà, you are ready to use altivec
Now let's talk about documentation. At first, I recommend reading the wikipedia article if you don't know anything about altivec. Then, nothing is better than starting with a small Hello world. I followed the instructions given in this document, about PMON on a pegasos. I didn't care about PMON, but the document starts with a 'hello world' in altivec.
Then, after following the basic instructions, I downloaded the complete
AltiVec Technology Programming Interface Manual, it's simple to read, and explains every single altivec commands. By the way, you might need to register on the freescale to have access to the documents.
OK for really lazy people, here is a dummy source code, calculating 1+2+3+4+5. Useless, but I like that
The source code is at the end, here is the result :
vec_int1 = (1,2,3,4)
vec_int2 = (0,0,0,5)
vec_int3 = (0,0,0,15)
Now I need to find something interesting to do in altivec, and more important, train myself on algorithm optimization, data prefetching, and so on. Maybe I'll post more about altivec later.
Here is the dummy source code, compile it with :
gcc -maltivec -mabi=altivec test.c -o test
#include <altivec.h>
#include <stdio.h>
void print_char_vector(vector unsigned char *this_one);
void print_int_vector(vector int *this_one);
vector int vec_int1;
vector int vec_int2;
vector int vec_int3;
int main() {
unsigned int a1[8] __attribute__ ((aligned (16)))
= {1,2,3,4, 0,0,0,5};
vec_int1 = vec_ld(0, (vector int*)a1);
vec_int2 = vec_ld(16, (vector int*)a1);
vec_int3 = vec_sums(vec_int1, vec_int2);
printf("vec_int1 = ");
print_int_vector(&vec_int1);
printf("\n");
printf("vec_int2 = ");
print_int_vector(&vec_int2);
printf("\n");
printf("vec_int3 = ");
print_int_vector(&vec_int3);
printf("\n");
}
void print_int_vector(vector int *this_one) {
printf("(%d,%d,%d,%d)",
((int*)this_one)[0],
((int*)this_one)[1],
((int*)this_one)[2],
((int*)this_one)[3]);
}
| Mon | Tue | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|
| << < | ||||||
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |