Motorola AltiVec can dramatically improve the performance of many tasks, even tasks that you might initially think are too linear to get much advantage from parallelizing. This article looks at some real-world code that processors might spend a serious amount of time running, and shows how to tweak it to get extra performance.
The first example is kinda funny. The optimization basically changes the meaning of the function. If the user expects the function to increment the counter by one, adding altivec isn’t going to help as it changes the meaning of the function since you’re adding 4 instead of 1 each time the function is called.
But it doesn’t matter whether you increase 10.000.000 times by one or 2.500.000 times by four. The code is this:
for (x = 0; x < 100000000; function())
;
Which in fact is:
for (x = 0; x < 100000000; x++)
Which, in either case, means:
x = 100000000
It’s a Sunday night, so I may not be in my prime :-). But surely even in the example you’ve posted, making function() increment the counter by 4 changes the meaning.
for(x = 0; x < 10000000; x++) means that the loop will be executed 10,000,000 times.
If we were to change x++ to function() given in the article, that would be equivalent to x+=4 since each call to function() effectively adds 4 to x. Thus for (x = 0; x < 100000000; function()) will be equivalent to for(x = 0; x < 10000000; x+=4) which means that the loop will only get executed 2,500,000 times. Very different meanings if you ask me.
Learn how to tailor your code for AltiVec
Level: Intermediate
Peter Seebach ([email protected])
Freelance writer
01 Apr 2005
Just wonder who sent the article has even read it.
And the Author, in his infinite humour, took care of writing a first installment on 04/01, and a second on 04/16.
Look at the links in the references at the bottom of the article. Please don’t turn this site into Slashdot.
Actually, this already was on Slashdot, as an April Fools article.
For anyone who doesn’t believe, just search for “April Fools” within the page.
I had a G4 about 2 years back and had read about Altivec, none of the game developers optimize their code for the Altivec. I don’t know of any third party app for mac that was optimized for the Altivec, people complain about games sucking on macs and that is the reason why.
This is a bit serious and off-topic for an April Fools article talking about speeding up the idle loop, but what the hell…
I don’t know of any third party app for mac that was optimized for the Altivec
How would you know if they were? I doubt anyone would bother advertising it – “Doom 3 – Optimised for AltiVec(tm)(R)!”
It’s not like SSE2/3 get used much either – ultimately you can’t rely on the processors having those extensions. Your third party app wouldn’t run on a G3 (or early G4? dunno when Alitivec came in) if it relied on AltiVec.
The argument about Doom 3 on Macs went over some time back, and I don’t think Altivec was really an issue.
Duh… 🙂 This is funny. Had me fooled there. LOL.
It’s actually quite good article. If you want to learn basics of altivec programmming (like I did), this article will teach you the syntax and show some nice optimizing principles and pitfalls. Can’t wait for part 4.
The idle-loop optimizing was funny idea, but maybe most simple example you can imagine. Of course it was a joke, but the rest of the article wasn’t. Don’t believe everything you read at /.
I just could not grasp the concept of speeding up the idle loop. It is so insane. But if the article does teach the basics of Altivec then it is even better than an April fools day joke.