Compiling Gurus: need advice

Discussion of chess software programming and technical issues.

Moderator: Ras

Edsel Apostol
Posts: 803
Joined: Mon Jul 17, 2006 5:53 am
Full name: Edsel Apostol

Compiling Gurus: need advice

Post by Edsel Apostol »

Hi Everyone,

I've been using Dev C++ for my program development for some time. It uses GCC. Recently I download VS C++ 2008 beta 2. I read that VS and ICC compiles much faster than GCC so I want to try them. I currently don't have ICC so I will try first with VS.

I need the opinion and advice of the compiling gurus on this forum.

I can't seem to compile my engine because of a missing "strcasecmp" function. What should be the equivalent function for this on VS? The solution I could think of is to search for code of "strcasecmp" in the net and incorporate it in my engine, but if there is already an equivalent function then I would rather use that.

I read that PGO helps boost the speed of the compiled executable. How am I going to use PGO using VS 2008 beta 2, if it is possible?

My engine is also bitboards and I want to release a 64 bit version for those who have a 64 bit system already. Is it possible to compile a 64 bit version from a 32 bit OS? What are the necessary compile flags, etc?
Dann Corbit
Posts: 12777
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Compiling Gurus: need advice

Post by Dann Corbit »

Edsel Apostol wrote:Hi Everyone,

I've been using Dev C++ for my program development for some time. It uses GCC. Recently I download VS C++ 2008 beta 2. I read that VS and ICC compiles much faster than GCC so I want to try them. I currently don't have ICC so I will try first with VS.

I need the opinion and advice of the compiling gurus on this forum.

I can't seem to compile my engine because of a missing "strcasecmp" function. What should be the equivalent function for this on VS? The solution I could think of is to search for code of "strcasecmp" in the net and incorporate it in my engine, but if there is already an equivalent function then I would rather use that.
_stricmp()

I read that PGO helps boost the speed of the compiled executable. How am I going to use PGO using VS 2008 beta 2, if it is possible?
You can't. You have to get the professional version to do PGO compiles.

My engine is also bitboards and I want to release a 64 bit version for those who have a 64 bit system already. Is it possible to compile a 64 bit version from a 32 bit OS? What are the necessary compile flags, etc?
You can't make real 64 bit versions for 32 bit operating systems. It's possible to get some boost by compiling for a specific CPU (to use special registers) but it won't run on other machines if you do that.
Edsel Apostol
Posts: 803
Joined: Mon Jul 17, 2006 5:53 am
Full name: Edsel Apostol

Re: Compiling Gurus: need advice

Post by Edsel Apostol »

Hi Dann,

Thanks!

How about PGO compiling using GCC? I think I have seen some compiling advice on superchessengine.com before, I will try to look it up.
You can't make real 64 bit versions for 32 bit operating systems. It's possible to get some boost by compiling for a specific CPU (to use special registers) but it won't run on other machines if you do that.
What I mean is that if I could compile a 64 bit executable for 64 bit OS using a 32 bit OS only. I know that 64 bit executables wouldn't run on 32 bit OS, but can I compile it from the 32 bit OS?
Dann Corbit
Posts: 12777
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Compiling Gurus: need advice

Post by Dann Corbit »

Edsel Apostol wrote:Hi Dann,

Thanks!

How about PGO compiling using GCC? I think I have seen some compiling advice on superchessengine.com before, I will try to look it up.
Yes.
You can't make real 64 bit versions for 32 bit operating systems. It's possible to get some boost by compiling for a specific CPU (to use special registers) but it won't run on other machines if you do that.
What I mean is that if I could compile a 64 bit executable for 64 bit OS using a 32 bit OS only. I know that 64 bit executables wouldn't run on 32 bit OS, but can I compile it from the 32 bit OS?[/quote]
Yes, you can do that. I would be leery to release anything that I did not test, though.
User avatar
pedrox
Posts: 1056
Joined: Fri Mar 10, 2006 6:07 am
Location: Basque Country (Spain)

Re: Compiling Gurus: need advice

Post by pedrox »

Hi Edsel, I use to compile Microsoft Virtual PC. I have an image with Windows Server 2003 and Microsoft Visual Studio 2008 beta 2, these images can be downloaded also from the Microsoft site.

I do a new project and I include all sources files and header files, go to "Configuration Manager" (Build menu) I put Release (not debug), in the project properties for optimization c/c ++ I put "Maximum speed (/O2)" and "Favor Fast Cod" (/Ot).

To make a compilation PGO going to the menu Build "Profile Guided Optimazation" the first step "Instrument", once finished, I have a function that looks 30 positions for 10 seconds, is the training, once we finish again to the menu "Profile Guided Optimization" and we "Update" and "Optimize". With PGO I have 20% faster

In the menu "Configuration Manager" can change your platform win32, a new and you choose x64. For my x64 is even slower, DanaSah not bitboard.
User avatar
Jim Ablett
Posts: 2126
Joined: Fri Jul 14, 2006 7:56 am
Location: London, England
Full name: Jim Ablett

Re: Compiling Gurus: need advice

Post by Jim Ablett »

Hi Edsel,
I can't seem to compile my engine because of a missing "strcasecmp" function. What should be the equivalent function for this on VS? The solution I could think of is to search for code of "strcasecmp" in the net and incorporate it in my engine, but if there is already an equivalent function then I would rather use that.

_stricmp()
I remember Glaurung use to use this code>

Code: Select all

/*
 * strncasecmp.c --
 *
 *      Source code for the "strncasecmp" library routine.
 *
 * Copyright (c) 1988-1993 The Regents of the University of California.
 */

#include <string.h>
#include <stdlib.h>
/*
 * This array is designed for mapping upper and lower case letter
 * together for a case independent comparison.  The mappings are
 * based upon ASCII character sequences.
 */

static unsigned char cm[] =
{
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
    0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
    0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
    0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
    0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
    0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
    0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
    0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
    0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
    0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
    0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
    0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
    0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
    0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
    0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
    0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
    0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
    0xc0, 0xe1, 0xe2, 0xe3, 0xe4, 0xc5, 0xe6, 0xe7,
    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
    0xf8, 0xf9, 0xfa, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
    0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
    0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
};

/*
 *----------------------------------------------------------------------
 *
 * strcasecmp --
 *
 *      Compares two strings, ignoring case differences.
 *
 * Results:
 *      Compares two null-terminated strings s1 and s2, returning -1, 0,
 *      or 1 if s1 is lexicographically less than, equal to, or greater
 *      than s2.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */

int             strcasecmp(const char *s1, const char *s2)
{
    unsigned char   u1,
                    u2;

    for (;; s1++, s2++) {
        u1 = (unsigned char) *s1;
        u2 = (unsigned char) *s2;
        if ((u1 == '\0') || (cm[u1] != cm[u2])) {
            break;
        }
    }
    return cm[u1] - cm[u2];
}

/*
 *----------------------------------------------------------------------
 *
 * strncasecmp --
 *
 *      Compares two strings, ignoring case differences.
 *
 * Results:
 *      Compares up to length chars of s1 and s2, returning -1, 0, or 1
 *      if s1 is lexicographically less than, equal to, or greater
 *      than s2 over those characters.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */

int             strncasecmp(const char *s1, const char *s2, size_t length)
{
    unsigned char   u1,
                    u2;

    for (; length != 0; length--, s1++, s2++) {
        u1 = (unsigned char) *s1;
        u2 = (unsigned char) *s2;
        if (cm[u1] != cm[u2]) {
            return cm[u1] - cm[u2];
        }
        if (u1 == '\0') {
            return 0;
        }
    }
    return 0;
}
and in Glaurung.h

Code: Select all

int             strncasecmp(const char *, const char *, size_t);
rdgs,
Jim.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Compiling Gurus: need advice

Post by bob »

Edsel Apostol wrote:Hi Dann,

Thanks!

How about PGO compiling using GCC? I think I have seen some compiling advice on superchessengine.com before, I will try to look it up.
You can't make real 64 bit versions for 32 bit operating systems. It's possible to get some boost by compiling for a specific CPU (to use special registers) but it won't run on other machines if you do that.
What I mean is that if I could compile a 64 bit executable for 64 bit OS using a 32 bit OS only. I know that 64 bit executables wouldn't run on 32 bit OS, but can I compile it from the 32 bit OS?
Yes you can, but it is non-trivial because you need the 64 bit libraries, a compiler than can produce 64 bit executables, a linker that can produce 64 bit executables, etc... I do this regularly on linux because I have a mix of 32 and 64 bit machines here...
Ron Murawski
Posts: 397
Joined: Sun Oct 29, 2006 4:38 am
Location: Schenectady, NY

Re: Compiling Gurus: need advice

Post by Ron Murawski »

Edsel Apostol wrote:Hi Everyone,

I've been using Dev C++ for my program development for some time. It uses GCC.
Hi Edsel,

Dev C++ development stopped about 3 years ago. If you still intend to work with GCC you might consider using CodeBlocks. CodeBlocks is open source and can be used as a front end for *any* C/C++ compiler, so you can swap to the compiler of your choice while maintaining a consistent IDE. If you are interested in CodeBlocks, make sure you download the nightly build. The stable release is quite old, has fewer features, and more bugs.
http://www.codeblocks.org/

Ron
Edsel Apostol
Posts: 803
Joined: Mon Jul 17, 2006 5:53 am
Full name: Edsel Apostol

Re: Compiling Gurus: need advice

Post by Edsel Apostol »

Hi Pedro,

Thanks!

I can't seem to find PGO support and 64 bit compile for VC++ 2008 beta 2.

can somebody verify this?
Edsel Apostol
Posts: 803
Joined: Mon Jul 17, 2006 5:53 am
Full name: Edsel Apostol

Re: Compiling Gurus: need advice

Post by Edsel Apostol »

Hi Jim,

I am aware of that code from Glaurung but I couldn't find the old source code anymore. Thanks for posting it here.