Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: 64Bit optimize coding - My experience (AMD64)

Author: Andreas Guettinger

Date: 12:30:07 12/21/05

Go up one level in this thread


On December 21, 2005 at 14:21:19, Tord Romstad wrote:

>On December 21, 2005 at 12:58:16, Andreas Guettinger wrote:
>
>>For comparision, the speedup of 64bit crafty on a G5 is around 50%.
>
>This was on a PowerMac?  A 50% speedup is quite impressive.  I just
>repeated your experiment with Crafty 20.1 on a first generation
>iMac G5 1.8 GHz, using the compiler options given in your post.
>Here are the results:
>
>Crafty v20.1
>
>White(1): bench
>Running benchmark. . .
>......
>Total nodes: 72473383
>Raw nodes per second: 0
>Total elapsed time: 139
>SMP time-to-ply measurement: 4.604317
>
>Crafty v20.1
>
>White(1): bench
>Running benchmark. . .
>......
>Total nodes: 72473383
>Raw nodes per second: 0
>Total elapsed time: 119
>SMP time-to-ply measurement: 5.378151
>
>The 64 bit executable is only about 16% faster.
>
>Tord

Well, the problem is that the -DINLINE_PPC flag does nothing on your sources. :)
I realized that a big part of the speedup seems to come from the asm
bitoperating routines.

Add a file inlineppc.h to the sources containing:

------------------

/* asm routines for 64 bit powerpc,
 * include this file if defined(INLINE_PPC) inside chess.h */

//#include <ppc_intrinsics.h>

int static __inline__ PopCnt(register BITBOARD a)
{
  register int c = 0;

  while (a) {
    c++;
    a &= a - 1;
  }
  return (c);
}

#if defined(INLINE_PPC)

/* code for PPC 64 bit */
int static __inline__ FirstOne(BITBOARD arg1)
{
	unsigned long index;

	__asm__("cntlzd %0, %1" : "=r" (index) : "r" (arg1));
	return index;
}

int static __inline__ LastOne(BITBOARD arg1)
{
	unsigned long index;

	__asm__("cntlzd %0, %1" : "=r" (index) : "r" (arg1 ^ (arg1 - 1)));
	return index;
}

#endif

-----------------------------

and make the following changes according to the diff file:

diff crafty-20.1/bench.c crafty-20.1_ppc/bench.c
153c153
<   Print(4095, "Raw nodes per second: %d\n", nodes / (total_time_used / 100));
---
>   Print(4095, "Raw nodes per second: %d\n", (int) (nodes / (total_time_used / 100)));
diff crafty-20.1/boolean.c crafty-20.1_ppc/boolean.c
19c19
< #if (!defined(INLINE_ASM) && !defined(VC_INLINE_ASM) && !defined(ALPHA) &&
!defined(INLINE_AMD)) || (defined(ALPHA) && !defined(PopCnt))
---
> #if (!defined(INLINE_ASM) && !defined(VC_INLINE_ASM) && !defined(ALPHA) && !defined(INLINE_AMD)) && !defined(INLINE_PPC) || (defined(ALPHA) && !defined(PopCnt))
diff crafty-20.1/chess.h crafty-20.1_ppc/chess.h
511c511
< #  if !defined(INLINE_AMD) && !defined(INLINE_ASM)
---
> #  if !defined(INLINE_AMD) && !defined(INLINE_ASM) && !defined(INLINE_PPC)
1073a1074,1076
> #if defined(INLINE_PPC)
> #  include "inlineppc.h"
> #endif
Only in crafty-20.1_ppc: crafty
Only in crafty-20.1_ppc: crafty.o
diff crafty-20.1/data.c crafty-20.1_ppc/data.c
162c162
< #if (!defined(_M_AMD64) && !defined (_M_IA64) && !defined(INLINE_ASM)) ||
defined(VC_INLINE_ASM)
---
> #if (!defined(_M_AMD64) && !defined (_M_IA64) && !defined(INLINE_ASM)  && !defined(INLINE_PPC)) || defined(VC_INLINE_ASM)
diff crafty-20.1/data.h crafty-20.1_ppc/data.h
327c327
< # if !defined(_M_AMD64) && !defined (_M_IA64) && !defined(INLINE_ASM)
---
> # if !defined(_M_AMD64) && !defined (_M_IA64) && !defined(INLINE_ASM) && !defined(INLINE_PPC)
Only in crafty-20.1_ppc: egtb.o
diff crafty-20.1/init.c crafty-20.1_ppc/init.c
1490c1490
< #if !defined(CRAY1) && !defined(_M_AMD64) && !defined (_M_IA64) &&
!defined(INLINE_ASM)
---
> #if !defined(CRAY1) && !defined(_M_AMD64) && !defined (_M_IA64) && !defined(INLINE_ASM) && !defined(INLINE_PPC)
Only in crafty-20.1_ppc: inlineppc.h

Then compile with:

darwinG5:
	$(MAKE) target=LINUX \
		CC=gcc CXX=g++ \
		CFLAGS='$(CFLAGS) -Wall -pipe -D_REENTRANT -O2 -mcpu=G5 \
			-mtune=G5' \
		CXFLAGS=$(CFLAGS) \
		LDFLAGS=$(LDFLAGS) \
		LIBS='-lstdc++' \
		opt='$(opt) -DFUTILITY -DINLINE_PPC -DFAST' \
		crafty-make

regards
Andy



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.