Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Is this possible?

Author: Dann Corbit

Date: 13:51:17 09/25/02

Go up one level in this thread


On September 25, 2002 at 16:08:50, Dieter Buerssner wrote:

>On September 24, 2002 at 20:32:19, Dann Corbit wrote:
>
>>On September 24, 2002 at 19:10:18, Arshad Syed wrote:
>>
>>>I am planning to write my own engine soon. Preferably I would like to code the
>>>search engine in Assembly Language since nodes/sec is a very important factor
>>>for me. Is it easy to interface Winboard with Assembly language code?
>>
>>Sure.  Put C wrappers around everything.
>>
>>For instance, from Crafty's vcinline.h:
>>
>>#if _MSC_VER >= 1200
>>#define FORCEINLINE __forceinline
>>#else
>>#define FORCEINLINE __inline
>>#endif
>>
>>FORCEINLINE int PopCnt(BITBOARD a) {
>>/* Because Crafty bitboards are typically sparsely populated, we use a
>>   streamlined version of the boolean.c algorithm instead of the one in x86.s
>>
>>  __asm {
>>        mov     ecx, dword ptr a
>>        xor     eax, eax
>>        test    ecx, ecx
>>        jz      l1
>>    l0: lea     edx, [ecx-1]
>>        inc     eax
>>        and     ecx, edx
>>        jnz     l0
>>    l1: mov     ecx, dword ptr a+4
>>        test    ecx, ecx
>>        jz      l3
>>    l2: lea     edx, [ecx-1]
>>        inc     eax
>>        and     ecx, edx
>>        jnz     l2
>>    l3:
>>  }
>>}
>
>Perhaps an example, where one can use as efficiently high level language. See my
>comment some time ago at http://f11.parsimony.net/forum16635/messages/31324.htm
>
>The C code (slighly microtuned for a 32 bit architecture by using 2 loops for
>the 2 32 bit parts of the bitboard - as the assembly above does as well)
>produces essentially the same assembly. I did not profile it, but there might
>even be a chance, that it is faster, because of the missing alignment of the
>jump destinations.

I agree that optimizing C compilers will usually do remarkably well.  In fact, I
would not recommend for anyone to write a complete chess program in Assembly
language.  I imagine that Ed regrets that original decision, since it would make
porting so much harder.

Here is what my compiler spit out (I could probably choose better flags too):

IF @Version GE 612
  .MMX
  MMWORD TEXTEQU <QWORD>
ENDIF
IF @Version GE 614
  .XMM
  XMMWORD TEXTEQU <OWORD>
ENDIF
       ALIGN     4
; parameter 1: 4 + esp
        PUBLIC   _PopCount
_PopCount       PROC NEAR
.B1.1:                          ; Preds .B1.0
        mov       edx, DWORD PTR [esp+4]                        ;6.29
        xor       eax, eax                                      ;5.21
        test      edx, edx                                      ;7.5
        je        .B1.5         ; Prob 16%                      ;7.5

                                ; LOE eax edx ebx ebp esi edi
.B1.3:                          ; Preds .B1.1 .B1.3
        add       eax, 1                                        ;9.13
        lea       ecx, DWORD PTR [edx-1]                        ;11.22
        and       edx, ecx                                      ;11.17
        jne       .B1.3         ; Prob 90%                      ;11.17
                                ; LOE eax edx ebx ebp esi edi
.B1.5:                          ; Preds .B1.3 .B1.1
        mov       ecx, DWORD PTR [esp+8]                        ;12.31
        test      ecx, ecx                                      ;13.5
        je        .B1.9         ; Prob 10%                      ;13.5

                                ; LOE eax ecx ebx ebp esi edi
.B1.7:                          ; Preds .B1.5 .B1.7
        add       eax, 1                                        ;15.13
        lea       edx, DWORD PTR [ecx-1]                        ;17.22
        and       ecx, edx                                      ;17.17
        jne       .B1.7         ; Prob 90%                      ;17.17
                                ; LOE eax ecx ebx ebp esi edi
.B1.9:                          ; Preds .B1.7 .B1.5
        ret                                                     ;18.12
        ALIGN     4
                                ; LOE
; mark_end;
_PopCount ENDP



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.