Brent 'Dax' Royal-Gordon <[EMAIL PROTECTED]> wrote:
> Dan Sugalski wrote:
>> This becomes a bit less efficient when we're looking at intermediate
>> values of expressions. Something like:
>>
>>    a = b + c + d
>>
>> turns to
>>
>>    new $P0, SomeIntermediateType
>>    add $P0, b, c
>>    add a, $P0, d

> Well...how about this:

> 1. Have all vtable methods which take a dest return a PMC *.

> 2. If dest is NULL, it's filled with the appropriate type before
>     anything else is done.

*Strong NAK* :)

The register allocator has to track the life span of each variable and
temp. If the life of a register ends at one point, this register is
reused:

   # a = b + c + d
   $P0 = $P1 + $P2         # (1]
   $P3 = new PerlUndef     # (2)
   $P3 = $P0 + $P4

Let's assume that C<$P1> or C<$P2> are also temps and not reused beyond
instruction (1). With that in mind $P3 is assigned to the same Parrot
register as one of this temps.

With the Parrot Calling Conventions we did effectively cut down the
assignable register range to P16..P31 (using registers in the low range
is possible but not easy).

So back to your proposal: Above example could look like:

   $P0 = $P1 + $P2
   $P3 = $P0 + $P4

Now the register allocator does of course not know, *if* the C<$P3> is
C<PMCNULL> at runtime. It has to assume that it isn't. No register can
be reused, the register allocator would run short of registers after
very few instructions.

>  (I believe PMC
> registers are initialized to NULL,

That's a wrong assumption too. They are intially PMCNULL in @MAIN. But
when you call a subroutine, the registers are just that, what they used
to be in the caller.

It could work, if the sequence is:

   $P0 = $P1 + $P2
   null $P3
   $P3 = $P0 + $P4

The C<null (out PMC)> opcode cuts the life range of C<$P3> because of
its C<out> specifier.

But now we have the runtime overhead in each such vtable method (test
for PMCNULL) and one additional function argument to pass.

leo

Reply via email to