Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: optimization of replacing int structs question

Author: Klaus Friedel

Date: 07:58:09 03/25/04

Go up one level in this thread


On March 25, 2004 at 10:06:34, Uri Blass wrote:

>Today when I sort moves in movei I replace between 2 arrays of integers when one
>integer is for the move and 2 other integers are for scores.
>
>My question is if I can do it faster than my primitive approach when I use a
>third varaible:
>
>g = gen_dat[from];
>gen_dat[from] = gen_dat[bi];
>gen_dat[bi] = g;
>
>I remember that it is possible to replace 2 int's faster but I do not remember
>the way to do it(I guess that it can help me to get speed improvement by simply
>replacing every int in the structs gen_dat[from],gen_dat[bi] but I am not sure
>about it).
>
>Uri

It's possible to exchange the two int's without a helper variable:

a ^= b;
b ^= a;
a ^= b;

Looks strange, but should work. If a and b are structs it depends
on their size. If the struct is 2 x 32 bit you might use the trick
on a union definition as 64-Bit ulong. You have to try your own if
it's really faster.

Regards
Klaus



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.