Crossfire Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CF: Bitwise vs. integer operations



On Wed, 22 Sep 1999, dragonm <dragonm@leech.org> wrote:
[quoting David Andrew Michael Noelle]
> > Plese tell me you're kidding.  I never would have suspected that that
> > was even possible.  My logic and processor design classes certainly
> > never suggested it.  Why would anyone go out of their way to make the
> > most inherently trivial operations slower than much more complex
> > operations?
> No joke.  Bitwise operations don't happen very often compared to integer
> operations, so if you go to extraordinary lengths to optimize integer
> operations, bitwise operations may suffer.  In point of fact, bitwise
> operations are more complex than integer operations.  When a processor's
> buses are optimized to transfer every bit in a word at once, transferring a
> partial word is actually more difficult.

I'll second that.  The modern processors are usually faster when they
can work on a full integer than when they have to mask some parts of
it to do bitwise operations.  Although it may seem strange, is is also
often faster to do some operations (e.g. addition) on an 'int' than on
a 'short'.  Again, this is because the processor has to mask some
parts of the registers when doing the operations.  Note that it was
not the case for the old 8-bits or 16-bits processors because they had
fast instructions for working on 1, 8 or 16 bits, but almost all
32-bits processors are slower when working with less than 32 bits.

So the conclusion is (I think this is even in some C FAQ): use 'int'
when you want to be fast, use 'short' or bit fields when you want to
save memory.

> [...] Does anybody even run Crossfire on MIPS machines?  :)
> 

Not anymore.  I usually test it on a SPARC (running Solaris), and on
an old Pentium (running Linux).

-Raphael

P.S.: I have been away from the list for a few days, and I now have
      180 unread messages from this list.  I will try to reply to some
      of them during the next days.

-
[you can put yourself on the announcement list only or unsubscribe altogether
by sending an email stating your wishes to crossfire-request@ifi.uio.no]