Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Silly question about "C"

Author: Gerd Isenberg

Date: 00:29:55 09/17/04

Go up one level in this thread


On September 16, 2004 at 19:57:07, Antonio Senatore wrote:

>Hi friends:
>
>Which data type is faster to manage positive values lower than 255 (under
>Win32); unsigned char, short or int?
>
>Thanks in advance
>Antonio

Faster due to native register width versus 1/4 less memory space.

If you have only a few, but often used variables of this kind use int (32-bit
native word width for x86-32 and even x86-64), specially for locals. If global
or heap memory space becomes an issue for huge arrays, it might be better to use
unsigned char arrays, or arrays of structs with e.g. four unsigned chars,
specially if they are needed seldomly, or you do some kind of single instruction
multiple data (SIMD) within a register (SWAR).

It also depends a bit on what operations (possible overflows) or algorithms are
done with those variables or whether you use them as index. Partial register
processing (al, ah,...) has some drawbacks, e.g. register stalls between
independent 8-bit registers inside one 16/32 bit register.

Otherwise it is about the faster mov versus movzx intruction to load an int
versus unsigned char zero extended into one 32-bit register, which may used as
an index.

Frequently used board arrays with 64 or 128 elements are most likely faster with
32-bit ints, even if it takes up to four times more 64-byte cachelines, but you
have 512 or even 1024 of them in L1 cache.

Gerd



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.