Euphoria Code Optimiser

new topic     » topic index » view thread      » older message » newer message

Has anyone written / does anyone fancy writing a code optimiser ?

There have been at least a couple of things mentioned on the listserv which
Robert does not think are suitable for inclusion in ex and exw which would
work very nicely in an optimiser.

The two I am thinking of are :

If <cond1> and <cond2> and <cond3>

and :

for a=1 to very_big do
    x[a] = things[a][PROPERTIES][SPEED][X]
    y[a] = things[a][PROPERTIES][SPEED][Y]
end for

Pretty trivial examples but I hope you get the idea.


What the optimiser could do (I am sure this list is not conclusive) is to
simply replace the
"if and and and"'s
with
"if then if then if then end if end if end if"
type statements and multiple lookups with a temporary variable. This is shown
more clearly below.

Example 1.

if x>y and length(p)>0 and update_sprites() and x != 2 and check_keyboard()
then
    do_foo()
end if

Now this is not completely straightforward as some functions are called, so
the first thing the optimiser does is put the function in an *if* statement :

if update_sprites() and check_keyboard() then
...

note that length() is excluded because the optimiser knows that it is a built-
in function and has no effect on the state of the world.

Then the rest of the conditions are nested (very messy, but nobody has to read
it except the interpreter)

if update_sprites() and check_keyboard() then
    if x>y  then
        if length(p)>0 then
            if x != 2 then
                 do_foo()
            end if
        end if
    end if
end if

Of course the user has to put the conditions in an appropriate order unless
the optimiser can figure out which are most likely to be false.
In this case the conditions would have to be least_likely to most_likely (to
be true) for maximum speed.

Example 2.

In the second example (this is something that I find happening a lot)

for a=1 to very_big do
    x[a] = things[a][PROPERTIES][SPEED][X]
    y[a] = things[a][PROPERTIES][SPEED][Y]
end for

I could have written :

sequence temp

for a=1 to very_big do
    temp=things[a][PROPERTIES][SPEED]
    x[a] = temp[X]
    y[a] = temp[Y]
end for

(I usually do more than two slices per loop, so do not be speed-cynical)

This is horrible to read and would definitely scare me away from my code in a
few months.


So, following all that does anybody feel up to it ? (I think David Cuny did a
lot of this sort of thing before but he seems busy enough on Win32 stuff now.
I consider it beyond myself.)



By the way Rob (if you are still reading) are calculations with constants in
optimised at compile-time ?
eg

constant my_num=396
sequence bar

for a=1 to very_big do
    bar={1,2,3}/my_num
    grill(bar)
end for

compiles

<snip>
bar={ 0.002525252525253, 0.005050505050505, 0.007575757575758}
<end snip>
??


Sorry if I bored you.

Daniel

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu