Path: chuka.playstation.co.uk!news From: "Martin Keates" Newsgroups: scee.yaroze.freetalk.english Subject: Re: work in progress demo Date: Sat, 21 Jul 2001 16:39:10 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 39 Message-ID: <9jc7nh$df3@www.netyaroze-europe.com> References: <9j7hfs$qcd2@www.netyaroze-europe.com> <9j95n4$sk21@www.netyaroze-europe.com> <9jalov$df1@www.netyaroze-europe.com> NNTP-Posting-Host: modem-602.barracuda.dialup.pol.co.uk X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 > In fact, here's some code that's sucking up the raster time. I'm not too > sure about how to optimise this further apart from converting the multiplies > into shifts + adds, so any pointers would be much appreciated! Optimising code by sight is a pretty tricky art. I'd be pretty surprised if you manage to optimise multiplies any better than gcc -O3 (unless you're using info about the values not available at compile time). You've only got one in this code anyway, and I bet it's not the bottleneck in the loop. % is a pretty slow operation usually. I think that in the loop offsetX and offsetY are guaranteed to be non-negative, so you don't need the <0 comparisons. Also, the most they'll be is BGSizeX-1, so instead of: if(offsetX++ < 0) { offsetX += BGSizeX; } offsetX %= BGSizeX; try: offsetX ++; if (offsetX == BGSizeX) offsetX= 0; which I think would be much faster (obviously you still need the % in the earlier code when offsetX can be any value). The exception to this would be if BGSizeX was a multiple of 2, in which case val % BGSize is equivalent to val & (BGSizeX-1) (*but* the compiler won't perform this optimisation because it doesn't know the value of BGSizeX at compile time). You'll have to try different values and code to see which gives you the best performance. Martin.