|
![](/i/fill.gif) |
On 22.07.11 23:51, David Given wrote:
> On 22/07/11 22:25, Thorsten Froehlich wrote:
> [...]
>> Well, as said, without the SDL I can't help as that is what in the end
>> determines how your functions are evaluated.
>
> I'm not looking to optimise this specific bit of code. I'm looking for
> general strategies in how to optimise code in general.
>
> For example: I assume that Povray parses functions into an AST, and then
> evaluates them by traversing the tree. Once the AST has been
> constructed, does it run any of the standard compiler optimisation
> algorithms on this such as common subexpression elimination or constant
> propagation?
Constant folding will always happen, as long as they are next to each other
in the tree. This includes single-argument intrinsic functions. (sqrt, sin,
cos, tan, abs, etc.). Further, there is inline expansion for pow, min and max.
There are no higher-level optimisations, as there is no detection (nor a
complete list) of side effects some pattern functions do have (weel, had
before 3.7). Further, the syntax tree is only kept as long as needed, which
means as soon as the parser is done with a function.
Without knowing the specifics, most likely for your use the best way to
eliminate common subexpressions is to use multiple functions and pass the
subexpressions as arguments.
Thorsten
Post a reply to this message
|
![](/i/fill.gif) |