Author: Dan Newman
Date: 03:39:50 10/24/00
Go up one level in this thread
On October 23, 2000 at 17:30:27, Bruce Moreland wrote:
>On October 23, 2000 at 12:29:27, Oliver Roese wrote:
>
>>On October 23, 2000 at 01:09:02, Landon Rabern wrote:
>>
>>>is it faster to cast to a char or to AND by 0xff, or to do they take the same
>>>number of clock cycles?
>>>
>>>Thanks,
>>>
>>>Landon W. Rabern
>>
>>Since "(unsigned char) u" and "u & 0xff" are equivalent expressions in C (or
>>arent they??) and nearly equivalent in other languages you surely cant tell
>>that, without looking on the assembler output of your compiler.
>>In C dont ever use char, there are implicitely converted to ints and that could
>>hurt. If the compiler can decide not to convert, slow 86-instructions must be
>>used. Hard to tell, what is slowest.
>>
>>Oliver
>
>I know that with the original pentium, in 32-bit mode, 32-bit and 8-bit
>operations were fine, but 16-bit operations were bad.
>
>I don't know if 8-bit operations are now bad, but if they are, it has been since
>sometime after the Pentium Pro.
>
>bruce
I think it's still about the same. The last time I checked (on a P3/500
Katmai) using 8-bit data types was almost as good as using 32-bit, but
16 bit'ers were significantly worse.
I tend to use 32-bit ints unless I have a large array of things that can
fit into 8 bit'ers--then I'll use an 8-bit element size to lower the cache
footprint and increase the amount of information per cache line. I couldn't
tell you at this point whether that is win or not... [ISTR the last time
I tried changing my board from char [64] to int [64] that I had a measurable
drop in node rate. So this may even be a win with fairly small arrays.]
I also will sometimes stuff several things into a 32-bit int (like the
move data type which has from-square, to-square, promo-type, etc.) and
retrieve the items as needed with bitwise ops and/or shifts. I put my
move type into a class with access functions for these things so that
I could try different ways of implementing the move type w/o having to
make massive changes to the code.
It turns out that stuffing these things into an int was faster than
maintaining them in separate chars, ie,
class move_t {
unsigned int bits;
public:
int from() { return bits & 0x3f; )
int to() { return (bits >> 6) & 0x3f; }
...
};
was faster than
class move_t {
char from_;
char to_;
char promo_;
char type_;
public:
int from() { return (int)from_; }
int to() { return (int)to_; }
...
};
-Dan.
This page took 0.01 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.