Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: question about optimizing code

Author: Reinhard Scharnagl

Date: 00:29:38 07/08/03

Go up one level in this thread


Hi Uri,

>I calculate exact ditribution of the bits in the first 10,000,000 nodes from
>the opening position and here is the result:
>
>I have 20,357,657 cases of calling the switch command.
>The average number of bits set is 1.27405
>
>in 2895517 cases  bit 0 is set
>in 2910299 cases  bit 1 is set
>in 2123957 cases  bit 2 is set
>in 2733137 cases  bit 3 is set
>in 5285584 cases  bit 4 is set
>in 4632172 cases  bit 5 is set
>in 4706124 cases  bit 6 is set
>in 5121911 cases  bit 7 is set

if you do not like to use a 'goto' then look at
the following proposal:

int mask;
do {
  switch (number) {
    cases [all odd numbers (with 0x01 matching)]:
      /* commands bit-1 */
      mask = ~0x01; break;
    cases [all numbers left with 0x02 matching]:
      /* commands bit-2 */
      mask = ~0x02; break;
    cases [all numbers left with 0x04 matching]:
      /* commands bit-3 */
      mask = ~0x04; break;
    case 0x08: case 0x18: case 0x28: case 0x38:
    case 0x48: case 0x58: case 0x68: case 0x78:
    case 0x88: case 0x98: case 0xa8: case 0xb8:
    case 0xc8: case 0xd8: case 0xe8: case 0xf8:
      /* commands bit-4 */
      mask = ~0x08; break;
    case 0x10: case 0x30: case 0x50: case 0x70:
    case 0x90: case 0xb0: case 0xd0: case 0xf0:
      /* commands bit-5 */
      mask = ~0x10; break;
    case 0x20: case 0x60: case 0xa0: case 0xe0:
      /* commands bit-6 */
      mask = ~0x20; break;
    case 0x40: case 0xc0:
      /* commands bit-7 */
      mask = ~0x40; break;
    case 0x80:
      /* commands bit-8 */
      mask = ~0x80; break;
    case 0x00: default:
      mask =  0x00; break;
  }
} while ((number &= mask) != 0);

Reinhard.



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.