public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "m dot reszat at kostal dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/23623] volatile keyword changes bitfield access size from 32bit to 8bit
Date: Tue, 30 Aug 2005 07:59:00 -0000	[thread overview]
Message-ID: <20050830074308.19283.qmail@sourceware.org> (raw)
In-Reply-To: <20050829140226.23623.m.reszat@kostal.com>


------- Additional Comments From m dot reszat at kostal dot com  2005-08-30 07:43 -------
(In reply to comment #1)
> (In reply to comment #0)
> 
> > Access to bf1.b is correctly done as 32-bits (lwz/stw opcodes), bf2.b is
> > accessed as 8-bits (lbz/stb opcodes). GCC3.4.3 shows the same behaviour, can't
> > go back any further. The same happens when the bitfield itself is made volatile,
> > not the whole struct.
> 
> This is intentional. The idea is not to touch any more of that volatile stuff
> than absolutely needed. Why do you think it is a bug?

When dealing with peripherals in embedded systems, the use of bitfields makes
the code much more readable. 

Ex.: 3 bits of a peripheral register define a timer prescaler
It can be s.th. like 
#define PS_VAL_05 0x00140000
#define PS_MASK   0x001c0000
...
per_reg = (per_reg & ~PS_MASK) | PS_VAL_05;

But could be as simple as 
per_reg.ps = 5;, or even per_reg.ps = func(...); 
Try to set up the latter w/o bitfields and you end up
per_reg = (per_reg & ~PS_MASK) | (func(...) << PS_SHIFT);

Most (admittedly not all) modern peripherals allow the bitfield approach, but
correct access size is a must (misalignment traps, access triggered buffering
etc.). 
IMHO the compiler/code generator should always use the basic type when a
variable is declared as volatile, i.e. volatile unsigned int ps:3; should
enforce 32-bit-access, probably even for non-bitfields. All compilers for
embedded systems I know of act this way, so I assumed this was a bug.
In other cases, e.g. communicating between threads through memory, access size
is not an issue and even if so, could be enforced by appropriate declaration or,
god help me, typecasting as a last resort.
Unfortunately, C does not provide a qualifier for access size enforcement,
"volatile" seems to be the closest friend. The current implementation puts me
between a rock and a hard place, as the "core volatile functionality" is needed
as well.
What do you think?

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23623


  parent reply	other threads:[~2005-08-30  7:43 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-29 14:11 [Bug c/23623] New: " m dot reszat at kostal dot com
2005-08-29 15:39 ` [Bug middle-end/23623] " pinskia at gcc dot gnu dot org
2005-08-29 16:21 ` pinskia at gcc dot gnu dot org
2005-08-29 21:27 ` falk at debian dot org
2005-08-30  7:59 ` m dot reszat at kostal dot com [this message]
2005-08-30 12:44 ` falk at debian dot org
2005-08-30 12:51 ` rearnsha at gcc dot gnu dot org
2005-08-30 13:42 ` m dot reszat at kostal dot com
2005-08-30 14:06 ` rearnsha at gcc dot gnu dot org
2005-09-08 15:12 ` m dot reszat at kostal dot com
     [not found] <bug-23623-11259@http.gcc.gnu.org/bugzilla/>
2006-03-28 18:03 ` pbrook at gcc dot gnu dot org
2006-03-29 15:22 ` pbrook at gcc dot gnu dot org
2006-03-29 17:44 ` pbrook at gcc dot gnu dot org
2006-05-16 17:15 ` pinskia at gcc dot gnu dot org
2006-08-02 11:30 ` jason dot morgan at vpnsolutions dot uk dot com
2009-01-13 10:12 ` frikkie at zitera dot co dot za
2009-01-13 10:42 ` frikkie at zitera dot co dot za
2009-01-13 15:52 ` frikkie at zitera dot co dot za
     [not found] <bug-23623-4@http.gcc.gnu.org/bugzilla/>
2013-06-08 19:57 ` sandra at codesourcery dot com
2013-06-14  2:59 ` sandra at codesourcery dot com
2013-10-07 15:40 ` sandra at codesourcery dot com
2013-12-11 16:50 ` edlinger at gcc dot gnu.org
2013-12-11 16:59 ` edlinger at gcc dot gnu.org
2014-02-27  7:28 ` jye2 at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050830074308.19283.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).