Author: Bruce Moreland
Date: 09:55:23 12/03/00
Go up one level in this thread
On December 03, 2000 at 10:40:03, David Rasmussen wrote:
>Most freely available sourcecode I've seen, implements hashtables in the manner
>of Crafty. That is, the a hashed record is a struct with some integers, which
>are treated at bit level to manage the necesary information. I do that too. But
>why aren't people just using the bitfield ability of C to do this?
>
>I mean
>
>struct HashRecord {
> int draft:6;
> int threat:1;
> etc.
>};
>
>Is this always slower? It should be pretty easy for a compiler to do exactly
>what, say, Crafty, is doing when reading and writing to such a structure.
These are fine. There are a few possible problems. You have a little
imprecision when you try to manage them (you don't know exactly what is
happening), and there is some conversion when you assign values to these.
For example, if you have a boolean *variable* containing TRUE or FALSE, and you
assign it to some random bit in one of these bitfields, the compiler will
generate a shift instruction and OR it into the right place. If you use an
integer and OR in a variable that already contains the shifted value, you save
the shift instruction.
Another example:
typedef union tagX {
struct {
unsigned a:2;
unsigned b:4;
unsigned c:2;
};
unsigned d;
} X;
X.b++ and X.d += 4 should do essentially the same thing, but there is a major
difference. The difference is that X.b++ can't destroy one of the other fields,
because if the thing overflows 4 bits, it's not allowed to carry.
If you know that X.b has to lie in the range 0..9, meaning that a carry is
impossible, the compiler generates a huge number of instructions (8, in the case
of my compiler), to do what it could have done in many fewer (1, in my case).
Because the compiler has to account for the case where X.b is 15, and there's no
way to tell it that X.b will never be 15, it generates a huge amount of code.
bruce
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.