|
|
In article <3d4b8aec@news.povray.org>, Micha Riser <mri### [at] gmxnet>
wrote:
> You probably mean Sqr((sin(EPoint[X])+sin(EPoint[Y])+sin(EPoint[Z]))/3);
Yeah, I screwed up the parentheses and the ".0" isn't necessary.
> Temporary variables are do not affect the performance mostly though. The
> has to use several registers anyways.
I know, and a good compiler would probably optimize it to the same
machine code, but there is no reason to use them, not even readability.
(Do modern compilers even pay any attention to "register"?)
My point was it doesn't conform to any kind of "strict guidelines" other
than maximum compatibility (it was apparently for compiling with an old
386 compiler). The "noise" variable I just don't understand...I guess it
helped some compiler with optimization or something.
> But to show the vector nature of this calculation it should be
> written as:
> DBL value=0;
> for(int i=0; i<3; i++) value+=sin(EPoint[i]);
> return Sqr(value/3.0);
>
> Of course this assumes that X,Y,Z are 0-2 index.
You mean for helping the compiler detect something that can be
vectorized and doing it automatically? It won't pick out the possibility
in the one-line version?
Would it get this version?
DBL value = 0;
value += sin(EPoint[0]);
value += sin(EPoint[1]);
value += sin(EPoint[2]);
return Sqr(value/3.0);
Or this (assuming a struct with x, y, and z components):
value += sin(EPoint.x);
value += sin(EPoint.y);
value += sin(EPoint.z);
I'm not surprised the for loop wasn't used in the existing
version...SIMD stuff wasn't even a factor, so of course the code wasn't
designed for it, and compilers probably weren't good enough at
optimizing to get rid of the for() loop.
--
Christopher James Huff <chr### [at] maccom>
POV-Ray TAG e-mail: chr### [at] tagpovrayorg
TAG web site: http://tag.povray.org/
Post a reply to this message
|
|