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

Kay.
--
Kay Roemer              roemer@informatik.uni-frankfurt.de
"If I ever meet ..."    http://www.uni-frankfurt.de/~roemer/
"... myself I'll hit myself so hard I won't know who hit me" (Zaphod)