From: mharris AT blackwidow DOT saultc DOT on DOT ca Date: Fri, 31 Jan 1997 16:52:03 -0500 (EST) Reply-To: mharris AT blackwidow DOT saultc DOT on DOT ca To: Benjamin D Chambers 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: Organization: Total disorganization. MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Tue, 28 Jan 1997, Benjamin D Chambers wrote: > > On Tue, 28 Jan 1997 20:30:34 -0500 DJ Delorie 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