[fpc-pascal] Registers in loops

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Dec 14 14:07:43 CET 2012


On 14 Dec 2012, at 13:46, Michael.VanCanneyt at Wisa.be wrote:

> On Fri, 14 Dec 2012, Jonas Maebe wrote:
>
>> Indeed, adding inline assembler to a routine disables many  
>> optimizations.
>
> Doesn't adding the list of modified registers to the 'ASM' block
> help in this case ? I thought this was why we supported this ?

That's required to guarantee the correctness of the generated code  
under all circumstances. It doesn't help with register variables though:

{$asmmode intel}
procedure test;
var
   l: longint;
begin
   // compiler decides to put l into register eax
   l:=1;
   asm
     push eax
     push edx
     rdtsc
     mov  l,eax
     pop edx
     pop eax
   end; // no register changed -> no list required
   // always writes 1
   writeln(l);
end;

It would be possible to prevent registers accessed from assembler code  
to be put into registers, but currently the compiler does not perform  
any kind of analysis of assembler code, and I think it should stay  
that way. There are too many ways in which assembler code can be  
written that defeats automatic analyses. If you use assembler, you get  
full freedom and that freedom gets taken away from the compiler.


Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20121214/6e30cb25/attachment.html>


More information about the fpc-pascal mailing list