9 Jan 2001 23:22:35 -0500

Related articles |
---|

[7 earlier articles] |

Re: non trivial constant folding anton@mips.complang.tuwien.ac.at (2001-01-09) |

Re: non trivial constant folding anton@mips.complang.tuwien.ac.at (2001-01-09) |

Re: non trivial constant folding metzger@rsn.hp.com (Robert Metzger) (2001-01-09) |

Re: non trivial constant folding sjmeyer@www.tdl.com (2001-01-09) |

Re: non trivial constant folding henry@spsystems.net (2001-01-09) |

Re: non trivial constant folding dew@cray.com (2001-01-09) |

Re: non trivial constant folding mpointie@eden-studios.fr (Mickaël Pointier) (2001-01-09) |

Re: non trivial constant folding morrell@morrell.cup.hp.com (Michael Morrell) (2001-01-09) |

Re: non trivial constant folding dmr@bell-labs.com (Dennis Ritchie) (2001-01-11) |

Re: non trivial constant folding ONeillCJ@logica.com (Conor O'Neill) (2001-01-11) |

Re: non trivial constant folding sjmeyer@www.tdl.com (2001-01-18) |

Re: non trivial constant folding genew@shuswap.net (2001-01-18) |

Re: non trivial constant folding anton@mips.complang.tuwien.ac.at (2001-01-19) |

[3 later articles] |

From: | "Mickaël Pointier" <mpointie@eden-studios.fr> |

Newsgroups: | comp.compilers |

Date: | 9 Jan 2001 23:22:35 -0500 |

Organization: | ImagiNET / Colt Internet |

References: | 01-01-015 01-01-029 |

Keywords: | optimize, summary |

Posted-Date: | 09 Jan 2001 23:22:35 EST |

[I reply on this message, but this answer is for every people that

take time to reply to my initial message: Thanks everybody, it

is very interesting]

"Chris F Clark" <cfc@world.std.com> a écrit dans le message news:

*> What you are looking for is sometimes called "canonicalizing" (or*

*> sorting).*

Ok.

*> Imagine how upset your user will be when after testing (in a program)*

*> the discriminant of a quadratic equation for a negative value (and*

*> getting false), and then computing the root and getting an incorrect*

*> imaginary number. (This actually happened in a FORTRAN compiler*

*> after we did some local optimizations without paying close enough*

*> attention to the ramifications.)*

I'm not really looking for "exact" operations mathematically speaking.

This optimisation phase is done by the compiler in "double", but final

results will all be rounder to few decimals, and comparisons are done

with huge epsilon values :)

"Mihai Christodorescu" <mihai@cs.wisc.edu> a écrit dans le message news:

*> There is also another problem: the optimized expression can behave*

*> differently than the original expression, due to operations being executed*

*> in different order/with different operands. Consider:*

*> "MAXINT + x - 1"*

*> If x is 1, then evaluating MAXINT + x will overflow.*

*>*

*> If you optimize the expression to be:*

*> "the_value_of_MAXINT_minus_1 + x"*

*> (i.e. you evaluate MAXINT - 1 at compile time), then if x is 1, the*

*> expression will not overflow. Of course, these are contrived examples, but*

a

*> compiler has to work for all cases, not most of the time (OK, at least in*

*> theory).*

Well, my "user" is supposed to use values that are far bellow the range of

numerics that the compiler itself is using. (something like storing a 24

bits value

in a "long double").

"Bonz" <bonzini@gnu.org> a écrit dans le message news:

*> Even if it is quite far from the direct question, it might help to*

*> know how Mathematica handles this. Each operator has attributes*

*> including "Flat" (associative) and "Unordered" (commutative).*

*> Mathematica uses lists internally and automatically converts for*

*> "Flat" operators*

*>*

*> Dot(Dot(a,b),c) ---> Dot(a,b,c)*

Yum. Love that one.

Looks like it will perform most of the job I'm looking for. Just have to

find an efficient way to have an AST that has a "node" counter instead

of the stupid binary tree I'm using right now.

For those that would like to know what I'm doing, I will take some time

to explain:

I'm doing a compiler for a pseudo code that will be executed on a

video game console. My main objectives are to have the smallest and

fastest possible code and interpreter. Considering I'm not looking

for accuracy, I can use all the mathematically evil things like

replacing divides by inverse multiplications, compare values by

subtracting and checking the difference with a epsilon, and so on.

Most of computation will be timings (in 1/50th of seconds) and

distances between "items" (something like a centimeter precision)...

I'm far from "Fortran" or floating point problems :) This "language"

looks like a kind of BASIC (GFA Basic for those that know about it),

so the syntax is very simple. It supports a kind of "actor"

multitasking. An example could be this:

DefScene

DefActor Hero

While Ennemy.alive

If see(Ennemy)

shoot Ennemy

Else

rotate 10

Endif

EndWhile

EndActor

DefActor Ennemy

While Hero.alive

If see(Hero)

shoot(Hero)

Else

rotate 10

Endif

EndWhile

EndActor

EndScene

Of course it's a stupid example, but right now I have no better idea...

Thanks again for the answers

Mickael Pointier

-----------------------------------

http://www.defence-force.org

Post a followup to this message

Return to the
comp.compilers page.

Search the
comp.compilers archives again.