public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gandalf at winds dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/42898]  New: Problem initializing volatile structures
Date: Fri, 29 Jan 2010 19:27:00 -0000	[thread overview]
Message-ID: <bug-42898-1386@http.gcc.gnu.org/bugzilla/> (raw)

I've recently upgraded to GCC 4.3.2 from 4.2.2, and I noticed a strange
change in how volatile bitmask structures are optimized.

Consider the following code (compiled using just the -O3 option):


/* 32-bit MMIO */
struct hardware {
  int parm1:8;
  int :4;
  int parm2:4;
  int parm3:15;
  int parm4:1;
};

void f1()
{
  volatile struct hardware *ptr=(void *)0x11223344;

  *ptr=(struct hardware) {
    .parm1=42,
    .parm2=13,
    .parm3=11850,
    .parm4=1,
  };
}

void f2()
{
  volatile struct hardware *ptr=(void *)0x11223344;

  struct hardware set={
    .parm1=42,
    .parm2=13,
    .parm3=11850,
    .parm4=1,
  };

  *ptr=set;
}


In GCC 4.3.2, this produces the following assembly:

f1:
        movl    $0, 287454020
        movb    $42, 287454020
        movl    287454020, %eax
        andb    $15, %ah
        orb     $208, %ah
        movl    %eax, 287454020
        movl    287454020, %eax
        andl    $-2147418113, %eax
        orl     $776601600, %eax
        movl    %eax, 287454020
        movl    287454020, %eax
        orl     $-2147483648, %eax
        movl    %eax, 287454020
        ret

f2:
        movl    $-1370828758, 287454020
        ret

Aren't both functions syntactically the same, and shouldn't they produce the
same optimized code as in "f2" above? This used to be the case in GCC 4.2.2.

The problem I'm seeing, apart from the lack of optimization, is that "f1"
causes 5 separate writes to a single MMIO register, instead of 1. This
particular hardware register is only expecting one write to this location, and
when multiple writes are received it causes the hardware to fail.

If this new behavior is intended, is there some sort of attribute I can add to
the code to get the original 4.2.2 behavior back?

Thanks,
 -Byron


-- 
           Summary: Problem initializing volatile structures
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gandalf at winds dot org
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


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


             reply	other threads:[~2010-01-29 19:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-29 19:27 gandalf at winds dot org [this message]
2010-01-29 19:38 ` [Bug c/42898] [4.3/4.4/4.5 Regression] volatile structures and compound literals pinskia at gcc dot gnu dot org
2010-01-29 22:42 ` [Bug middle-end/42898] [4.3/4.4/4.5 Regression] volatile structures and compound literal initializers rguenth at gcc dot gnu dot org
2010-01-29 22:42 ` rguenth at gcc dot gnu dot org
2010-01-29 22:42 ` rguenth at gcc dot gnu dot org
2010-01-30 18:09 ` rguenth at gcc dot gnu dot org
2010-01-30 18:17 ` rguenth at gcc dot gnu dot org
2010-01-30 20:56 ` gandalf at winds dot org
2010-01-30 21:25 ` rguenther at suse dot de
2010-01-31 17:02 ` rguenth at gcc dot gnu dot org
2010-01-31 17:04 ` rguenth at gcc dot gnu dot org
2010-01-31 17:07 ` rguenth at gcc dot gnu dot org
2010-01-31 17:09 ` [Bug middle-end/42898] [4.5 " rguenth at gcc dot gnu dot org
2010-01-31 20:01 ` ebotcazou at gcc dot gnu dot org
2010-01-31 21:06 ` ebotcazou at gcc dot gnu dot org
2010-01-31 21:08 ` ebotcazou at gcc dot gnu dot org
2010-02-01  1:47 ` howarth at nitro dot med dot uc dot edu
2010-02-01  1:51 ` howarth at nitro dot med dot uc dot edu
2010-02-01  1:54 ` howarth at nitro dot med dot uc dot edu
2010-02-01  3:13 ` matz at gcc dot gnu dot org
2010-02-02 13:31 ` rguenth at gcc dot gnu dot org
2010-02-05 14:40 ` jamborm at gcc dot gnu dot org
2010-02-08 13:24 ` jamborm at gcc dot gnu dot org
2010-02-08 13:32 ` jamborm at gcc dot gnu dot org
2010-02-08 22:36 ` pinskia at gcc dot gnu dot 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=bug-42898-1386@http.gcc.gnu.org/bugzilla/ \
    --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).