[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dividing by a power of two



|> > I've noticed this too. The problem is that (x/16) is not equal to (x>>4)
|> > when `x' is negative, so gcc has to test for the sign of `x'. This
|> 
|> Not if gcc uses "asr" (arithmetic shift right). This takes care to copy the
|> sign bit to all bits shifted in from the left, so "asr #1, -16" gives -8.
|> 
|> The PureC compiler has this same oddity, it does well for x*16 and some such
|> but not for divisions by powers of two...

Well.

But have you tried it with a number which is *not* a multiple of two?
E.g. asr #1,-15 returns returns -8, while I remember that the
``equivalent'' divs #2,-15 returns -7. (To sad that I have no MC68000
here to really test it :-( )

Regards Wolfgang

----
Wolfgang Lux				#include <Standard Disclaimer>
WZH Heidelberg, IBM Germany             Internet: lux@heidelbg.ibm.com
+49-6221-59-4546			VNET:     LUX at HEIDELBG
+49-6221-59-3300 (fax)			EARN:     LUX at DHDIBMIP