Cygwin for chess

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Greg McGlynn

Cygwin for chess

Post by Greg McGlynn »

Hi all,

Having written a relatively weak Java chess engine almost a year ago, I decided recently to start from scratch and write a new one in C, a language with which I am less familiar. Since I run Windows but have done some C++ on Linux in the past, I downloaded Cygwin and gcc and have a basic engine working. gcc does some nice optimizations and the new engine's perft is significantly faster than the old Java one's. However, I figured that running on Cygwin must be slowing it down some--is this correct? Also the .exe produced is dependent on the presence cygwin1.dll.

To try to improve this I downloaded Visual C++ 2008 Express and imported my code; after fixing up some syntax VC++ didn't like I got it to compile, producing a standalone .exe. However perft ran several times slower than it did under Cygwin. I found some optimization options in VC++ and set them as best I could, but still the Cygwin program runs twice as fast. Is Cygwin irrelevant to speed then? Is gcc better at optimization? Am I missing some optimization flags in VC++? I'm hoping someone around here can clarify some of this for me--I don't have much experience with any of this stuff and don't understand what factors are involved here.

Thanks for any help,

Greg McGlynn
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Cygwin for chess

Post by sje »

My guess is that when you get a "free" version of a commercial product from Microsoft, you shouldn't expect that you'll get all the bells and whistles that are included in the "pay" version.
User avatar
pedrox
Posts: 1056
Joined: Fri Mar 10, 2006 6:07 am
Location: Basque Country (Spain)

Re: Cygwin for chess

Post by pedrox »

Visual C ++ 2008 Express is perfectly valid to build engines, only loses regarding other versions of payment do PGO (profile guided optimization) and this means about 10% of speed but still I think that is faster than even doing PGO with gcc.

Check in administrator of configurations that you have mode "release" and not "debug" and that you are optimizing in speed / O2 and you're encouraging the code rapid / Ot.
User avatar
Onno Garms
Posts: 224
Joined: Mon Mar 12, 2007 7:31 pm
Location: Bonn, Germany

Re: Cygwin for chess

Post by Onno Garms »

Greg McGlynn wrote: I found some optimization options in VC++ and set them as best I could, but still the Cygwin program runs twice as fast.
Such a large difference in speed is not normal. For my engine, VC++ express produces slightly faster code then gcc under Cygwin, which is not surprising as Cygwin still has gcc 3.x.

Also, both VC++ express and gcc/Cygwin only produce 32 bit code.

You should check your optimisation settings in VC++ again. Also consider runtime bound checks etc. (are very expensive, so should be all off in release mode). Disable managed extensions.

Under Cygwin, do you use the Windows API or do you use Posix? In case of the latter, maybe you call functions like probe_for_user_input or timer too frequently (and their speed might differ in Windows API and Posix).
Last edited by Onno Garms on Tue Aug 26, 2008 5:05 pm, edited 1 time in total.
User avatar
hgm
Posts: 27851
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Cygwin for chess

Post by hgm »

In principle running under Cygwin should make no difference at all. Cygwin is just an interface, you call systemm routines in a DLL in stead of calling the native Windows system routines directly. But this only happens for system calls. When your program is calculating, there is absoluteluy no difference.

I do all my development under Cygwin, but I never run my engines under it. My engines do not need the Cygwin1.dll, and I run them plain under Windows. Just compile with the option "-mno-cygwin".
User avatar
Onno Garms
Posts: 224
Joined: Mon Mar 12, 2007 7:31 pm
Location: Bonn, Germany

Re: Cygwin for chess

Post by Onno Garms »

hgm wrote:Cygwin is just an interface, you call systemm routines in a DLL in stead of calling the native Windows system routines directly. But this only happens for system calls.
True, but Cygwin1.dll might address the Windows system in a different way then the application.

What I wanted to say is:

If Posix is used for the Cygwin compile (normally equivalent to not using -mno-cygwin) there must be some code like

Code: Select all

void myfunc()
{
#ifdef _WIN32
  do_this();
#else
  do_that();
#endif
}
in the engine's sources. Possibly do_this() is more expensive then do_that().
User avatar
hgm
Posts: 27851
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Cygwin for chess

Post by hgm »

My own code does not contain any such things. I do not know about include-library headers, of course, but apart from reading the clock and standard i/o (from which my engine refrains during search), I do not call any routines I did not write myself.

I thought the -mno-cygwin compile would just link as subroutines in the executable what otherwise would be in the DLL.
Greg McGlynn

Re: Cygwin for chess

Post by Greg McGlynn »

hgm wrote:In principle running under Cygwin should make no difference at all. Cygwin is just an interface, you call systemm routines in a DLL in stead of calling the native Windows system routines directly. But this only happens for system calls. When your program is calculating, there is absoluteluy no difference.

I do all my development under Cygwin, but I never run my engines under it. My engines do not need the Cygwin1.dll, and I run them plain under Windows. Just compile with the option "-mno-cygwin".
OK--I'm not doing any system calls or anything so I should be fine I guess. -mno-cygwin is nice; I hadn't realized that existed.
Onno Garms wrote:For my engine, VC++ express produces slightly faster code then gcc under Cygwin
I tried flipping a few more switches in the configuration settings but not much changed. Perhaps I'm just misunderstanding some of the settings, but if the difference is only slight I think I'll just keep doing what I've been doing and not worry about it.

Thank you all.
Dann Corbit
Posts: 12564
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Cygwin for chess

Post by Dann Corbit »

Greg McGlynn wrote:Hi all,

Having written a relatively weak Java chess engine almost a year ago, I decided recently to start from scratch and write a new one in C, a language with which I am less familiar. Since I run Windows but have done some C++ on Linux in the past, I downloaded Cygwin and gcc and have a basic engine working. gcc does some nice optimizations and the new engine's perft is significantly faster than the old Java one's. However, I figured that running on Cygwin must be slowing it down some--is this correct? Also the .exe produced is dependent on the presence cygwin1.dll.

To try to improve this I downloaded Visual C++ 2008 Express and imported my code; after fixing up some syntax VC++ didn't like I got it to compile, producing a standalone .exe. However perft ran several times slower than it did under Cygwin. I found some optimization options in VC++ and set them as best I could, but still the Cygwin program runs twice as fast. Is Cygwin irrelevant to speed then? Is gcc better at optimization? Am I missing some optimization flags in VC++? I'm hoping someone around here can clarify some of this for me--I don't have much experience with any of this stuff and don't understand what factors are involved here.

Thanks for any help,

Greg McGlynn
The best compilers for chess programming are (in order)
1. Intel C++
2. Microsoft Visual C++
3. GCC (Mingw version is usually used, but Cygwin is similar)

In order to find out why GCC is faster I suggest running gprof to find out where the time is going with GCC and then running the performnace wizard using MS VC++. That will tell you where the time is going for both programs and also probably give you excellent hints on how to speed it up. If your program is open source, there are several experts who can do very fast C++ builds for you.
Dann Corbit
Posts: 12564
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Cygwin for chess

Post by Dann Corbit »

Onno Garms wrote:
Greg McGlynn wrote: I found some optimization options in VC++ and set them as best I could, but still the Cygwin program runs twice as fast.
Such a large difference in speed is not normal. For my engine, VC++ express produces slightly faster code then gcc under Cygwin, which is not surprising as Cygwin still has gcc 3.x.

Also, both VC++ express and gcc/Cygwin only produce 32 bit code.

You should check your optimisation settings in VC++ again. Also consider runtime bound checks etc. (are very expensive, so should be all off in release mode). Disable managed extensions.

Under Cygwin, do you use the Windows API or do you use Posix? In case of the latter, maybe you call functions like probe_for_user_input or timer too frequently (and their speed might differ in Windows API and Posix).
If he is using STL, there are some VC++ defaults that cause bounds checking and slow the code down by an order of magnitude.

As a wild guess, I suspect that is the problem. The GCC default is to not perform the bounds checking.