This is the mail archive of the gcc-bugs@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]

Right-shift bug in egcs-2.91.66


This code is intended to print out either a 32-bit value or a 64-bit value.
The code is common between Linux and Windows.  On Linux, physical addresses are
32-bit, but on Windows they're 64-bit.

    u32 test = 0x12345678;
    printk("0x%08lx%08lx\n", (u32)(test >> 32), (u32)test );

The result is supposed to be 

	0x0000000012345678

instead, printk outputs:

	0x1234567812345678

The resulting assembly code is:

	movl $305419896,%ebx
	pushl %ebx
	pushl %ebx
	pushl $.LC4
	call printk

As you can see, gcc thinks that "test >> 32" is the same thing as "test".  I'm
not sure if it "optimizes out" the right-shift because right-shifting a 32-bit
value by 32 bits always results in zero, or if it's confusing a shift with a
rotate.


-- 
Timur Tabi - ttabi@interactivesi.com
Interactive Silicon - http://www.interactivesi.com


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