H1 2015 Priorities and Bare-Metal Programming

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 3 01:35:53 PST 2015


On 2/3/2015 1:11 AM, Mike wrote:
> All things being equal, will there be any difference between the resulting
> binaries for each of these scenarios?

No.

> Another way of putting it:  Does pragma(inline, true) simply allow the user to
> compiler parts of their source file with -inline?

Yes.

pragma(inline, false) paradoxically can be used to improve performance. Consider:

   if (cond)
     foo();
   else
     bar();

If cond is nearly always false, then foo() is rarely executed. If the compiler 
inlines it, it will likely take away registers from being used to inline bar(), 
and bar() needs those registers. By marking foo() as not inlinable, it won't 
consume those registers. (Also, inlining foo() may consume much code, making for 
a less efficient jump around it and making it less likely for the hot code to 
fit in the cache.)

This is why I'm beginning to think a pragma(hot, true/false) might be a better 
approach, as there are more optimizations that can be done better if the 
compiler knows which branches are hot or not.


More information about the Digitalmars-d mailing list