public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* programming language that does not inhibit further optimization by gcc
@ 2013-10-15  0:31 Albert Abramson
  2013-10-15 12:00 ` Rob
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Albert Abramson @ 2013-10-15  0:31 UTC (permalink / raw)
  To: gcc

I have been looking everywhere online and talking to other coders at
every opportunity about this, but cannot find a complete answer.
Different languages have different obstacles to complete optimization.
 Software developers often have to drop down into non-portable
Assembly because they can't get the performance or small size of
hand-optimized Assembly for their particular platform.

The C language has the alias issue that limits the hoisting of loads.
Unless the programmer specifies that two arrays will never overlap
using the 'restrict' keyword, the compiler may not be able to handle
operations on arrays efficiently because of the unlikely event that
the arrays could overlap.  Most/all languages also demand the
appearance of serialization of instructions and memory operations, as
well as extreme correctness in even the most unlikely circumstances,
even where the programmer may not need them.

Is there a language out there (similar to Fortran or a dialect of C)
that doesn't inhibit the compiler from taking advantage of every
optimization possible?  Is there some way to provide a C/C++ compiler
with extra information about variables and programs so that it can
maximize performance or minimize size?  For example:

int age = 21;    //[0, 150)  setting maximum limits, compiler could use byte int
int outsideTemp = 20;    //[-273, 80]
float ERA = 297;           //[0, 1000, 3]   [min, max, digits of
accuracy needed]

Better yet, allow some easier way of spawning multiple threads without
have to learn all of the Boost libraries, OpenCL, or OpenGL.  In other
words, is there yet a language that is designed only for performance
that places no limits on compiler optimizations?  Is there a language
that allows the compiler to pack struct variables in tighter by
reorganizing those values, etc?

If not, is it possible to put together some dialect of C/C++ that
replaces Assembly outright?

-- 
Max Abramson
“In the end, more than freedom, they wanted security. They wanted a
comfortable life, and they lost it all – security, comfort, and
freedom. When the Athenians finally wanted not to give to society but
for society to give to them, when the freedom they wished for most was
freedom from responsibility, then Athens ceased to be free and was
never free again.” --Sir Edward Gibbon

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

* Re: programming language that does not inhibit further optimization by gcc
  2013-10-15  0:31 programming language that does not inhibit further optimization by gcc Albert Abramson
@ 2013-10-15 12:00 ` Rob
  2019-03-30  7:14   ` Albert Abramson
  2013-10-15 14:45 ` Ian Lance Taylor
  2013-10-15 22:09 ` gwenael chailleu
  2 siblings, 1 reply; 6+ messages in thread
From: Rob @ 2013-10-15 12:00 UTC (permalink / raw)
  To: Albert Abramson; +Cc: gcc

GCC does value analysis similar to what you mentioned. You'll find it
under the -fdump-tree-vrp options. To provide extra information you
can add range checks which GCC will pick up on. If you know a value is
small, use a small integer type and gcc will pick up the range of
values which can be assigned to it.

What are the problems you're trying to solve? Is it a low memory
system you're running on?

If you're after performance, add restrict to your parameters and
either use unions to get around aliasing or do what the Linux dev team
do with -fno-strict-aliasing.

Regarding threading - I think trying to use multiple threads without
having to learn thread libraries is a bit of a gamble. Threading is
difficult even in high level languages and you should have a good
background before approaching.

For struct packing, I suppose you could just order your entries
largest-first which is one approach, but it's kinda like the 0-1
knapsack problem.


On 15 October 2013 01:31, Albert Abramson <abramson.albert@gmail.com> wrote:
> I have been looking everywhere online and talking to other coders at
> every opportunity about this, but cannot find a complete answer.
> Different languages have different obstacles to complete optimization.
>  Software developers often have to drop down into non-portable
> Assembly because they can't get the performance or small size of
> hand-optimized Assembly for their particular platform.
>
> The C language has the alias issue that limits the hoisting of loads.
> Unless the programmer specifies that two arrays will never overlap
> using the 'restrict' keyword, the compiler may not be able to handle
> operations on arrays efficiently because of the unlikely event that
> the arrays could overlap.  Most/all languages also demand the
> appearance of serialization of instructions and memory operations, as
> well as extreme correctness in even the most unlikely circumstances,
> even where the programmer may not need them.
>
> Is there a language out there (similar to Fortran or a dialect of C)
> that doesn't inhibit the compiler from taking advantage of every
> optimization possible?  Is there some way to provide a C/C++ compiler
> with extra information about variables and programs so that it can
> maximize performance or minimize size?  For example:
>
> int age = 21;    //[0, 150)  setting maximum limits, compiler could use byte int
> int outsideTemp = 20;    //[-273, 80]
> float ERA = 297;           //[0, 1000, 3]   [min, max, digits of
> accuracy needed]
>
> Better yet, allow some easier way of spawning multiple threads without
> have to learn all of the Boost libraries, OpenCL, or OpenGL.  In other
> words, is there yet a language that is designed only for performance
> that places no limits on compiler optimizations?  Is there a language
> that allows the compiler to pack struct variables in tighter by
> reorganizing those values, etc?
>
> If not, is it possible to put together some dialect of C/C++ that
> replaces Assembly outright?
>
> --
> Max Abramson
> “In the end, more than freedom, they wanted security. They wanted a
> comfortable life, and they lost it all – security, comfort, and
> freedom. When the Athenians finally wanted not to give to society but
> for society to give to them, when the freedom they wished for most was
> freedom from responsibility, then Athens ceased to be free and was
> never free again.” --Sir Edward Gibbon

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

* Re: programming language that does not inhibit further optimization by gcc
  2013-10-15  0:31 programming language that does not inhibit further optimization by gcc Albert Abramson
  2013-10-15 12:00 ` Rob
@ 2013-10-15 14:45 ` Ian Lance Taylor
  2013-10-15 22:09 ` gwenael chailleu
  2 siblings, 0 replies; 6+ messages in thread
From: Ian Lance Taylor @ 2013-10-15 14:45 UTC (permalink / raw)
  To: Albert Abramson; +Cc: GCC Development

On Mon, Oct 14, 2013 at 5:31 PM, Albert Abramson
<abramson.albert@gmail.com> wrote:
>
> Is there a language out there (similar to Fortran or a dialect of C)
> that doesn't inhibit the compiler from taking advantage of every
> optimization possible?

Sure: Fortran.


> Is there some way to provide a C/C++ compiler
> with extra information about variables and programs so that it can
> maximize performance or minimize size?  For example:
>
> int age = 21;    //[0, 150)  setting maximum limits, compiler could use byte int
> int outsideTemp = 20;    //[-273, 80]
> float ERA = 297;           //[0, 1000, 3]   [min, max, digits of
> accuracy needed]

Hmmm, OK, that kind of thing is available in PL/1 and, I think, in
Ada.  But as far as I know it doesn't help compilers very much in
practice.

Ian

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

* Re: programming language that does not inhibit further optimization by gcc
  2013-10-15  0:31 programming language that does not inhibit further optimization by gcc Albert Abramson
  2013-10-15 12:00 ` Rob
  2013-10-15 14:45 ` Ian Lance Taylor
@ 2013-10-15 22:09 ` gwenael chailleu
  2 siblings, 0 replies; 6+ messages in thread
From: gwenael chailleu @ 2013-10-15 22:09 UTC (permalink / raw)
  To: Albert Abramson; +Cc: gcc

Here is the way I understood the goal of your long quest (I may be
completely mistaken since I do not quite get what part of the job you
want to leave to the language and what part to its compiler)

"Is there a language that allow the developer to add information about
the way a particular program will really use the variables it
declares, or the function it calls, so that this information can be
exploited by the compiler to optimize as far as possible the final
binary ?"

We are developing Cawen (please do not hesitate to take a look at
http://www.melvenn.com/en/cawen/why-cawen/), a language that includes
C99 and produces C99 source code (it can be considered as a
precompiling tool for C).

-----------
Variables :

Cawen gives you the possibility to enrich variables with user information :

Your sample code :

int age = 21;    //[0, 150)  setting maximum limits, compiler could use byte int
int outsideTemp = 20;    //[-273, 80]
float ERA = 297;           //[0, 1000, 3]   [min, max, digits of
accuracy needed]

Can be written in Cawen as

int age < < min = 0, max = 150 > > = 21;
int outsideTemp < < min = -273, max = 80 > > = 20;
float ERA < < min=0,max=1000,accur=3 > > = 297;

The range properties can further be asked for in the Cawen code with
age = > min, age = > max and so on.

Ex :

int repartition [ age = > max  + 1];

min, max are not Cawen keywords, you can create as many labels as you want :

int age < < min = 0, max = 150, average = 100 > >;


One can also code things like :

@declare(integer,age,max,150,min,0);
etc. ..

It is up to the Cawen coder to implement the @declare macro that would
consider that an integer beetwen 0 and 150 must be declared as an
unsigned char in the generated C code.

unsigned char age;

age = > min and age = > max remain available...

This was for user code. As far as giving hints to the compiler is
concerned, Cawen has got no compiler and relies entirely on the C
compiler. So that range information can only be used at compile time
if the C compiler can make use of them through a specific syntax.
In this case, Cawen preprocessor would let you code your own
transformation from its own syntax :

int age < < min =0, max = 150 > > = 21;

to the C target

int age whatever_compiler_specific_syntax_(0,150);

Of course, age = > min, age = > max are still available.

---------

Functions :

Here is an example of how Cawen's function template mechanism can be
used for optimization :

This line appends the 10 first elements of a to b.

@govel::append(a,10,b); // govel is the first Cawen's standard library

The function will first check if there is enough elements in a. This
checking is totally unnecessary if the coder knows that a is equal to
"a_string_that_is_more_than_10_char_long".

Coding

@govel::append{ !src_check }(a,10,b)

you can tell Cawen (in govel's code) to skip it.

Feel free to create and implement hundreds of templating parameters !

@govel::append{ !src_check  size_opt_level = 1  speed_opt_level = 3
!memcpy debug   comment = " with a lot of care" ...   }(a,10,b)


Regards

TS & GC

2013/10/15 Albert Abramson <abramson.albert@gmail.com>:
> I have been looking everywhere online and talking to other coders at
> every opportunity about this, but cannot find a complete answer.
> Different languages have different obstacles to complete optimization.
>  Software developers often have to drop down into non-portable
> Assembly because they can't get the performance or small size of
> hand-optimized Assembly for their particular platform.
>
> The C language has the alias issue that limits the hoisting of loads.
> Unless the programmer specifies that two arrays will never overlap
> using the 'restrict' keyword, the compiler may not be able to handle
> operations on arrays efficiently because of the unlikely event that
> the arrays could overlap.  Most/all languages also demand the
> appearance of serialization of instructions and memory operations, as
> well as extreme correctness in even the most unlikely circumstances,
> even where the programmer may not need them.
>
> Is there a language out there (similar to Fortran or a dialect of C)
> that doesn't inhibit the compiler from taking advantage of every
> optimization possible?  Is there some way to provide a C/C++ compiler
> with extra information about variables and programs so that it can
> maximize performance or minimize size?  For example:
>
> int age = 21;    //[0, 150)  setting maximum limits, compiler could use byte int
> int outsideTemp = 20;    //[-273, 80]
> float ERA = 297;           //[0, 1000, 3]   [min, max, digits of
> accuracy needed]
>
> Better yet, allow some easier way of spawning multiple threads without
> have to learn all of the Boost libraries, OpenCL, or OpenGL.  In other
> words, is there yet a language that is designed only for performance
> that places no limits on compiler optimizations?  Is there a language
> that allows the compiler to pack struct variables in tighter by
> reorganizing those values, etc?
>
> If not, is it possible to put together some dialect of C/C++ that
> replaces Assembly outright?
>
> --
> Max Abramson
> “In the end, more than freedom, they wanted security. They wanted a
> comfortable life, and they lost it all – security, comfort, and
> freedom. When the Athenians finally wanted not to give to society but
> for society to give to them, when the freedom they wished for most was
> freedom from responsibility, then Athens ceased to be free and was
> never free again.” --Sir Edward Gibbon

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

* Re: programming language that does not inhibit further optimization by gcc
  2013-10-15 12:00 ` Rob
@ 2019-03-30  7:14   ` Albert Abramson
  2019-03-30 10:42     ` David Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Albert Abramson @ 2019-03-30  7:14 UTC (permalink / raw)
  To: Rob; +Cc: gcc

Now I'm on a totally unrelated project, writing code in C, but still using
the GCC compiler under the hood.  The previous developers used raw pointers
quite a bit.  However, as I expand the code, I'd like to use some of the
features in C++, but Atmel Studio doesn't REALLY support C++.
 Code::Blocks is letting me turn warning flags on and off, but I don't see
the same for individual C++ features.  (Lots of subsets of C++, but I
really need a true superset of C.)

Is there some way to manually turn on individual C++17 features, one at a
time?  I read somewhere that you can, but I don't see the post online
anywhere.  And if I create a list of individual C++ features, can this made
into a kind of standard, shared with other programmers?  In other words,
I'd like to make use of lambdas, namespaces, smart pointers, range-based
for loops, and a few others that would save me a lot of time and maybe even
reduce the size of the binary (since we're very RAM limited in the embedded
world).

I'm writing about this on the Facebook page "C+ Project," which is open to
all programmers.

On Tue, Oct 15, 2013 at 8:00 AM Rob <robpilling@gmail.com> wrote:

> GCC does value analysis similar to what you mentioned. You'll find it
> under the -fdump-tree-vrp options. To provide extra information you
> can add range checks which GCC will pick up on. If you know a value is
> small, use a small integer type and gcc will pick up the range of
> values which can be assigned to it.
>
> What are the problems you're trying to solve? Is it a low memory
> system you're running on?
>
> If you're after performance, add restrict to your parameters and
> either use unions to get around aliasing or do what the Linux dev team
> do with -fno-strict-aliasing.
>
> Regarding threading - I think trying to use multiple threads without
> having to learn thread libraries is a bit of a gamble. Threading is
> difficult even in high level languages and you should have a good
> background before approaching.
>
> For struct packing, I suppose you could just order your entries
> largest-first which is one approach, but it's kinda like the 0-1
> knapsack problem.
>
>
> On 15 October 2013 01:31, Albert Abramson <abramson.albert@gmail.com>
> wrote:
> > I have been looking everywhere online and talking to other coders at
> > every opportunity about this, but cannot find a complete answer.
> > Different languages have different obstacles to complete optimization.
> >  Software developers often have to drop down into non-portable
> > Assembly because they can't get the performance or small size of
> > hand-optimized Assembly for their particular platform.
> >
> > The C language has the alias issue that limits the hoisting of loads.
> > Unless the programmer specifies that two arrays will never overlap
> > using the 'restrict' keyword, the compiler may not be able to handle
> > operations on arrays efficiently because of the unlikely event that
> > the arrays could overlap.  Most/all languages also demand the
> > appearance of serialization of instructions and memory operations, as
> > well as extreme correctness in even the most unlikely circumstances,
> > even where the programmer may not need them.
> >
> > Is there a language out there (similar to Fortran or a dialect of C)
> > that doesn't inhibit the compiler from taking advantage of every
> > optimization possible?  Is there some way to provide a C/C++ compiler
> > with extra information about variables and programs so that it can
> > maximize performance or minimize size?  For example:
> >
> > int age = 21;    //[0, 150)  setting maximum limits, compiler could use
> byte int
> > int outsideTemp = 20;    //[-273, 80]
> > float ERA = 297;           //[0, 1000, 3]   [min, max, digits of
> > accuracy needed]
> >
> > Better yet, allow some easier way of spawning multiple threads without
> > have to learn all of the Boost libraries, OpenCL, or OpenGL.  In other
> > words, is there yet a language that is designed only for performance
> > that places no limits on compiler optimizations?  Is there a language
> > that allows the compiler to pack struct variables in tighter by
> > reorganizing those values, etc?
> >
> > If not, is it possible to put together some dialect of C/C++ that
> > replaces Assembly outright?
> >
> > --
> > Max Abramson
> > “In the end, more than freedom, they wanted security. They wanted a
> > comfortable life, and they lost it all – security, comfort, and
> > freedom. When the Athenians finally wanted not to give to society but
> > for society to give to them, when the freedom they wished for most was
> > freedom from responsibility, then Athens ceased to be free and was
> > never free again.” --Sir Edward Gibbon
>


-- 
“In the end, more than freedom, they wanted security. They wanted a
comfortable life, and they lost it all – security, comfort, and freedom.
When the Athenians finally wanted not to give to society but for society to
give to them, when the freedom they wished for most was freedom from
responsibility, then Athens ceased to be free and was never free again.”
--Sir Edward Gibbon

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

* Re: programming language that does not inhibit further optimization by gcc
  2019-03-30  7:14   ` Albert Abramson
@ 2019-03-30 10:42     ` David Brown
  0 siblings, 0 replies; 6+ messages in thread
From: David Brown @ 2019-03-30 10:42 UTC (permalink / raw)
  To: Albert Abramson; +Cc: gcc

On 30/03/2019 08:13, Albert Abramson wrote:
> Now I'm on a totally unrelated project, writing code in C, but still using
> the GCC compiler under the hood.  The previous developers used raw pointers
> quite a bit.  However, as I expand the code, I'd like to use some of the
> features in C++, but Atmel Studio doesn't REALLY support C++.
>   Code::Blocks is letting me turn warning flags on and off, but I don't see
> the same for individual C++ features.  (Lots of subsets of C++, but I
> really need a true superset of C.)
> 
> Is there some way to manually turn on individual C++17 features, one at a
> time?  I read somewhere that you can, but I don't see the post online
> anywhere.  And if I create a list of individual C++ features, can this made
> into a kind of standard, shared with other programmers?  In other words,
> I'd like to make use of lambdas, namespaces, smart pointers, range-based
> for loops, and a few others that would save me a lot of time and maybe even
> reduce the size of the binary (since we're very RAM limited in the embedded
> world).
> 
> I'm writing about this on the Facebook page "C+ Project," which is open to
> all programmers.
> 

Your post here is new - it is not helpful to make it a follow-up on a 6 
year old conversation.  And it is not helpful to write as though we are 
all familiar with what you are doing and the projects you work on.

To get the crux of the matter, it seems that you want to write mainly C, 
but use some C++17 features.  The way to do that is with C++17.  You 
don't "turn on individual C++17 features" - you enable C++17 support 
(with the "-std=gnu++17" flag support) and just use the features you 
want (limited by the lack of C++ libraries for the AVR).


If you choose to use an IDE and use it to control compiler flags, there 
is always a way to manually enter flags yourself.

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

end of thread, other threads:[~2019-03-30 10:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-15  0:31 programming language that does not inhibit further optimization by gcc Albert Abramson
2013-10-15 12:00 ` Rob
2019-03-30  7:14   ` Albert Abramson
2019-03-30 10:42     ` David Brown
2013-10-15 14:45 ` Ian Lance Taylor
2013-10-15 22:09 ` gwenael chailleu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).