shift 32 bits on sparc

vesely@lucia.it vesely@lucia.it
Fri Mar 17 13:46:00 GMT 2000


When I shift by 32 bits I should get 0 as a result, shouldn't I?
I did the that, in order to translate a network mask
from <x.x.x.x/bits> format to binay, on a 32 bit sparc.
The following is a piece of a debugging session where I
realized that 0xffffffff << 32 results in -1.
Is this a known bug or am I missing something?
Ciao
Ale
gcc -v
Reading specs from
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/2.95.2/specs
gcc version 2.95.2 19991024 (release)
(gdb) disas 0x50c90 0x50ca8
Dump of assembler code from 0x50c90 to 0x50ca8:
0x50c90 <set_from_opt__7matchipPCc+240>:	mov 0x20, %o0	! 0x20
0x50c94 <set_from_opt__7matchipPCc+244>:	ld [ %l2 + 4 ], %o1
0x50c98 <set_from_opt__7matchipPCc+248>:	sub %o0, %o1, %o0
0x50c9c <set_from_opt__7matchipPCc+252>:	mov -1, %o1
0x50ca0 <set_from_opt__7matchipPCc+256>:	sll %o1, %o0, %o0
0x50ca4 <set_from_opt__7matchipPCc+260>:	st %o0, [ %l2 + 4 ]
End of assembler dump.
(gdb) info registers pc o0 o1
pc 0x50c98	330904
o0 0x20	32
o1 0x0	0
(gdb) stepi
0x50c9c	1237	mask = ULONG_MAX << (32 - mask);
(gdb) info registers pc o0 o1
pc 0x50c9c	330908
o0 0x20	32
o1 0x0	0
(gdb) stepi
0x50ca0	1237	mask = ULONG_MAX << (32 - mask);
(gdb) info registers pc o0 o1 l2
pc 0x50ca0	330912
o0 0x20	32
o1 0xffffffff	-1
l2 0xeffff170	-268439184
(gdb) print *(unsigned *)(0xeffff174)
$13 = 0
(gdb) stepi
0x50ca4	1237	mask = ULONG_MAX << (32 - mask);
(gdb) info registers pc o0 o1 l2
pc 0x50ca4	330916
o0 0xffffffff	-1
o1 0xffffffff	-1
l2 0xeffff170	-268439184


Sent via Deja.com http://www.deja.com/
Before you buy.


More information about the Gcc-bugs mailing list