public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* optimization hints?
@ 1999-06-11  1:47 Alfred Perlstein
  1999-06-11  1:58 ` Jeffrey A Law
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Alfred Perlstein @ 1999-06-11  1:47 UTC (permalink / raw)
  To: egcs

It has always seemed weird that C, the langue usually chosen because
it's closeness to the machine level wouldn't have a hint like 
system for doing branches.

Is there such a way to do this?

case in point:


  do {
    if ((ret = poll(pfds, num_pfds, INFTIM)) == -1)
        switch(ret = errno) {
        case EINTR:
             continue;
        default:
             panic("internal poll error %s", strerror(ret));
        }
    }
  ......
  } while (...);

just the fact that I don't expect an error (poll() returning -1),
I was hoping to be able to tell it that this code isn't likely to
execute and perhaps even move it someplace else to maximize the
instruction cache utilization of my code.

does this make sense?  is there anything in the works to do this, or
perhaps something I missed?

isn't it about time C developers had this kind of control over thier
code?

it'd be nice to have a "maybe((ret = poll(pfds, num_pfds, INFTIM)) == -1)"
or something :)

thanks,
-Alfred 

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: optimization hints?
@ 1999-06-11 10:34 Mike Stump
  1999-06-16  9:42 ` Alfred Perlstein
  1999-06-30 15:43 ` Mike Stump
  0 siblings, 2 replies; 20+ messages in thread
From: Mike Stump @ 1999-06-11 10:34 UTC (permalink / raw)
  To: bright, egcs

> Date: Fri, 11 Jun 1999 04:06:15 -0500 (EST)
> From: Alfred Perlstein <bright@rush.net>

> It has always seemed weird that C, the langue usually chosen because
> it's closeness to the machine level wouldn't have a hint like system
> for doing branches.

>     if ((ret = poll(pfds, num_pfds, INFTIM)) == -1)

> isn't it about time C developers had this kind of control over thier
> code?

Yes and no.  gcc is better off if in this one case, gcc developers can
tag `known' functions with expected results (or unexpected results as
the case may be), and let the optimizer use this to rearrange code.

For example, the simple rule that compares to -1 are usually false,
even as a general optimization rule, would go a long way to doing the
right thing in most C code I have seen.

The results one gets from that one general rule I feel would be better
than littering C code with attributes, pragma and the like.

Also note that you can get most of the benefit by using
-fbranch-probabilities, from the doc:

@item -fbranch-probabilities
After running a program compiled with @samp{-fprofile-arcs}
(@pxref{Debugging Options,, Options for Debugging Your Program or
@code{gcc}}), you can compile it a second time using
@samp{-fbranch-probabilities}, to improve optimizations based on
guessing the path a branch might take.

if your port doesn't yet support this, maybe you want to contribute
support for this?

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: optimization hints?
@ 1999-06-11 16:50 Alex Rosenberg
  1999-06-30 15:43 ` Alex Rosenberg
  0 siblings, 1 reply; 20+ messages in thread
From: Alex Rosenberg @ 1999-06-11 16:50 UTC (permalink / raw)
  To: egcs

> just the fact that I don't expect an error (poll() returning -1),
> I was hoping to be able to tell it that this code isn't likely to
> execute and perhaps even move it someplace else to maximize the
> instruction cache utilization of my code.

Apple's MrC compiler has two pragmas for this:

#pragma seldom

This moves the marked block to the end of the function (after the exit
node).

#pragma outofline

This puts the marked block in a seperate GL function in the XCOFF, which
results in placement at the end of the file by the linker.

Both would be straight-forward to implement in egcs, but pragmas have been
shunned in the past. No keyword alternative approach comes to mind.

A particularly useful variant would be to automatically move C++ catch
blocks.

+------------------------------------------------------------+
| Alexander M. Rosenberg           < mailto:alexr@_spies.com > |
| Nobody cares what I say. Remove the underscore to mail me. |

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: optimization hints?
@ 1999-06-11 17:43 Mike Stump
  1999-06-30 15:43 ` Mike Stump
  0 siblings, 1 reply; 20+ messages in thread
From: Mike Stump @ 1999-06-11 17:43 UTC (permalink / raw)
  To: alexr, egcs

> Date: Fri, 11 Jun 1999 16:49:48 -0700
> From: "Alex Rosenberg" <alexr@spies.com>
> To: egcs@egcs.cygnus.com

> A particularly useful variant would be to automatically move C++ catch
> blocks.

They are already move to the end of the function (as I recall).  If
the infrastructure was in the compiler to move them farther, I would
have used it.  I thought about it, but didn't take the hit to add the
infrastructure.

Generally speaking, I think this type of thing is good.  Also,
coverage feedback to reorder hot spots for the cache would be nice,
seems we may already have most of the code to do that already.

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

end of thread, other threads:[~1999-06-30 15:43 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-11  1:47 optimization hints? Alfred Perlstein
1999-06-11  1:58 ` Jeffrey A Law
1999-06-30 15:43   ` Jeffrey A Law
1999-06-11  6:08 ` Robert Lipe
1999-06-11  9:12   ` Joe Buck
1999-06-30 15:43     ` Joe Buck
1999-06-11 18:28   ` Benjamin Scherrey
1999-06-11 19:17     ` Robert Lipe
1999-06-30 15:43       ` Robert Lipe
1999-06-30 15:43     ` Benjamin Scherrey
1999-06-30 15:43   ` Robert Lipe
1999-06-30 15:43 ` Alfred Perlstein
1999-06-11 10:34 Mike Stump
1999-06-16  9:42 ` Alfred Perlstein
1999-06-30 15:43   ` Alfred Perlstein
1999-06-30 15:43 ` Mike Stump
1999-06-11 16:50 Alex Rosenberg
1999-06-30 15:43 ` Alex Rosenberg
1999-06-11 17:43 Mike Stump
1999-06-30 15:43 ` Mike Stump

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).