Post details: altivec, here I come !

28 June, 2006

Permalink 11:52 UTC, by Damien Krotkine Email , 407 words, 770 views   English (US)
Categories: Personal

altivec, here I come !

I just started learning altivec. It's quite easy, actually easier than I expected, I can only recommend you to try.

What you need :

  • a ppc with altivec enabled. any G4 or G5 based machine will do. I use the pegasos Freescale donated me in sept 2004, a nifty machine
  • a linux distro, with altivec enabled gcc. Hm, what about gentoo linux ? :)
  • documentation about altivec. In short, you'll need a "altivec for newbie" tutorial. It's not trivial to find those documentation, see below
  • some very basic knowledge in C, an editor, gcc

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]);
}

Comments:

Comment from: Hoa [Visitor]
unfortunately, altivec is mostly dead since Apple Computer does not use PowerPC any more.
PermalinkPermalink 17 July, 2006 @ 22:21
Comment from: Damien Krotkine [Member] Email · http://www.damz.net
I wouldn't claim so easily that altivec is dead. Genesi might well sell a bunch of G4 before the end of ppc is announced.
PermalinkPermalink 17 July, 2006 @ 23:16
Comment from: dommi [Visitor] Email · http://thoreg.org
altivec will have a big COMEBACK via the Playstation3 and the including CELL processor!!! :)

greetings
PermalinkPermalink 7 December, 2006 @ 12:07

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))

Damien Krotkine

August 2008
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

Search

Categories

Misc

XML Feeds

What is RSS?

Who's Online?

  • Guest Users: 41

powered by
b2evolution