Right shift vs. divide

Frank Adams franka at mmintl.UUCP
Fri Dec 27 15:50:26 AEST 1985

In article <974 at brl-tgr.ARPA> Schauble at mit-multics.arpa (Paul Schauble) writes:
>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.

And you were doing so well up to this point! :-)  Of course a C compiler
can make this optimization, because the variables may be declared unsigned.

By the way, the FORTRAN compiler for the DEC-10 would process an integer
divide by two by checking the sign, incrementing if negative, and then
doing a right shift.  Since the divide took special setup (the single vs
double length operands problem), this didn't necessarily even take more
space than a divide instruction.

Frank Adams                           ihpn4!philabs!pwa-b!mmintl!franka
Multimate International    52 Oakland Ave North    E. Hartford, CT 06108

More information about the Comp.lang.c mailing list