Saturday, September 3, 2011

Trying Delphi XE2, ChessKISS 64 bits vs 32 bits

 Well, it was not difficult to make it work under 64 bits, but a bit to tune the WIN32 assembler versions that are not longer valid. I had to change the following functions:


function TBit.FirstBitSet(aValue: integer): integer;
{$IFDEF WIN32}
//EDX
ASM
  BSF EAX, EDX
END;
{$ELSE}
const
  Mod37BitPosition: array[0..36] of integer =
  (
    32, 0, 1, 26, 2, 23, 27, 0, 3, 16, 24, 30, 28, 11, 0, 13, 4, 7, 17,
    0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9, 5, 20, 8, 19, 18
  );

begin
  {
  result := 0;

  for i := 0 to 31 do
  begin
    if _GetBit(aValue, i) then
      Exit(i);
  end;
  }

  result := Mod37BitPosition[(-aValue and aValue) mod 37];
end;
{$ENDIF}

function TBit.LastBitSet(aValue: integer): integer;
{$IFDEF WIN32}
//EDX
ASM
  BSR EAX, EDX
END;
{$ELSE}
const
  MultiplyDeBruijnBitPosition: array[0..31] of integer =
    (0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9);

begin
  {
  result := 0;

  for i := 31 downto 0 do
  begin
    if _GetBit(aValue, i) then
      Exit(i);
  end;
  }
  result := MultiplyDeBruijnBitPosition[cardinal(aValue * $077cb531) shr 27];
end;
{$ENDIF}

function TBit.PopFirstBitSet(var aValue: integer): integer;
//In = [EDX] Out = EAX
{$IFDEF WIN32}
ASM
  PUSH ECX
  MOV ECX, [EDX]
  BSF EAX, ECX
  BTR [EDX], EAX
  POP ECX
END;
{$ELSE}
begin
  result := FirstBitSet(aValue);
  _Clear(aValue, result);
end;
{$ENDIF}

Coming from Delphi 2010 is a bit strange this build configuration, I've set it up to release, this has boost again the performance so is not longer two times slower, silly me...


Some tests from initial position.

Win32)
02/09/2011 23:52:29, Send: 1 77 0 57 Nb1c3 
02/09/2011 23:52:29, Send: 2 5 0 228 Nb1c3 Nb8c6 
02/09/2011 23:52:29, Send: 3 69 0 359 Nb1c3 Nb8c6 Ng1f3 
02/09/2011 23:52:29, Send: 4 5 1 5309 Nb1c3 Nb8c6 Ng1f3 Ng8f6 
02/09/2011 23:52:29, Send: 5 52 0 7137 Nb1c3 Nb8c6 Ng1f3 Ng8f6 d4 
02/09/2011 23:52:29, Send: 6 39 1 12584 Nb1c3 Nb8c6 d3 Ng8f6 Bc1e3 d5 
02/09/2011 23:52:29, Send: 7 56 4 30821 Nb1c3 d6 Ng1f3 Bc8e6 e4 Nb8c6 Bf1b5 
02/09/2011 23:52:30, Send: 8 13 25 107775 Ng1f3 d5 e3 Bc8e6 Bf1b5 Nb8c6 Nf3e5 Ng8f6 Nb1c3 
02/09/2011 23:52:30, Send: 9 9 35 220814 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8g4 d4 Bg4xf3 
02/09/2011 23:52:31, Send: 10 7 78 451966 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8g4 d4 e6 
02/09/2011 23:52:32, Send: 11 12 157 905577 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8d7 d4 a6 Bb5d3 
02/09/2011 23:52:39, Send: 12 16 650 2598910 e4 e5 Nb1c3 Nb8c6 Ng1f3 Ng8f6 Bf1b5 Bf8d6 d3 O-O Bc1g5 Kg8h8 
02/09/2011 23:52:48, Send: 13 23 858 4698110 e4 Ng8f6 Nb1c3 d5 e4xd5 Nf6xd5 Ng1f3 Nb8c6 Bf1b5 Bc8g4 O-O a6 Bb5xc6 b7xc6 
02/09/2011 23:52:58, Send: 14 21 1085 7551076 e4 Ng8f6 Nb1c3 d5 e4xd5 Nf6xd5 Ng1f3 Nb8c6 Bf1b5 Nd5xc3 b2xc3 Qd8d5 Ra1b1 Bc8d7 
Depth 14 reached in 32 seconds.
Win64)
03/09/2011 0:01:30, Send: 1 77 0 57 Nb1c3 
03/09/2011 0:01:30, Send: 2 5 0 228 Nb1c3 Nb8c6 
03/09/2011 0:01:30, Send: 3 69 0 359 Nb1c3 Nb8c6 Ng1f3 
03/09/2011 0:01:30, Send: 4 5 1 5309 Nb1c3 Nb8c6 Ng1f3 Ng8f6 
03/09/2011 0:01:30, Send: 5 52 0 7137 Nb1c3 Nb8c6 Ng1f3 Ng8f6 d4 
03/09/2011 0:01:30, Send: 6 39 1 12584 Nb1c3 Nb8c6 d3 Ng8f6 Bc1e3 d5 
03/09/2011 0:01:30, Send: 7 56 6 30821 Nb1c3 d6 Ng1f3 Bc8e6 e4 Nb8c6 Bf1b5 
03/09/2011 0:01:31, Send: 8 13 32 107775 Ng1f3 d5 e3 Bc8e6 Bf1b5 Nb8c6 Nf3e5 Ng8f6 Nb1c3 
03/09/2011 0:01:31, Send: 9 9 51 220817 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8g4 d4 Bg4xf3 
03/09/2011 0:01:32, Send: 10 7 106 451687 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8g4 d4 e6 
03/09/2011 0:01:34, Send: 11 12 215 908965 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8d7 d4 a6 Bb5d3 
03/09/2011 0:01:43, Send: 12 19 900 2607087 e4 e5 Nb1c3 Nb8c6 Ng1f3 Bf8d6 Bf1b5 Ng8e7 O-O a6 Bb5d3 Bd6c5 
03/09/2011 0:01:53, Send: 13 23 931 4361400 e4 Ng8f6 Nb1c3 d5 e4xd5 Nf6xd5 Ng1f3 Nb8c6 Bf1b5 Bc8g4 O-O a6 Bb5xc6 b7xc6 
03/09/2011 0:02:10, Send: 14 21 1780 7805174 e4 Ng8f6 Nb1c3 d5 e4xd5 Nf6xd5 Ng1f3 Nb8c6 Bf1b5 Nd5xc3 b2xc3 Qd8d5 Ra1b1 Bc8d7 Bb5d3
Depth 14 reached in 40 seconds, 10 seconds slower!, but the worst thing is that they are different, OMG!
02/09/2011 23:52:29, Send: 1 77 0 57 Nb1c3 
03/09/2011 0:01:30,  Send: 1 77 0 57 Nb1c3 
02/09/2011 23:52:29, Send: 2 5 0 228 Nb1c3 Nb8c6 
03/09/2011 0:01:30,  Send: 2 5 0 228 Nb1c3 Nb8c6 
02/09/2011 23:52:29, Send: 3 69 0 359 Nb1c3 Nb8c6 Ng1f3 
03/09/2011 0:01:30,  Send: 3 69 0 359 Nb1c3 Nb8c6 Ng1f3 
02/09/2011 23:52:29, Send: 4 5 1 5309 Nb1c3 Nb8c6 Ng1f3 Ng8f6 
03/09/2011 0:01:30,  Send: 4 5 1 5309 Nb1c3 Nb8c6 Ng1f3 Ng8f6 
02/09/2011 23:52:29, Send: 5 52 0 7137 Nb1c3 Nb8c6 Ng1f3 Ng8f6 d4 
03/09/2011 0:01:30,  Send: 5 52 0 7137 Nb1c3 Nb8c6 Ng1f3 Ng8f6 d4 
02/09/2011 23:52:29, Send: 6 39 1 12584 Nb1c3 Nb8c6 d3 Ng8f6 Bc1e3 d5 
03/09/2011 0:01:30,  Send: 6 39 1 12584 Nb1c3 Nb8c6 d3 Ng8f6 Bc1e3 d5 
02/09/2011 23:52:29, Send: 7 56 4 30821 Nb1c3 d6 Ng1f3 Bc8e6 e4 Nb8c6 Bf1b5 
03/09/2011 0:01:30,  Send: 7 56 6 30821 Nb1c3 d6 Ng1f3 Bc8e6 e4 Nb8c6 Bf1b5 
02/09/2011 23:52:30, Send: 8 13 25 107775 Ng1f3 d5 e3 Bc8e6 Bf1b5 Nb8c6 Nf3e5 Ng8f6 Nb1c3 
03/09/2011 0:01:31,  Send: 8 13 32 107775 Ng1f3 d5 e3 Bc8e6 Bf1b5 Nb8c6 Nf3e5 Ng8f6 Nb1c3 
02/09/2011 23:52:30, Send: 9 9 35 220814 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8g4 d4 Bg4xf3 
03/09/2011 0:01:31,  Send: 9 9 51 220817 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8g4 d4 Bg4xf3 
02/09/2011 23:52:31, Send: 10 7 78 451966 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8g4 d4 e6 
03/09/2011 0:01:32,  Send: 10 7 106 451687 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8g4 d4 e6 
Different number of searches!

02/09/2011 23:52:32, Send: 11 12 157 905577 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8d7 d4 a6 Bb5d3 
03/09/2011 0:01:34,  Send: 11 12 215 908965 Ng1f3 d5 e3 Nb8c6 Bf1b5 Ng8f6 Nb1c3 Bc8d7 d4 a6 Bb5d3 
Different number of searches!

02/09/2011 23:52:39, Send: 12 16 650 2598910 e4 e5 Nb1c3 Nb8c6 Ng1f3 Ng8f6 Bf1b5 Bf8d6 d3 O-O Bc1g5 Kg8h8 
03/09/2011 0:01:43,  Send: 12 19 900 2607087 e4 e5 Nb1c3 Nb8c6 Ng1f3 Bf8d6 Bf1b5 Ng8e7 O-O a6 Bb5d3 Bd6c5 

02/09/2011 23:52:48, Send: 13 23 858 4698110 e4 Ng8f6 Nb1c3 d5 e4xd5 Nf6xd5 Ng1f3 Nb8c6 Bf1b5 Bc8g4 O-O a6 Bb5xc6 b7xc6 
03/09/2011 0:01:53,  Send: 13 23 931 4361400 e4 Ng8f6 Nb1c3 d5 e4xd5 Nf6xd5 Ng1f3 Nb8c6 Bf1b5 Bc8g4 O-O a6 Bb5xc6 b7xc6 

02/09/2011 23:52:58, Send: 14 21 1085 7551076 e4 Ng8f6 Nb1c3 d5 e4xd5 Nf6xd5 Ng1f3 Nb8c6 Bf1b5 Nd5xc3 b2xc3 Qd8d5 Ra1b1 Bc8d7 
03/09/2011 0:02:10,  Send: 14 21 1780 7805174 e4 Ng8f6 Nb1c3 d5 e4xd5 Nf6xd5 Ng1f3 Nb8c6 Bf1b5 Nd5xc3 b2xc3 Qd8d5 Ra1b1 Bc8d7 Bb5d3
Hooray!, more not so funny debugging sessions in order to find nasty bugs, let's see how I will tackle this...

No comments:

Post a Comment