|
#1
| ||||
| ||||
| Does anyone know how to get AltiVec instructions to compile in OS X? I was going through <a href="http://developer.apple.com/hardware/ve/tutorial.html">Apple's tutorial</a>, and I couldn't get anything to compile with "cc" or "cpp." Are there special header files? Special compiler? -Rob |
|
#2
| ||||
| ||||
| Ah. There's a -faltivec flag for the "cc" compiler, and that gets you a little further but not all the way. -Rob |
|
#3
| ||||
| ||||
| I still can't compile AltiVec code. The "vector" keyword seems to throw it for a loop when I compile with "cc -altivec". Anyone successfully compiled AltiVec code on OS X? -Rob |
|
#4
| |||
| |||
| Have you tried searching the header files for the word 'vector'? Sounds like you may not be including a needed header file. |
|
#5
| ||||
| ||||
| No luck with the header files, but I might have had a different error after all. Here's a simple file that takes two 4-float arrays and does a a[i]*x + b[i] calculation on them in one fell swoop. I present it as starter code for those who would like to start incorporating AltiVec instructions in their code (like me). With a little tweak you could as easily do a a[i]*x[i] + b[i] also: Code: main()
{
float a[] = { 1, 2, 3, 4 };
float b[] = { 5, 6, 7, 8 };
float x = 3.14;
int memOffset = 0;
float result[4];
vector float aV, bV, xV, resultV;
// Convert scalar x to vector xV
vector float dummy = (vector float)(0);
*((float *)&dummy) = x;
xV = vec_splat( dummy, 0 );
// Create vector types from 4-float arrays
aV = vec_ld( memOffset, &a[0] );
bV = vec_ld( memOffset, &b[0] );
// Perform the a[i]*x + b[i] calculation
resultV = vec_madd( xV, aV, bV );
// Save vector type in a 4-float array
vec_st( resultV, memOffset, &result[0] );
return 0;
} -Rob |
|
#6
| |||
| |||
| Thank you rob! the -faltivec switch does the trick. I think that the thing were doing differently is that you're not adding the vecLib Framework to your project. By the way add that -faltivec to the OTHER_CFLAGS in Expert build settings. peter |
|
#7
| ||||
| ||||
| Thanks, Peter. You're way ahead of me. I haven't even gotten to the ProjectBuilder stuff yet. -Rob |
|
#8
| |||
| |||
| rob, Just an update, you don't need the vecLib framework after all. It adds convenience funtions and stuff like that. all you need is the switch. also I'm not ahead of you, I couldn't get anything to work until you told me about the -faltivec switch. And just like you I'm still copying and pasting routines without having a clue how to write my own. Know any good docs? Funny i did the project builder stuff first. I think its easier that way, just set the switch and you're away. Peter |
![]() |
| Thread Tools | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| php won't compile on Panther | Gnomo | Mac OS X System & Mac Software | 0 | October 27th, 2003 11:12 AM |
| HELP: I have no idea how to compile! | Berk | Software Programming & Web Scripting | 2 | October 31st, 2002 12:55 PM |
| simple "hello world" code using c++ | huck | Unix & X11 | 3 | October 1st, 2002 02:25 PM |
| How to compile stuff | fintler | Unix & X11 | 1 | August 28th, 2002 08:57 AM |
| tk compile crash | buc99 | Software Programming & Web Scripting | 0 | June 6th, 2002 12:38 AM |