Author: Anthony Cozzie
Date: 15:55:40 03/11/03
Go up one level in this thread
On March 11, 2003 at 14:46:11, Russell Reagan wrote:
>I got some warnings yesterday from my compiler about mixing data types. One
>warning said something like, "converting bool to int, performance warning", or
>something similar. What is good practice regarding the use of different sized
>variables together? One example from my program is that I store the move as a
>struct with several byte sized fields. My thinking is that since I will need to
>save the move everytime I make a move, I can copy those 4 bytes once, instead of
>having to do 4 copies of 32-bit values.
>
>typedef struct {
> unsigned char from;
> unsigned char to;
> unsigned char type;
> unsigned char whatever;
>} Move;
>
>Instead of:
>
>typedef struct {
> unsigned int from;
> unsigned int to;
> unsigned int type;
> unsigned int whatever;
>} Move;
>
>I got another warning when using an unsigned char as my board index, and using a
>signed char as the offset from that index (it might have been a different
>situation, but it was something similar, when I was mixing unsigned with
>signed).
>
>I got various warnings about mixing char with int, unsigned with signed, and so
>on. They were not all performance warnings, but I would like to know if it is
>better to use the smaller structure and save time copying it, or if it is better
>to use the larger structure and work with "faster" variables. It seems like you
>could keep more stuff in the cache if you used smaller sized variables when
>suitable. I'd also like to know if there are ever performance issues when mixing
>variables of different types (mixing char w/ short w/ long, unsigned w/ signed,
>etc.).
>
>Thanks,
>Russell
I use the following:
typedef struct
{
zappa_s8 f_loc; //Move to square b
zappa_s8 in_loc; //Starting from square a
zappa_s8 ptype; //piece type
zappa_s8 prom_to; //Promote to piece type X
} zmove_def;
//Since it is often convienient to access all 4 bytes cleanly,
//zmove is also defined as a union.
typedef union
{
zappa_s32 i; //all 4 bytes - i for integer
zmove_def m; //individual bytes - m for move
} zmove;
where s8 is signed 8bit, etc. this works well for me: for starters I can
redefine zappa_s32 on different architechtures (for example on alpha I believe
short int is 32bits). Also, it gives a convenient way of referring to the move
as either its parts or the 32bit whole. Apparently tscp does it this way. Bob
uses pure ints in crafty; to me that seems a little low level. <shrug>.
anthony
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.