On Aug 18, 2005, at 21:54, Uri Guttman wrote:


"LT" == Leopold Toetsch <[EMAIL PROTECTED]> writes:

  LT> Here is a plan to implement most of the needed bits.

  LT> # constant pi = 4 * atan2(1,1);

  LT> translates to

  LT> .sub anon_1 @IMMEDIATE, @ANON
  LT>      $N0 = atan 1.0, 1.0
  LT>      $P0 = new .Float
  LT>      $P0 = $N0
  LT>      .return ($P0)
  LT> .end

did you forget the 4 * part of the init value?

Of course. I just wanted to simplify the example a bit ;-)

and shouldn't atan2(1,1)
be (possibly) optimized to a constant or looked up in a table of easy
trig stuff and that value used?

Yep. The former is already done for unary and binary basic math, but seems to be missing for trig opcodes still:

$ echo "add N0, 1, 1
end" | ./parrot -t1 -a -
     0 set N0, 2        - N0=0.000000,
     3 end

The 'times 4' part (and creating pi) is another run through the optimization loop (after constant propagation).

then you could just generate the
constant folded value of pi in the compiler and emit that float for the
init.

That would yield a constant folded FLOATVAL pi, but not a PMC.

 constant num pi = ...

vs

 constant pi = ...

(I guess)

 if this gets compiled to bytecode this would really reduce the
runtime (even in BEGIN) to almost nothing.

Yep. But anyway runtime costs are the same. It's read and thaw (for a PMC) a constant - and thaw is executed once during PBC loading.

uri

leo

Reply via email to