[cpp-threads] pthreads (was: RE: C++ Connections proposal)
Hans Boehm
Hans.Boehm at hp.com
Wed Apr 27 05:58:25 BST 2005
That's a good point. We clearly need to address that. X86/Linux does the
same thing. I didn't try Windows. A tiny test program is attached.
I think we basically have two options, though:
1) Leave the rule as it is. In this case, that would force two
byte stores instead of a word load and store, which isn't obviously
a big deal.
2) Allow any fields to be overwritten in a struct when a bit field is
written. That assumes that this problem doesn't arise if I put the
field b in this example inside a separate nested struct. Empirically,
that assumption is correct on Itanium, but I didn't check elsewhere.
My intuition is that either of these are acceptable from the user's
perspective, though (1) is preferable. Bit-fields are generally not that
common. Anything that doesn't provide default isolation for structures
not containing bit-fields seems dubious, since I think it would require
updating of literally billions of lines of client code.
My meta-assumption is that we're not worrying a lot about the effort
needed to update compiler back-ends, at least not yet. It is clear that
this proposal wil require significant work for almost every optimizing
compiler, and that's unavoidable. (And it may be a net reduction in
future work, since it will hopefully avoid the steady stream of complaints
from kernel implementors in the future.)
Hans
On Tue, 26 Apr 2005, Nelson, Clark wrote:
> > My guess is that some compilers might currently perform
> > transformations
> > like this, but it would be easy to teach them to stop when we teach
> > them that only adjacent bit-fields can be spuriously rewritten.
> > And I believe we need to do that anyway.
>
> I'm sorry, but I'm afraid the adjacent bit-field rule isn't good enough.
> Consider a case like the following:
>
> struct X { char a; int b: 16; char c; };
>
> Reasonable ABIs can (and the Itanium ABI does) put a into byte 0, b into
> bytes 1 and 2, and c into byte 3, and to access b will use a 4-byte
> memory instruction, because a 2-byte access would be unaligned.
>
> --
> Clark Nelson Vice chair, J16 (ANSI C++ standard committee)
> Intel Corporation
> clark.nelson at intel.com
>
> --
> cpp-threads mailing list
> cpp-threads at decadentplace.org.uk
> http://decadentplace.org.uk/mailman/listinfo/cpp-threads_decadentplace.org.uk
>
-------------- next part --------------
#include <stdio.h>
#include <stddef.h>
struct X { char a; int b: 16; char c; } x;
int main()
{
printf("%lu %lu %lu %lu\n",
offsetof(struct X, a),
/* offsetof(struct X, b) */0,
offsetof(struct X, c),
sizeof(struct X));
__asm("# look here");
x.b = 42;
return 0;
}
More information about the cpp-threads
mailing list