Re: non trivial constant folding

"MickaŽl Pointier" <>
9 Jan 2001 23:22:35 -0500

          From comp.compilers

Related articles
[7 earlier articles]
Re: non trivial constant folding (2001-01-09)
Re: non trivial constant folding (2001-01-09)
Re: non trivial constant folding (Robert Metzger) (2001-01-09)
Re: non trivial constant folding (2001-01-09)
Re: non trivial constant folding (2001-01-09)
Re: non trivial constant folding (2001-01-09)
Re: non trivial constant folding (Micka√ęl Pointier) (2001-01-09)
Re: non trivial constant folding (Michael Morrell) (2001-01-09)
Re: non trivial constant folding (Dennis Ritchie) (2001-01-11)
Re: non trivial constant folding (Conor O'Neill) (2001-01-11)
Re: non trivial constant folding (2001-01-18)
Re: non trivial constant folding (2001-01-18)
Re: non trivial constant folding (2001-01-19)
[3 later articles]
| List of all articles for this month |

From: "MickaŽl Pointier" <>
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" <> a ťcrit dans le message news:
> What you are looking for is sometimes called "canonicalizing" (or
> sorting).

> 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" <> 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
> 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" <> 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:

        DefActor Hero
                While Ennemy.alive
                        If see(Ennemy)
                                shoot Ennemy
                                rotate 10

        DefActor Ennemy
                While Hero.alive
                        If see(Hero)
                                rotate 10

Of course it's a stupid example, but right now I have no better idea...
Thanks again for the answers

        Mickael Pointier

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.