Right shift vs. divide

Andrew Koenig ark at alice.UucP
Tue Dec 24 02:03:42 AEST 1985


> Anyone still think they're the same thing?  This optimization only works
> if the numbers are known to be non-negative. A Pascal compiler may make
> this optimization, becausethe programmer may specify the range for
> variables, but not C.

Moral: a C compiler can substitute a right shift for a divide by
a constant power of two if and only if the LHS of the expression
is an unsigned integer type.

By the way, a right shift of a signed quanitity is not required to
be an arithmetic shift.



More information about the Comp.lang.c mailing list