On Fri, 3 Aug 2001, Hartmut Schirmer wrote:
On Sun, 4 Mar 2001, Mariano Alvarez Fernandez wrote:
Nevertheless the real bug is that: 1L << 32 == 1 !!!!!! This is what breaks bccbgi (and even modetest) in 32 bpp mode.
Yes, strange. Andris, is this a compiler bug or just undefined behaviour ?
If we are treating it as bug, it's an Intel bug. At least on both CPU's I tested this with (Pentium MMX and Pentium III) after following instructions mov $1, %eax movb foo, %cl shl %cl, %eax I'm getting 1 << (foo % 32) in %eax. I looked in old reference of M$ Macro assembler (year 1991, it happened I have it near me) and I saw that this behaviour is documented to be present for all CPUs after 808[68]
What C standard is requesting to be result off foo<<bar if bar is bigger than number of bits in foo?
compiling the following source using gcc -O3 -fomit-grame-pointer (gcc2.7.2.3)
extern int si; extern unsigned ui; extern long li; extern unsigned long ul;
void foo(void) { si <<= 32; ui <<= 32; li <<= 32; ul <<= 32; }
void foo2(void) { si = 1; si <<= 32; ui = 1; ui <<= 32; li = 1; li <<= 32; ul = 1; ul <<= 32; }
I would have expected the foo() in both cases. It shouldn´t make any difference if ´ui´ unknown or known to be 1 ... Can yhou please check other GCC versions. I would expect gcc 3.0 to behave at least consistent here.
Below are results I got with gcc-3.0 20010301 (prerelease) configured for i686-pc-linux-gnu
Andris
Reading specs from /disk2/gcctest/lib/gcc-lib/i686-pc-linux-gnu/3.0/specs Configured with: ../gcc/configure --prefix=/disk2/gcctest --enable-shared --verbose --enable-threads=posix : (reconfigured) gcc version 3.0 20010301 (prerelease) /disk2/gcctest/lib/gcc-lib/i686-pc-linux-gnu/3.0/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ shift2.cc -D__GNUG__=3 -D_GNU_SOURCE -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase shift2.cc -O2 -version -o /tmp/cc9iIywe.s GNU CPP version 3.0 20010301 (prerelease) (cpplib) (i386 Linux/ELF) GNU CPP version 3.0 20010301 (prerelease) (cpplib) (i386 Linux/ELF) GNU C++ version 3.0 20010301 (prerelease) (i686-pc-linux-gnu) compiled by GNU C version 3.0 20010301 (prerelease). #include "..." search starts here: #include <...> search starts here: /usr/lib/qt/include . /disk2/gcctest/include/g++-v3 /disk2/gcctest/include/g++-v3/i686-pc-linux-gnu /usr/local/include /disk2/gcctest/lib/gcc-lib/i686-pc-linux-gnu/3.0/include /disk2/gcctest/i686-pc-linux-gnu/include /usr/include End of search list. shift2.cc: In function `void foo()': shift2.cc:8: warning: left shift count >= width of type shift2.cc:9: warning: left shift count >= width of type shift2.cc:10: warning: left shift count >= width of type shift2.cc:11: warning: left shift count >= width of type shift2.cc: In function `void foo2()': shift2.cc:16: warning: left shift count >= width of type shift2.cc:17: warning: left shift count >= width of type shift2.cc:18: warning: left shift count >= width of type shift2.cc:19: warning: left shift count >= width of type as -V -Qy -a -o shift2.o /tmp/cc9iIywe.s GNU assembler version 2.10.91 (i386-slackware-linux) using BFD version 2.10.1.0.4 GAS LISTING /tmp/cc9iIywe.s page 1
1 .file "shift2.cc" 2 .version "01.01" 3 gcc2_compiled.: 4 .text 5 .align 16 6 .globl _Z3foov 7 .type _Z3foov,@function 8 _Z3foov: 9 .LFB1: 10 0000 55 pushl %ebp 11 .LCFI0: 12 0001 31C0 xorl %eax, %eax 13 0003 31C9 xorl %ecx, %ecx 14 0005 A3000000 movl %eax, si 14 00 15 000a 31D2 xorl %edx, %edx 16 000c 89E5 movl %esp, %ebp 17 .LCFI1: 18 000e 890D0000 movl %ecx, ui 18 0000 19 0014 31C0 xorl %eax, %eax 20 0016 89150000 movl %edx, li 20 0000 21 001c A3000000 movl %eax, ul 21 00 22 0021 5D popl %ebp 23 0022 C3 ret 24 .LFE1: 25 .Lfe1: 26 .size _Z3foov,.Lfe1-_Z3foov 27 0023 8DB60000 .align 16 27 00008DBC 27 27000000 27 00 28 .globl _Z4foo2v 29 .type _Z4foo2v,@function 30 _Z4foo2v: 31 .LFB2: 32 0030 55 pushl %ebp 33 .LCFI2: 34 0031 BA010000 movl $1, %edx 34 00 35 0036 B8010000 movl $1, %eax 35 00 36 003b 89150000 movl %edx, si 36 0000 37 0041 B9010000 movl $1, %ecx 37 00 38 0046 89E5 movl %esp, %ebp 39 .LCFI3: 40 0048 A3000000 movl %eax, ui 40 00 41 004d 890D0000 movl %ecx, li 41 0000 42 0053 89150000 movl %edx, ul 42 0000 43 0059 5D popl %ebp GAS LISTING /tmp/cc9iIywe.s page 2
44 005a C3 ret 45 .LFE2: 46 .Lfe2: 47 .size _Z4foo2v,.Lfe2-_Z4foo2v 48 .ident "GCC: (GNU) 3.0 20010301 (prerelease)" GAS LISTING /tmp/cc9iIywe.s page 3
DEFINED SYMBOLS *ABS*:0000000000000000 shift2.cc /tmp/cc9iIywe.s:3 .text:0000000000000000 gcc2_compiled. /tmp/cc9iIywe.s:8 .text:0000000000000000 _Z3foov /tmp/cc9iIywe.s:30 .text:0000000000000030 _Z4foo2v
UNDEFINED SYMBOLS si ui li ul