public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Bitfields
@ 2009-09-20 13:01 Zoltán Kócsi
  2009-09-20 14:01 ` Bitfields Paolo Bonzini
  2009-09-20 21:00 ` Bitfields Joseph S. Myers
  0 siblings, 2 replies; 6+ messages in thread
From: Zoltán Kócsi @ 2009-09-20 13:01 UTC (permalink / raw)
  To: gcc

I wonder if there would be at least a theoretical support by the
developers to a proposal for volatile bitfields:

When a HW register (thus most likely declared as volatile) is defined as
a bitfield, as far as I know gcc treats each bitfield assignment as a
separate read-modify-write operation. Thats is, if I have a 32-bit
register with 3 fields

struct s_hw_reg {

 int field1 : 10,
     field2 : 10,
     field3 : 12;

};

then

reg.field1 = val1;
reg.field2 = val2;

will be turned into a fetch, mask, or with val1, store, fetch, mask, or
with val2, store sequence. I wonder if there could be a special gcc
extension, strictly only when a -f option is explicitely passed to the
compiler, where the comma operator could be used to tell the compiler
to concatenate the operations:

reg.field1 = val1, reg.field2 = val2;

would then turn into fetch, mask with a combined mask of field1 and
field2, or val1, or val2, store.

Since the bit field operations can not be concatenated that way
currently, and quite frequently you want to change multiple fields in a
HW register simultaneously (i.e. with a single write), more often
than not you have to give up the whole bit field notion and define
everything like

#define MASK1 0xffc00000
#define MASK2 0x003ff000
#define MASK3 0x00000fff

and so on, then you explicitely write the code that fetches, masks
with a compined mas, or-s with a combined field value set and stores. A
lot of typing could be avoided with the bitfields, not to mention that
it would be a lot more elegant, if one could somehow coerce the compiler
to be a bit more relaxed regarding to bitfield access. Actually
'relaxed' is not a good word, because I would not want the compiler to
have a free reign in the access: if there's a semicolon at the end of
the assignment operator expression, then do it bit by bit, adhering
the standard to its strictest. However, the comma operator, and only
that operator, and only if both sides of the comma refer to bit fields
within the same word, and only if explicitely asked by a command line
switch, would tell the compiler to combine the masking and setting
operations within a single fetch - store pair.

Is it a completely brain-dead idea?

Zoltan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-09-21 16:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-20 13:01 Bitfields Zoltán Kócsi
2009-09-20 14:01 ` Bitfields Paolo Bonzini
2009-09-20 14:07   ` Bitfields Robert Dewar
2009-09-20 21:00 ` Bitfields Joseph S. Myers
2009-09-21  4:18   ` Bitfields zoltan
2009-09-21 16:40   ` Bitfields DJ Delorie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).