Re: [fpc-devel]default calling convention change for i386

2003-12-26 Thread Peter Vreman
 On Wed, 24 Dec 2003, Peter Vreman wrote:

 }Most important was compatibility, second is speed. In the drystone test
 }there was a performance gain of at least 10%.

 Okay, I think this answers the question :)

 } Register convention saves opcode space in the called function, because
 } within
 } the instruction opcode,  registers are encoded with small bit fields,
 } whereas
 } offsets into a stack frame are encoded as (8-, 16-, or 32-bit) words,
 } unless
 } the processor supports something like short offsets. Actually, I don't
 } know
 } if the i386 does support such short offsets. AFAIK, the 68000 does not.
 }
 }Sorry, this is not correct. The code size is increased with register
 }calling. The reason is that in the called routines the passed registers
 }need to be saved in the local stackframe. When we have register variables
 }support (currently not working for 1.9.x) this can be reduced.

 This is exactly what makes me doubt in the benefits of register calling.
 Because of the small number of registers to spare, the whole process of
 calling and executing a subroutine looks like this to me:

 1. Calculate values of parameters and push them into stack, one by one.
 2. Pop the values into appropriate registers (omitted when not using
 register convention)
 3. Call the subroutine.
 4. Push parameters into stack (omitted when not using register convention)
 5. Access parameters in stack as they are needed.

 Well, this is just an oversimplified theory. As Peter noted, the practice
 might be somewhat more pleasant :)

The push on the stack (=saving the value) is the task of the register
allocator. The compiler internally uses imaginary registers. These
registers will be assigned later on by the register allocator and when it
has too less real registers available the register will be save temporary
in the stackframe. The better the register allocator can do his job the
better code is generated. In a lot of cases with simple callings like
proc(i,j,k) the values of i,j and k will directly be loaded in the correct
register.

For more information see the technical design (=source code) :-)



___
fpc-devel maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel]default calling convention change for i386

2003-12-24 Thread Jonas Maebe
On 24 dec 2003, at 00:39, Peter Vreman wrote:

From today the default calling convention for i386 is changed from 
stdcall
(the default since 1.9.0) to register calling. This means that you 
have to
look at how assembler code loads the arguments and maybe store them
yourself in local variables.
Also note that the old calling convention is still available by using 
the oldfpccall modifier (e.g. procedure test; oldfpccall;)

Jonas

___
fpc-devel maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel]default calling convention change for i386

2003-12-24 Thread Ingmar Tulva
Bad news :(

Is this true for all {$mode }'s or only {$mode delphi} ?

On Wed, 24 Dec 2003, Peter Vreman wrote:

}Hi all,
}
}From today the default calling convention for i386 is changed from stdcall
}(the default since 1.9.0) to register calling. This means that you have to
}look at how assembler code loads the arguments and maybe store them
}yourself in local variables.
}
}The register calling is compatible with delphi, so delphi assembler can
}now be used without changes. If there are still incompatibilities with
}delphi register calling please report the to the fpc-devel mailinglist
}including some same code.

--

Ingmar

--

Experience is what you get when you don't get what you want


___
fpc-devel maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re[2]: [fpc-devel]default calling convention change for i386

2003-12-24 Thread Pavel V. Ozerski
Hello Ingmar,

Wednesday, December 24, 2003, 1:21:32 PM, you wrote:

IT Bad news :(

IT Is this true for all {$mode }'s or only {$mode delphi} ?

Why bad, Try to add {$calling oldfpccall} into your source
-- 
Best regards,
 Pavelmailto:[EMAIL PROTECTED]



___
fpc-devel maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re[2]: [fpc-devel]default calling convention change for i386

2003-12-24 Thread Ingmar Tulva
On Wed, 24 Dec 2003, Pavel V. Ozerski wrote:

}IT Bad news :(
}
}IT Is this true for all {$mode }'s or only {$mode delphi} ?
}
}Why bad, Try to add {$calling oldfpccall} into your source

Just personal taste, nothing else :) No, I'm not complaining, do what
you find is right.

Anyway, has someone actually analyzed how benefitial register calling
convention is? Sure it provides huge speed boost in case of a function
which adds two arguments together and returns the result - or is it so
sure? In fact, I imagine that in most cases, register convention will
eventually be detrimental to both speed and code size.

Again, no complain intended, just curiousity.

--

Ingmar

--

Experience is what you get when you don't get what you want


___
fpc-devel maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel]default calling convention change for i386

2003-12-24 Thread Anton Tichawa
Hello!

On Wednesday 24 December 2003 13:00, Ingmar Tulva wrote:

 Anyway, has someone actually analyzed how benefitial register calling
 convention is? Sure it provides huge speed boost in case of a function
 which adds two arguments together and returns the result - or is it so
 sure? In fact, I imagine that in most cases, register convention will
 eventually be detrimental to both speed and code size.

 Again, no complain intended, just curiousity.


I'm not a developper of free-pascal, so the following statements are just 
general considerations.

To me, register convention is a great step forward, concerning the economic 
usage of available resources.

Register convention saves opcode space in the called function, because within 
the instruction opcode,  registers are encoded with small bit fields, whereas 
offsets into a stack frame are encoded as (8-, 16-, or 32-bit) words, unless 
the processor supports something like short offsets. Actually, I don't know 
if the i386 does support such short offsets. AFAIK, the 68000 does not.

Every register parameter also saves at least two memory (stack) accesses, 
which are considerably slower compared to register accesses and increase bus 
use.

When writing low-level functions in 680x0 assembler, I always pass parameters 
in registers (there are 15 of them, which is quite a lot). In an embedded 
system, I sometimes even use global register variables, e. g. register D7 
contains, throughout the whole program, the current user ID.

A bit off-topic: I also return boolean result in a processor flag, to allow 
fast testing:

pascal:

begin
  if my_boolean_function then begin
bla

assembler
  jsr my_boolean_function
  bcs.s yes
..
yes: bla

Implementations I know of, pass boolean result in D0, which is slower, but 
still faster compared to stack parameters.

In 180 degree contradiction to your opinion, I think that register convention 
will, in most cases, save both memory and execution time :)

As an example, consider the call

function main;
var
  a: integer;
  b: integer;
begin
  my_function(a, b);
end;

With conventional calling:

move a, -(a7) // 2 memory accesses
move b, -(a7) // 2 memory accesses
jsr my_function

WIth register calling:

move a, d0// 1 memory access
move b, d1// 1 memory access
jsr my_function

This example still does not include the benefits within procedure my_function, 
namely the saving of instruction extension words with stack offsets. In that 
case, 2 memory accesses (to the instruction extension word and to the stack 
data) are saved by register convention.

A further benefit would result from optimization between the registers passing 
parameters to my_function, and the registers used within function main for 
variables a and b, by allocating identical registers, thus removing 
instructions of the form move d5, d5. That's an optimization technique easy 
in assembler, but difficult for a compiler, especially when maintaining 
register allocation through serveral levels of function calls.

If anyone does some performance testing, comparing the two conventions, please 
post it to the list.

Anton.


___
fpc-devel maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel]default calling convention change for i386

2003-12-24 Thread Anton Tichawa
On Wednesday 24 December 2003 16:36, Anton Tichawa wrote:

 This example still does not include the benefits within procedure
 my_function, namely the saving of instruction extension words with stack
 offsets. In that case, 2 memory accesses (to the instruction extension word
 and to the stack data) are saved by register convention.

Still another benefit is the reduced usage of stack memory.

Anton.


___
fpc-devel maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-devel


[fpc-devel]default calling convention change for i386

2003-12-23 Thread Peter Vreman
Hi all,

From today the default calling convention for i386 is changed from stdcall
(the default since 1.9.0) to register calling. This means that you have to
look at how assembler code loads the arguments and maybe store them
yourself in local variables.

The register calling is compatible with delphi, so delphi assembler can
now be used without changes. If there are still incompatibilities with
delphi register calling please report the to the fpc-devel mailinglist
including some same code.

Note that for other processors like powerpc (including the x86_64) we only
support the stdcall (following the standard ABI) calling convention and
all other conventions are ignored.

Peter


___
fpc-devel maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-devel