Mail Archives: djgpp/1997/01/31/22:06:42
On Tue, 28 Jan 1997, Benjamin D Chambers wrote:
>
> On Tue, 28 Jan 1997 20:30:34 -0500 DJ Delorie <dj AT delorie DOT com> writes:
> >
> >> function. Anyway, here's my problem; To my understanding the
> >following
> >> are 100% equal:
> >>
> >> other_stuff = stuff / 256;
> >> other_stuff = stuff << 8;
> >
> >The second multiplies. Try ">> 8" instead.
> >
> >
> Also, just to be clear, the first gets translated into the second when
> compiling with optimizations on (-O2).
> In fact, I believe *ALL* integer multiplication/division by a constant
> gets converted to shifts when using -O2, so you might as well use the
> first - if for nothing else then for readability's sake.
If *ALL* integer mults/divs are converted to shifts, then what would
be the equivalent for:
other_stuff = stuff * 57
other_stuff = stuff << ???
The point I'm trying to make is that no, only mul/div's by powers of 2
would be converted to shifts. Others such as multiplying by numbers
whose factors are of powers of 2 can also be optimized in this way.
Numbers that don't fit (such as 57) can't be implemented via shifting
and be optimal.
Mike A. Harris | http://blackwidow.saultc.on.ca/~mharris
Computer Consultant | My webpage has moved and my address has changed.
My dynamic address: http://blackwidow.saultc.on.ca/~mharris/ip-address.html
mailto:mharris AT blackwidow DOT saultc DOT on DOT ca
4DOS can be downloaded from ftp://ftp.std.com/vendors/jpsoft
- Raw text -