[cpp-threads] Memory model counterproposal: bit-fields

Boehm, Hans hans.boehm at hp.com
Fri May 27 23:27:24 BST 2005


Agreed.  But it's one more thing to learn.

Evidence of a significant performance impact on code that we care
about would go a long ways towards convincing me.  Does someone
have a pointer to some important code with misaligned bit-fields for
which it might matter?  I've seen bit-fields used mostly to break
up a particular byte or word into smaller pieces, or in structures
consisting of only bit-fields which model device registers.  In both
cases, the stricter rules have no performance impact at all, since
the enclosing addressable unit consists entirely of bit-fields.

Hans 

> -----Original Message-----
> From: 
> Cpp-threads_decadentplace.org.uk-bounces at decadentplace.org.uk 
> [mailto:Cpp-threads_decadentplace.org.uk-bounces at decadentplace
> .org.uk] On Behalf Of Peter Dimov
> Sent: Friday, May 27, 2005 3:00 AM
> To: cpp-threads at decadentplace.org.uk
> Subject: Re: [cpp-threads] Memory model counterproposal: bit-fields
> 
> 
> Boehm, Hans wrote:
> > As far as the programming model is concerned, I think I could live 
> > with Peter's formulation, so long as it's clear that it 
> doesn't apply 
> > to bit-fields of nested structs.  The statement is certainly simple 
> > enough.  But it still seems to me that it allows significantly more 
> > surprising behavior, for relatively minimal gain.
> >
> > For example, if I have an interface that uses an
> > opaque (to the client) struct r to hold a request and its result, 
> > where
> >
> > make_request(r&)
> >
> > makes the request, and
> >
> > get_result(r&)
> >
> > retrieves the result, I can put an r in a struct with a bit 
> field only 
> > if there is no concurrency involved, even though one would really 
> > expect that to be transparent to the client.
> 
> I think that it might be acceptable. The idiom would be to always put 
> bitfields in their own nested struct.
> 
> struct X
> {
>     R r;
> 
>     struct Bf
>     {
>         int v: 30;
>         int w: 2;
>     } bf;
> };
> 
> or something like that.
> 
> 
> -- 
> cpp-threads mailing list
> cpp-threads at decadentplace.org.uk 
> http://decadentplace.org.uk/mailman/listinfo/cpp-threads_decad
entplace.org.uk




More information about the cpp-threads mailing list