On 7 April 2011 16:02, Alex Kodat <[email protected]> wrote:

> There are always pieces of information that are extremely useful in optimizing
> code that are simply not present in the code itself so not possible for a
> compiler to use in optimization.

Some compilers, and more important, some languages, allow the
programmer to provide hints to the compiler.

The thread title says HLL, but we seem to be talking about C. C is
notorious for not having hints, except for the deprecated REGISTER
declaration, which I believe is now specified as "ignored" rather than
"may or may not be acted upon" (or whatever standards-lingo for that
is).

I remember years ago dealing with the C library function memcpy(). If
you pass the length in in a variable, the compiler cannot generate a
simple MVC, because it doesn't know the length (unless fancy data flow
analysis yields the knowledge that it is in fact fixed). But in the
general case the compiler cannot even generate an EXecute of an MVC,
because the length may exceed 256. It can always generate an MVC loop
or an MVCL (or more currently MVCLE), but that will be inefficient for
the probably likely short case.

But there is a trick: if the length variable is too small to allow
for, say, > 256, then MVC could be used. A character variable, one
might think, except that in C these are expanded to the always wider
int, and so that doesn't work. But in C++, which does not expand char
to int,  it *does* work, if the compiler is sufficiently on the ball.
And back around 1997 SAS/C was on the ball, and IBM C wasn't.

But the whole thing stinks - inventing cute tricks to pass implicit
knowledge *through* the language to the code generator. It would be
much nicer to be able to explicitly provide hints that the compiler
could exploit according to its abilities.

Interestingly, various hardware architectures have such hinting
mechanisms, so once the compiler is aware it may be able to pass them
on to the hardware layer. Even the JVM allows for vendor add-ons,
which are intended for debugging, but could be performance hints, as
long as they have no effect on the results.

Tony H.

Reply via email to