This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PATCH m68k fix for long long shift by 16


Joseph S. Myers wrote:
> 
> On Sat, 9 Jun 2001, Peter Jakubek wrote:
> 
> > I just came across a problem with right shift of long long by 16.
> > This patch should fix it.
> >
> > 2001-06-09  Peter Jakubek <pjak@snafu.de>
> >
> >       * config/m68k/m68k.md (ashrdi_const): Fix right shift by 16.
> 
> On what platform did you test this?
> 
> Is the testcase this fixes already in the GCC testsuite?  If not, can you
> supply one?
> 
> --
> Joseph S. Myers
> jsm28@cam.ac.uk

I tested this on 68010 and 68040. 

The following code demonstrates the problem:

long long Asr16 (long long v) {return v >> 16;}

int main ()
{
  long long v = Asr16 (0x12345678abcdef12LL);
  printf ("Value %x:%x", int (v >> 32), int (v));
  return 0;
}

The output should be "Value 1234:5678abcd", but it isn't.
The high word is always 0.

I think the patch is pretty obvious. Without my patch gcc
generates code similar to:

  move.w %d0,%d1
  clr.w  %d0     | clear bit 15-0 of %d0
  swap   %d1
  ext.l  %d0     | sign extend bit 15-0 of %d0, result is zero

This always clears d0 (the high long word).

With my patch the generated code looks like this:

  move.w %d0,%d1
  swap   %d0
  ext.l  %d0
  swap   %d1

Unfortunately I don't have the testsuite environment
working. So I can't provide a test case. But anyone
that is familiar with the motorola 68k series will
hopefully agree that the patch does not break things.

-- 
Peter Jakubek
pjak@snafu.de


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]