RavenBlog |
|
Comments on Saturday 16 August 2003: |
I had been led to believe that Visual C++ would only honour __inline on class member functions if the function content was in the header file. This is evidently not the case, as a bit of assembly-code reading and a 15% speed increase will both attest. I was also under the, apparently mistaken, impression that "if ((*pvalue)&8)" would be a faster operation than "if (yc) {if (*(arraypointer+y*width+x))". The assembly code shows that neither of the two pieces of optimised code has been compiled into anything stupid; indeed, the former becomes simply "test [eax],4; je (address)", and yet that is slower than the latter, which looked more like (from memory) "test eax,eax; je (address); mov ebx,[address]; mov ecx,[address]; imul ebx,ecx; add ebx,[address]; test [eax],[eax]; je (address)" If I recall correctly, that imul operation alone should take longer than the entirety of the other code block. So how is it that the latter, long piece of code resulted in 350 frames per second, and the former only 250? My best guess is that it's to do with the modern-day processor lookahead/caching things being really inept at guessing correctly in the former case, and good at it in the latter. Hooray for modern processors where such simple things produce such unintuitive results. Having learned this lesson, I removed more bitwise operations and replaced them with whole bunches of array lookups, resulting in about another 30% speed increase. This optimising information has been brought to you by the operator &, and by the number 240000. [19:16] |