[fpc-pascal] FPC Graphics options?

Florian Klämpfl florian at freepascal.org
Sun May 21 10:35:57 CEST 2017


Am 20.05.2017 um 23:15 schrieb Sven Barth via fpc-pascal:
> On 20.05.2017 21:34, Jonas Maebe wrote:
>> There's at least one minor twist of the classic "C compiler evaluates
>> constant stuff at compile time":
>> 1) oy and oz are constant. The "floor" function is a standard C library
>> function, and hence C compilers know what it does and can evaluate it at
>> compile time. Therefore, the oy-floor(oy) and oz-floor(oz) expressions
>> are (equal) constants for C compilers.
> 
> Would it help here if we'd declare suitable overloads for Floor() for


The overloads are imo not needed, if x is randomly positive/negative the following code is much
better than the current implementation:

function Floor(x : float) : Integer;Inline;
  begin
    Result := Trunc(x)-ord(Frac(x)<0);
  end;

> the various floating point types instead of only the "Float" one,
> declare them as inline and have the inline nodes for Frac() and Trunc()
> handle constant values?

I adjusted the inline heuristics so the Floor code above is completely folded for constant arguments.

> At least if the compiler also recognizes that oy and oz are constant...

If the typed constants are declared as read only, we could treat them as real constants. Maybe at
least in -O4 mode?



More information about the fpc-pascal mailing list