comp.lang.ada
 help / color / mirror / Atom feed
* Modern optimizing compilers
@ 2017-08-21 20:32 Victor Porton
  2017-08-21 23:19 ` gautier_niouzes
  0 siblings, 1 reply; 6+ messages in thread
From: Victor Porton @ 2017-08-21 20:32 UTC (permalink / raw)


Can modern optimizing compilers (such as GNAT or LLVM) "realize" that they 
should not create a record on the stack, if only some variables of the 
record are used and values of these variables as (in principle) predictable?

Does it work with Ada's tagged record?

-- 
Victor Porton - http://portonvictor.org


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Modern optimizing compilers
  2017-08-21 20:32 Modern optimizing compilers Victor Porton
@ 2017-08-21 23:19 ` gautier_niouzes
  2017-08-22  1:11   ` Victor Porton
  0 siblings, 1 reply; 6+ messages in thread
From: gautier_niouzes @ 2017-08-21 23:19 UTC (permalink / raw)


You can compile a package containing a test procedure putting 123 into an Integer field of a record (tagged or not) and look at the assembler output.
With GNAT it's gcc -S -O2 test_pkg.adb
NB: the procedure probably needs to feed then an "out" parameter to prevent the compiler optimizing out completely the assignment with 123.

Gautier
_____________________________________________________________
A free online game in Ada: http://pasta.phyrama.com/game.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Modern optimizing compilers
  2017-08-21 23:19 ` gautier_niouzes
@ 2017-08-22  1:11   ` Victor Porton
  2017-08-22  1:17     ` Victor Porton
  0 siblings, 1 reply; 6+ messages in thread
From: Victor Porton @ 2017-08-22  1:11 UTC (permalink / raw)


gautier_niouzes@hotmail.com wrote:

> You can compile a package containing a test procedure putting 123 into an
> Integer field of a record (tagged or not) and look at the assembler
> output. With GNAT it's gcc -S -O2 test_pkg.adb NB: the procedure probably
> needs to feed then an "out" parameter to prevent the compiler optimizing
> out completely the assignment with 123.

It seems that your case is wrong.

This procedure has no other choice than to write into the referenced record.

We can however check with code like:

procedure M is
  type T is record
    X: Integer;
  end record;

  I: T;
begin
  I.X := 10;
  Ada.Text_IO.Put_Line(Integer'Image(I.X));
end;

> Gautier
> _____________________________________________________________
> A free online game in Ada: http://pasta.phyrama.com/game.html

-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Modern optimizing compilers
  2017-08-22  1:11   ` Victor Porton
@ 2017-08-22  1:17     ` Victor Porton
  2017-08-22  1:20       ` Victor Porton
  0 siblings, 1 reply; 6+ messages in thread
From: Victor Porton @ 2017-08-22  1:17 UTC (permalink / raw)


Victor Porton wrote:

> gautier_niouzes@hotmail.com wrote:
> 
>> You can compile a package containing a test procedure putting 123 into an
>> Integer field of a record (tagged or not) and look at the assembler
>> output. With GNAT it's gcc -S -O2 test_pkg.adb NB: the procedure probably
>> needs to feed then an "out" parameter to prevent the compiler optimizing
>> out completely the assignment with 123.
> 
> It seems that your case is wrong.
> 
> This procedure has no other choice than to write into the referenced
> record.
> 
> We can however check with code like:
> 
> procedure M is
>   type T is record
>     X: Integer;
>   end record;
> 
>   I: T;
> begin
>   I.X := 10;
>   Ada.Text_IO.Put_Line(Integer'Image(I.X));
> end;

I don't understand the assembler output of compiling this program (with 
added "with Ada.Text_IO;") with GCC 7.1.0, but it looks like very poorly 
optimized (very long). I don't know why the assembler code is so long.

>> Gautier
>> _____________________________________________________________
>> A free online game in Ada: http://pasta.phyrama.com/game.html
> 
-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Modern optimizing compilers
  2017-08-22  1:17     ` Victor Porton
@ 2017-08-22  1:20       ` Victor Porton
  2017-08-22  7:28         ` gautier_niouzes
  0 siblings, 1 reply; 6+ messages in thread
From: Victor Porton @ 2017-08-22  1:20 UTC (permalink / raw)


Victor Porton wrote:

> Victor Porton wrote:
> 
>> gautier_niouzes@hotmail.com wrote:
>> 
>>> You can compile a package containing a test procedure putting 123 into
>>> an Integer field of a record (tagged or not) and look at the assembler
>>> output. With GNAT it's gcc -S -O2 test_pkg.adb NB: the procedure
>>> probably needs to feed then an "out" parameter to prevent the compiler
>>> optimizing out completely the assignment with 123.
>> 
>> It seems that your case is wrong.
>> 
>> This procedure has no other choice than to write into the referenced
>> record.
>> 
>> We can however check with code like:
>> 
>> procedure M is
>>   type T is record
>>     X: Integer;
>>   end record;
>> 
>>   I: T;
>> begin
>>   I.X := 10;
>>   Ada.Text_IO.Put_Line(Integer'Image(I.X));
>> end;
> 
> I don't understand the assembler output of compiling this program (with
> added "with Ada.Text_IO;") with GCC 7.1.0, but it looks like very poorly
> optimized (very long). I don't know why the assembler code is so long.

Oh, I forgot -O3 flag :-)

Not sure if the optimizer with -O3 is good, but now the code it much 
shorter, however yet seems for me too long.

>>> Gautier
>>> _____________________________________________________________
>>> A free online game in Ada: http://pasta.phyrama.com/game.html
>> 
-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Modern optimizing compilers
  2017-08-22  1:20       ` Victor Porton
@ 2017-08-22  7:28         ` gautier_niouzes
  0 siblings, 0 replies; 6+ messages in thread
From: gautier_niouzes @ 2017-08-22  7:28 UTC (permalink / raw)


> Not sure if the optimizer with -O3 is good, but now the code it much 
> shorter, however yet seems for me too long.

It's not good: it's very good!...
On more complex source code, the assembler output is very long, looks confuse to the human reader... but the result is very fast.
Intuition or common sense are helpless in guessing performance from the assembler output.
If you want compact machine code, use -Os instead.
It may be useful to use -O2 plus selected options like loop unrolling for tuning performance.

Side note 1: IIRC id software already delegated the performance of their full-software Quake 1 3D renderer for GCC's optimizer, some 20 years ago!...

Side note 2: A similar full-software 3D renderer in Ada is available @ http://sf.net/projects/engine-3d/

_________________________ 
Gautier's Ada programming 
http://gautiersblog.blogspot.com/search/label/Ada 
NB: follow the above link for a valid e-mail address 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-08-22  7:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-21 20:32 Modern optimizing compilers Victor Porton
2017-08-21 23:19 ` gautier_niouzes
2017-08-22  1:11   ` Victor Porton
2017-08-22  1:17     ` Victor Porton
2017-08-22  1:20       ` Victor Porton
2017-08-22  7:28         ` gautier_niouzes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox