[Bug c/43755] New: Bit shifting by a 8 byte variable isn't the same as bit shifting by an 8 or a 4 byte constant on 64bit platform.

2010-04-14 Thread mail dot alexhaase at gmail dot com
I found four constant unsigned long (64bit) values which do not agree with bit
shifting ~0 by an unsigned long variable holding the value 32 (demo attached):
1) shifting ~0 by 32
2) shifting ~0 by (unsigned long)32
3) shifting ~((unsigned long)0) by (unsigned long) 32
4) shifting ~((unsigned long)0) by 32

One and two are the same(0), and three and four are the
same(18446744069414584320). However, letting unsigned long a=32 and mask=~0<"
# 1 ""
# 1 "./test.c"
int main(void) {
  unsigned long mask;
  unsigned long lower_set_bit=32;
  unsigned long a;
  unsigned long b;
  unsigned long c;
  unsigned long d;

  a= ~0 <<(unsigned long)32;
  b= ~((unsigned long)0) << (unsigned long) 32;
  c= ~0 << 32;
  d= ~((unsigned long)0) <<32;

  do {
mask=(~(0) << lower_set_bit);
  } while(mask!=a && mask!=b && mask!=c && mask!=d);

  return 0;


-- 
   Summary: Bit shifting by a 8 byte variable isn't the same as bit
shifting by an 8 or a 4 byte constant on 64bit
platform.
   Product: gcc
   Version: 4.4.1
Status: UNCONFIRMED
  Severity: minor
  Priority: P3
 Component: c
    AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mail dot alexhaase at gmail dot com
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


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



[Bug c/43755] Bit shifting by a 8 byte variable isn't the same as bit shifting by an 8 or a 4 byte constant on 64bit platform.

2010-04-14 Thread mail dot alexhaase at gmail dot com


--- Comment #1 from mail dot alexhaase at gmail dot com  2010-04-15 03:16 
---
Created an attachment (id=20384)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20384&action=view)
Bug demo


-- 


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



[Bug c/43756] New: Bit shifitng by a constant 32 isn't the same as bitshifting by a variable 32.

2010-04-14 Thread mail dot alexhaase at gmail dot com
I ran my demo code from bug id #43755 on a 32bit host for fun. All the casting
i could dream up for the value of ~0 << 32 resulted in a value of 0 when using
constants. However when using a variable to upshift by 32, I get the result ~0
(4294967295). I'm stumped.


-- 
   Summary: Bit shifitng by a constant 32 isn't the same as
bitshifting by a variable 32.
   Product: gcc
   Version: 4.4.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mail dot alexhaase at gmail dot com
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


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



[Bug c/43756] Bit shifitng by a constant 32 isn't the same as bitshifting by a variable 32.

2010-04-14 Thread mail dot alexhaase at gmail dot com


--- Comment #1 from mail dot alexhaase at gmail dot com  2010-04-15 03:32 
---
Created an attachment (id=20385)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20385&action=view)
a demo of this bug


-- 


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



[Bug c/43755] Bit shifting by a 8 byte variable isn't the same as bit shifting by an 8 or a 4 byte constant on 64bit platform.

2010-04-14 Thread mail dot alexhaase at gmail dot com


--- Comment #2 from mail dot alexhaase at gmail dot com  2010-04-15 03:33 
---
I tested on 32bits and found slightly less confusing, though still confusing
results. Bug id #43756


-- 


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