From mboxrd@z Thu Jan 1 00:00:00 1970 From: mrs@wrs.com (Mike Stump) To: bright@rush.net, egcs@egcs.cygnus.com Subject: Re: optimization hints? Date: Fri, 11 Jun 1999 10:34:00 -0000 Message-id: <199906111733.KAA22371@kankakee.wrs.com> X-SW-Source: 1999-06/msg00389.html > Date: Fri, 11 Jun 1999 04:06:15 -0500 (EST) > From: Alfred Perlstein > 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? From mboxrd@z Thu Jan 1 00:00:00 1970 From: mrs@wrs.com (Mike Stump) To: bright@rush.net, egcs@egcs.cygnus.com Subject: Re: optimization hints? Date: Wed, 30 Jun 1999 15:43:00 -0000 Message-ID: <199906111733.KAA22371@kankakee.wrs.com> X-SW-Source: 1999-06n/msg00389.html Message-ID: <19990630154300.UK92rFXaODNWy-JZlu0foEC-a9MuaPTpfBAS8o3dUeM@z> > Date: Fri, 11 Jun 1999 04:06:15 -0500 (EST) > From: Alfred Perlstein > 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?