Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: longjmp question

Author: Gerd Isenberg

Date: 09:08:16 06/20/04

Go up one level in this thread


On June 20, 2004 at 06:00:58, Ross Boyd wrote:

>My engine (coded in C) uses longjmp() to terminate a search.
>
>Is there any disadvantage or hidden overhead in this approach?
>
>I notice other engines use a flag which is tested at every node of the search.
>Surely there's an overhead in doing it that way????
>
>I suppose the main drawback of longjmp() is portability. Most languages other
>than C don't support it.
>
>Am I missing something?
>
>Ross

Yes, there is a tiny overhead if asking a flag everywhere in the search.

I never used setjmp()/longjmp() so far in C or C++, but C++ try-catch blocks, as
recently in my recursive De Bruijn generator. You may throw different values for
different reasons and interprete it inside a catch(int e) or
catch(ownExceptionType e) block.

Gerd


    m_Lock = 0;
    try {findDeBruijn(0, 64-6, 0);}
    catch(BitBoard deBruijnFound)
    {
       printBitScan(deBruijnFound);
    }



void findDeBruijn(BitBoard seq, int depth, int unique)
{
    if ( (m_Lock & pow2[unique]) == 0 )
    { // unique is not locked
        if ( depth <= 0 )
        {   // De Bruijn found
            if ( ++m_dBCount == m_Match4nth )
            {   // n.th De Bruijn found
                throw seq; // throw an BitBoard exception, unwind the stack
            }
        }
        else
        {
            m_Lock ^= pow2[unique]; // lock current index
            if ( unique == 31 )
            {   // 31->63->63 is a unique sub path
                findDeBruijn(seq | pow2[depth-1], depth-2, 62);
            }
            else
            {   // 32 as successor from 16,48 is always last!
                if ( depth != 1 && unique != 16 && unique != 48 )
                    findDeBruijn(seq, depth-1, (unique*2)&63);
                findDeBruijn(seq | pow2[depth-1], depth-1, (unique*2+1)&63);
            }
            m_Lock ^= pow2[unique]; // unlock index
        }
    }
}





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.