This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: programming language that does not inhibit further optimization by 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]