POV-Ray : Newsgroups : povray.binaries.programming : matrices.c : Re: matrices.c Server Time
24 Apr 2024 17:10:41 EDT (-0400)
  Re: matrices.c  
From: Mark Wagner
Date: 29 Nov 2001 00:02:25
Message: <3c05c161@news.povray.org>

>> BUT:
>> Did you look thoroughly at this part of the code I suggested ?
>>
>Not really, I confess.

[code removed]

>> If so, I hope that you noticed that the (1.0 - cosx) expression
>> here appears in all of the transform lines, while it did not
>> appear in 3 of those lines originally.
>
>The original lines where easier for math people, because they were
>simply the traditionnal matrix.
>Your lines are more difficult to recognize as a rotation (at least for me).

Does this matter?  His code will run faster.

>They might do it with a two pass optimiser: first pass count the use of
> sub-expression. second pass assign a register for the most useful
> sub-result, according to the available register in the window.
>
>But they do not have to.
>All they usually need is to keep a symbolic map of the register contents,
>so that if (1-cosx) is still in a register, they used it directly.


Did you look at what Tor did?  No compiler in the world will make that
particular optimization, because it involves symbolic algebra.  In the
original code, the expression (1.0 - cosx) appears *six* times.  An
optimizing compiler will notice this and evaluate it only once, storing the
result in either a CPU register or memory, whichever is appropriate.  What
Tor did was notice that with a certain algebraic manipulation, the
expressions such as V1[X] * V1[X] + cosx * (1.0 - V1[X] * V1[X])could be
converted into expressions like V1[X] * V1[X] * (1.0 + cosx) + cosx,
allowing the *nine* occurrences of (1.0 - cosx) to be recognized as a common
subexpression which need only be evaluated once.

--
Mark


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.