This is the mail archive of the gcc-help@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]
Other format: [Raw text]

optimizer question


				Hi,

   When confronted with the following code:

void main()
{
	int x = 2;
	int y;

	y = rand();
	y = y / x;
	printf("%d.\n", y);
}

Why does gcc generate a division instead of a shift ? Is this a shortcoming of the optimizer or some feature of C I don't 
understand ? When I replace the 'x' in the division with '2', a shift is generated. I'm using gcc-3.2 -O3 on x86 linux.

				thanks

					Zoltan


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