Re: [fpc-pascal] Inline function parameters

2021-11-07 Thread Sven Barth via fpc-pascal

Am 08.11.2021 um 03:45 schrieb Ryan Joseph via fpc-pascal:



On Nov 7, 2021, at 2:17 PM, Jonas Maebe via fpc-pascal 
 wrote:


Is there anyway a function parameter could be inlined in FPC? This would go a 
long way in helping to parameterize functions that have tight loops in them.

It's theoretically possible through constant propagation.

I understand simple constant propagation cases but how does this apply to 
inlining entire functions? I think C++ can do this with closures so it's 
something worth looking in to for the future.


This has nothing to do with closures.

Take a look at this:

=== code begin ===

type
  TFunc = function(aArg: LongInt): LongInt;
  TLongIntArray = array of LongInt;

function MultBy2(aArg: LongInt): LongInt; inline;
begin
  Result := aArg * 2;
end;

function Map(aArr: TLongIntArray; aFunc: TFunc): TLongIntArray; inline;
begin
  SetLength(Result, Length(aArr));
  for i := 0 to High(aArr) do
    Result[i] := aFunc(aArr[i]);
end;

var
  l1, l2: TLongIntArray;
begin
  l1 := [1, 2, 3, 4];
  l2 := Map(l1, @MultBy2);
end.

=== code end ===

Assuming constant propagation of function variables would work correctly 
what would happen in the compiler would be as follows (this is how the 
compiler already works):


Step 1: Inline Map function

=== code begin ===

// ...

begin
  l1 := [1, 2, 3, 4];
  SetLength(l2, 4);
  for i := 0 to 3 do
    Result[i] := MultBy2(aArr[i]);
end.

=== code end ===

Step 2: Check whether inlining provided new optimization possibilities 
(which again includes inlining and thus allows inlining of MultBy2!)


=== code begin ===

// ...

begin
  l1 := [1, 2, 3, 4];
  SetLength(l2, 4);
  for i := 0 to 3 do
    Result[i] := aArr[i] * 2;
end.

=== code end ===

And there you have it (simplified obviously). As long as the compiler 
can determine *at compile time* the code of the function (and the 
function is inlineable) it should in theory be able to inline it. This 
is true no matter if it's a function variable, a method variable 
(pointing to a non-virtual method) or an anonymous function. However if 
somewhere between passing in the function address and calling the 
function inlining does not work for one reason or the other (e.g. due to 
open array parameters which are currently not supported by inlining) 
then the compiler obviously can't inline the provided function either.


Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Inline function parameters

2021-11-07 Thread Ryan Joseph via fpc-pascal


> On Nov 7, 2021, at 2:17 PM, Jonas Maebe via fpc-pascal 
>  wrote:
> 
>> Is there anyway a function parameter could be inlined in FPC? This would go 
>> a long way in helping to parameterize functions that have tight loops in 
>> them.
> 
> It's theoretically possible through constant propagation.

I understand simple constant propagation cases but how does this apply to 
inlining entire functions? I think C++ can do this with closures so it's 
something worth looking in to for the future.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Cross-compiling and warnings from linker

2021-11-07 Thread Sergey Organov via fpc-pascal
Hello,

Using cross-compiler from x86-linux to arm-linux, I keep getting a lot
of warnings at the linking stage of my programs, in the form:

/opt/[...]/arm-linux-gnueabihf-ld: warning: library search path 
"/usr/lib/eject/" is unsafe for cross-compilation   
/opt/[...]/arm-linux-gnueabihf-ld: warning: warning: library search path 
"/usr/lib/console-setup/" is unsafe for 
cross-compilation
[...]

for virtually every sub-directory in /usr/lib. FPC 3.2.0 and 3.2.2 both
have this issue.

This makes me suspect FPC cross produces instructions for the linker to
search for wrong directories, where host libraries reside, that could
lead to unpredictable results, and tons of the warnings are really
annoying.

What's the way to fix this?

Thanks,
-- Sergey Organov

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Inline function parameters

2021-11-07 Thread Jonas Maebe via fpc-pascal

On 07/11/2021 05:26, Ryan Joseph via fpc-pascal wrote:

Is there anyway a function parameter could be inlined in FPC? This would go a 
long way in helping to parameterize functions that have tight loops in them.


It's theoretically possible through constant propagation.


If there isn't I wonder if this is an area where the proposed "pure" function 
modifier could be used to make it possible.


That's completely unrelated.


Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal