Re: AltiVec optimization in Cocoa?
Re: AltiVec optimization in Cocoa?
- Subject: Re: AltiVec optimization in Cocoa?
- From: Mike Vannorsdel <email@hidden>
- Date: Sun, 19 May 2002 19:17:08 -0600
To answer some questions:
Some code in the Cocoa frameworks are optimized for AltiVec. These can be
found in CoreGraphics for instance. I believe NSAffineTransform's code
benefits from this. But I can't be sure as I've never seen the source, but
I do see the vector instructions within some of the frameworks. There's
nothing special you need to do to benefit from the AltiVec support in the
frameworks.
However, code you write yourself is not automatically vectorized (optimized
for AltiVec) by the compiler and is something you need to do yourself. The
preferable method is to use the C functions, rather than assembly. You'll
need to use the -faltivec flag with GCC for it to recognize vector types and
instructions.
If AltiVec code is executed on a G3, I believe the Mac OS will try and
emulate the vector processor. This is invariably slow. If the code is not
caught by an emulator, then you'll get an illegal instruction fault. To
prevent this, beware of code like this:
void computeData(void * someData)
{
if (hasAltiVec)
doAltiVecCode(someData);
else
doScalarCode(someData);
}
Depending on the compiler, this might cause problems if the inner functions
are inlined (because there will be vector instructions in the calling
function's setup).
AltiVec is best suited for situations were an algorithm is used on several
pieces of like-data. For instance, you have a stream of 1000 floats and
want to multiply all of them by a factor of 4 and subtract 2. Here you're
applying the same algorithm (4x + 2) to several pieces of like-data
(floats). If you're creative, you can accelerate other types of code such
as large if statements and switches.
Writing code for AltiVec is a lot harder than it looks. You have to watch
data alignment and need to use data pre-fetching to get worthwhile
performance in most places. You also need to schedule your code around to
work with the pipelines if the compiler is doing a poor job at doing it
itself. Getting to know SimG4 will help you with this.
Goto www.altivec.org and view the documentation there, such as Lund's
tutorial, and join the email list if you'd like to learn about AltiVec.
Also, this knowledge will be useful for any SIMD processor.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.