public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "olegendo at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/52394] SH Target: SH2A defunct bitops
Date: Sun, 20 Sep 2015 03:37:00 -0000	[thread overview]
Message-ID: <bug-52394-4-TqHWoyh8ma@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-52394-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52394

--- Comment #2 from Oleg Endo <olegendo at gcc dot gnu.org> ---
The SH2A bitops seem to produce some of the insns, but it seems the generated
code is either really bad (defeating the original purpose) or broken.

For example:


volatile struct
{
  union
  {
    unsigned char BYTE;
    struct
    {
      unsigned char BIT7:1;
      unsigned char BIT6:1;
      unsigned char BIT5:1;
      unsigned char BIT4:1;
      unsigned char BIT3:1;
      unsigned char BIT2:1;
      unsigned char BIT1:1;
      unsigned char BIT0:1;
    }
    BIT;
  }
  ICR0;
}
USRSTR;

int
main (unsigned char a, unsigned char b, unsigned char c)
{
  USRSTR.ICR0.BIT.BIT5 |= b & 1;
  return 0;
}

compiled with -m2a -mb -mbitops -O2:
        mov.l   .L2,r2        // addr of USRSTR

        mov     #1,r1
        and     r1,r5         // b & 1

        mov     #0,r0
        bor.b   #5,@(0,r2)    // T |= (bit in mem)

        movt    r7            // r7 = T
        mov.b   @r2,r3        // load byte
        cmp/pl  r7            // T = r7
        mov     #5,r7
        movt    r1            // r1 = T
        bclr    #5,r3         // clear bit 5 of loaded byte
        shld    r7,r1         // T << 5
        or      r3,r1         // OR bit
        mov.b   r1,@r2        // write back
        rts/n

It seems that this will produce funny results at the first bor.b insn because
at function entry the T bit is undefined.

The code should actually be something like this:
        mov.l   .L2,r2
        bld     #0,r5
        mov     #0,r0
        bor.b   #5,@(0,r2)
        bst.b   #5,@(0,r2)


  parent reply	other threads:[~2015-09-20  3:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-27  2:51 [Bug target/52394] New: " olegendo at gcc dot gnu.org
2012-02-28  0:49 ` [Bug target/52394] " kkojima at gcc dot gnu.org
2015-09-20  3:37 ` olegendo at gcc dot gnu.org [this message]
2015-09-20 10:01 ` olegendo 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=bug-52394-4-TqHWoyh8ma@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).