public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: ftu@fi.uu.nl
To: gcc-gnats@gcc.gnu.org
Subject: target/7533: gcc 3.0.2 h8300 right shift 15 is wrong
Date: Wed, 07 Aug 2002 17:26:00 -0000	[thread overview]
Message-ID: <20020807232805.21542.qmail@sources.redhat.com> (raw)


>Number:         7533
>Category:       target
>Synopsis:       gcc 3.0.2 h8300 right shift 15 is wrong
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Wed Aug 07 16:36:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     dick wesseling
>Release:        3.0.2
>Organization:
>Environment:
h8300 cross compiler
>Description:
The h8300 backend attempts to decompose unsigned >>15 into:

 1) a single half register left shift, which moves 1 bit into the carry
    register,

 2) followed by half register MOV and XOR which has the effect of >>16

 3) followed by a single bit full register left rotate which combines
    the carry and the register.


The bug is that step 1) uses the wrong register half.

consider the following code:

unsigned long s15(unsigned long in)  {
        return in>>15;
}

if the input parameter is EeeeeeeeeeeeeeeeRxxxxxxxxxxxxxxx 
then the following happens:

;       GCC For the Hitachi H8/300
;       By Hitachi America Ltd and Cygnus Support
; -O2

        .h8300s
        .file   "h8300-shift-bug.c"
        .section .text
        .align 1
        .global _s15
_s15:                       Carry  e0              r0
        push.l  er6
        mov.l   er7,er6         -  EeeeeeeeeeeeeeeeRxxxxxxxxxxxxxxx
> >      shll.w  e0              E  eeeeeeeeeeeeeee0Rxxxxxxxxxxxxxxx
        mov.w   e0,r0           E  eeeeeeeeeeeeeee0eeeeeeeeeeeeeee0
        xor.w   e0,e0           E  0000000000000000eeeeeeeeeeeeeee0
        rotxl.l er0             0  0000000000000000eeeeeeeeeeeeeeeE
        pop.l   er6
        rts
        .end
        .ident
"GCC: (GNU) 3.0.2"

The intended code was:

        push.l  er6         Carry  e0              r0
        mov.l   er7,er6         -  EeeeeeeeeeeeeeeeRrrrrrrrrrrrrrrr
> >      shll.w  r0              R  Eeeeeeeeeeeeeeeerrrrrrrrrrrrrrr0
        mov.w   e0,r0           R  EeeeeeeeeeeeeeeeEeeeeeeeeeeeeeee
        xor.w   e0,e0           R  0000000000000000Eeeeeeeeeeeeeeee
        rotxl.l er0             -  000000000000000EeeeeeeeeeeeeeeeR
        
>How-To-Repeat:
compile this function:
unsigned long s15(unsigned long in)  {
        return in>>15;
}
>Fix:
*** gcc-3.0.2/gcc/config/h8300/h8300.c.orig     Wed Nov 21 18:09:08 2001
--- gcc-3.0.2/gcc/config/h8300/h8300.c  Thu Aug  8 00:55:36 2002
***************
*** 2477,2487 ****
            {
            case SHIFT_ASHIFT:
              info->special = "shlr.w\t%e0\n\tmov.w\t%f0,%e0\n\txor.w\t%f0,%f0\n\trotxr.l\t%S0";
              goto end;
            case SHIFT_LSHIFTRT:
!             info->special = "shll.w\t%e0\n\tmov.w\t%e0,%f0\n\txor.w\t%e0,%e0\n\trotxl.l\t%S0";
              goto end;
            }
        }
        else if ((TARGET_H8300 && count == 16)
               || (TARGET_H8300H && 16 <= count && count <= 19)
--- 2477,2487 ----
            {
            case SHIFT_ASHIFT:
              info->special = "shlr.w\t%e0\n\tmov.w\t%f0,%e0\n\txor.w\t%f0,%f0\n\trotxr.l\t%S0";
              goto end;
            case SHIFT_LSHIFTRT:
!             info->special = "shll.w\t%r0\n\tmov.w\t%e0,%f0\n\txor.w\t%e0,%e0\n\trotxl.l\t%S0";
              goto end;
            }
        }
        else if ((TARGET_H8300 && count == 16)
               || (TARGET_H8300H && 16 <= count && count <= 19)
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2002-08-07 23:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-07 17:26 ftu [this message]
2002-08-07 20:16 Dick Wesseling
2002-11-07  5:58 kazu

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=20020807232805.21542.qmail@sources.redhat.com \
    --to=ftu@fi.uu.nl \
    --cc=gcc-gnats@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).