[Bug c/66077] New: Right shift calculation error

2015-05-08 Thread mike.jost at hp dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66077

Bug ID: 66077
   Summary: Right shift calculation error
   Product: gcc
   Version: 4.4.7
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: mike.jost at hp dot com
  Target Milestone: ---

Curious right shift calculation error. I have used this sequence many times in
de Bruijn sequence calc to count trailing zeros. simplified to basic steps. Not
sure if this is a linux VM issue or compiler issue.

This same code works
using Quincy 2205 v1.3 05-Feb-2008
MinGW GCC version 4.2.1 on windows platform

fails with.
version:
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enax
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) 


Linux VM
$ uname -a
Linux hpnsw019.rose.hp.com 2.6.32-504.12.2.el6.centos.plus.x86_64 #1 SMP Thu
Mar 12 18:39:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


#include 

int main(int argc, char **argv)
{
   unsigned long w  = 64UL;
   unsigned long x  = 0xF12B3740UL;
   unsigned long y  = 0UL;
   unsigned long z  = 0UL;
   unsigned long a  = 0UL;


   y = (w * 0x07C4ACDDUL); /* = 0xF12B3740UL */
   z = y >> 27UL;
   a = x >> 27UL;

   printf("w = %lu\n",w);
   printf("x = 0x%X\n", x);
   printf("y = 0x%X\n", y);
   printf("z = %lu\n", z);
   printf("a = %lu\n", a);
}

output:
w = 64
x = 0xF12B3740
y = 0xF12B3740
z = 62
a = 30


z and a should be the same (30).


[Bug c/66077] Right shift calculation error

2015-05-08 Thread mike.jost at hp dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66077

--- Comment #2 from Mike Jost  ---
Thanks for the explanation! Bit by the 64 bit. That will teach me to use
uint32_t instead of assuming 32 for unsigned long. I've been running on 32 bit
embedded targets for too long!


Regards,
Michael Jost
mike.j...@hp.com
Software Engineer
Object Technology Solutions, Inc. (OTSI) contractor
HP Roseville - R3U Q8
(916) 785-2815



-Original Message-
From: pinskia at gcc dot gnu.org [mailto:gcc-bugzi...@gcc.gnu.org] 
Sent: Friday, May 08, 2015 11:40 AM
To: Jost, Mike (OTSI Contractor)
Subject: [Bug c/66077] Right shift calculation error

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

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #1 from Andrew Pinski  --- Your X and Y
are not correctly displaying.

The correct values are:
x = 0xF12B3740
y = 0x1F12B3740


You should be using %lX rather than %X to display unsigned long.

Like:
   printf("x = 0x%lX\n", x);
   printf("y = 0x%lX\n", y);

As you can see there is another bit set in the upper 32bits which causes the
difference.

--
You are receiving this mail because:
You reported the bug.