Crossfire Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CF: Bitwise vs. integer operations
> Date: Thu, 23 Sep 1999 10:53:01 +0200 (MET DST)
> From: quinet@gamers.org (Raphael Quinet)
> 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.
I think we might be somehow talking about different things. When you
say "mask some parts of it to do bitwise operations", what bitwise
operations are you talking about? I thought masking some parts of it
*WAS* the bitwise operation in question. Optimizing for 32-bits at
the expense of 8 or 16-bit operations I can understand. What I'm
still not clear on is whether you're suggesting that the basic logic
operations of AND, OR, NAND, and XOR between two 32-bit integers are
slower than adding or subtracting the same two 32-bit integers.
> 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.
This makes sense. Good rule of thumb. Having done most of my
programming under severe memory constraints, my first impulse is
always to optimize for memory first and for speed only when it doesn't
cost memory. Memory has gotten a lot cheaper lately, or so I've
heard, so that's probably not a particularly good strategy any more.
I'll try to keep this rule in mind.
--
-Dave Noelle, dave@Straylight.org
-the Villa Straylight, http://www.straylight.org
Coalition Against Unsolicited Commercial Email == http://www.cauce.com
Disclaimer: SUNY Buffalo still won't officially admit to sharing my opinions.
Neither will U.C.L.A. Imagine that.
-
[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]