Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: slow coding

Author: Dieter Buerssner

Date: 10:18:30 11/20/05

Go up one level in this thread


On November 17, 2005 at 18:34:34, Daniel Mehrmannn wrote:

>On November 17, 2005 at 18:13:36, Dann Corbit wrote:
>
>>Consider the following when depth >= 3:
>>
>>			if (depth < 2)
>>				FutilityMargin = FutilityMargin1;
>>			else if (depth < 3)
>>				FutilityMargin = FutilityMargin2;
>>			/* else
>>				FutilityMargin = FutilityMargin3; */
>>

>btw this looks like a very slow coding. It's better to use here switch()/case
>stuff for an faster code instead the expensive if() stuff.

I doubt it very much. In cases I investigated in the past, compilers produce
if/else chain type assembly automatically from such small switches - because it
is faster.

See example below. Regards,
Dieter

C:\SRC>cat switch.c
int res0=0, res1=1, res2=2;
int res_array[128] /*MAX_DEPTH */ = {0,0,1,2 /*, ... */};

int switch_method(unsigned u)
{
  int res;
  switch(u)
  {
    case 0: case 1:
      res=res0; break;
    case 2:
      res=res1; break;
    default:
      res = res2;
  }
  return res;
}

int if_method(unsigned u)
{
  int res;
  if (u < 2)
    res = res0;
  else if (u<3)
    res = res1;
  else
    res = res2;
  return res;
}

int array_method(unsigned u)
{
  return res_array[u];
}


C:\SRC>gcc -O2 -S -fomit-frame-pointer switch.c

C:\SRC>cat switch.s
	.file	"switch.c"
.globl _res_array
	.data
	.align 32
_res_array:
	.long	0
	.long	0
	.long	1
	.long	2
	.space 496
.globl _res2
	.align 4
_res2:
	.long	2
.globl _res1
	.align 4
_res1:
	.long	1
.globl _res0
	.bss
	.align 4
_res0:
	.space 4
	.text
	.p2align 4,,15
.globl _switch_method
	.def	_switch_method;	.scl	2;	.type	32;	.endef
_switch_method:
	movl	4(%esp), %eax
	cmpl	$1, %eax
	jbe	L4
	cmpl	$2, %eax
	je	L5
	movl	_res2, %eax
	ret
	.p2align 4,,7
L4:
	movl	_res0, %eax
	ret
	.p2align 4,,7
L5:
	movl	_res1, %eax
	ret
	.p2align 4,,15
.globl _if_method
	.def	_if_method;	.scl	2;	.type	32;	.endef
_if_method:
	movl	4(%esp), %eax
	cmpl	$1, %eax
	ja	L9
	movl	_res0, %eax
	ret
	.p2align 4,,7
L9:
	cmpl	$2, %eax
	ja	L11
	movl	_res1, %eax
	ret
	.p2align 4,,7
L11:
	movl	_res2, %eax
	ret
	.p2align 4,,15
.globl _array_method
	.def	_array_method;	.scl	2;	.type	32;	.endef
_array_method:
	movl	4(%esp), %eax
	movl	_res_array(,%eax,4), %eax
	ret



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.