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: gomp slowness


On Fri, 2007-11-02 at 13:47 -0600, Joel Dice wrote:

> > So any (application) program needing TLS (other than the stack)
> > is automatically badly designed.  I've been writing code for
> > three decades without using any global variables, ever since
> > I learned about re-entrancy.
> 
> While I agree that global and thread-local variables are to be avoided in 
> general, I wonder how you would treat the following case:

> Function A needs to supply some data to function Z, but only via a call 
> stack containing functions B through Y.  Must B through Y all take that 
> data as a parameter and pass it as an argument? 

Yes. Felix does precisely this.
Note the ABI will often pass it in a register,
and the variable is not used in functions B-Y .. 
so gcc+ABI will probably optimise away the explicit pointer 
passing anyhow, in effect leaving exactly the 'store it
in an unused register' anyhow.

Felix trusts the gcc to handle this reasonably
well and it does seem to do so in most cases.

>  Would it not be more 
> efficient to store it in a register on a register-rich machine instead of 
> copying in on every call?

No: 'As-if' rule. Copying is efficient because it can be optimised
away. You write your C code with explicit passing and complain
right here in this list if gcc doesn't optimise it efficiently :)

> Even putting runtime efficiency aside, the code in the intermediate 
> functions is made arguably less readable by each bit of context it has to 
> forward along but never use itself.  

No, it's the other way around. When you use global variables to 
store state, you cannot easily reason about your code because
the coupling is not represented in the function argument-parameter
bindings explicitly.

> OTOH, using thread-locals introduces 
> "action at a distance", which never helps readability.

Yes.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


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