delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/30/05:19:51

From: mharris AT blackwidow DOT saultc DOT on DOT ca
Date: Thu, 30 Jan 1997 05:06:14 -0500 (EST)
Reply-To: mharris AT blackwidow DOT saultc DOT on DOT ca
To: Benjamin D Chambers <chambersb AT juno DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: fixed point math: NEED HELP QUICK!
In-Reply-To: <19970128.181621.14527.2.chambersb@juno.com>
Message-ID: <Pine.LNX.3.95.970130050351.190C-100000@capslock.com>
Organization: Total disorganization.
MIME-Version: 1.0

On Tue, 28 Jan 1997, Benjamin D Chambers wrote:

> >> 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.

You cant be GUARANTEED that the code generated will be the shifted
version.  What if a different C compiler is used?  The only way to
ensure that you get the shifts is to code it that way.  It may look
obscure, but a comment will fix that up.

other_stuff = stuff >> 8; /*  stuff * 8  */


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

DJGPP: Current version 2.01

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019