what is the best free compiler to use?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: what is the best free compiler to use?

Post by Joost Buijs »

Sven wrote: Wed Oct 03, 2018 2:32 pm
Joost Buijs wrote: Wed Oct 03, 2018 9:15 am
odomobo wrote: Wed Oct 03, 2018 6:48 am
phhnguyen wrote: Wed Oct 03, 2018 3:54 am Probably I work mainly on macOs, using gcc, thus I didn’t twist the code and settings enough for speeding up with Windows/VS.
In my experience, if you build in release mode for x64 (if you have a 64-bit processor) will get you a pretty optimal build. I'm lucky if tweaking the settings from there will give me any performance improvement. By default, it enables some pretty aggressive optimizations, including link-time optimization.
With VS I usually get the best result when I enable AVX2 code generation, which most CPUs support nowadays, another thing is to disable the 'Security Check' in the generated code which also gains a few percent in speed. I'm totally happy with VS, it compiles very fast especially when you enable MP compilation, totally rebuilding my engine with VS takes about 5 sec. on my 10 core PC, and that is with the project on an old hard drive, on a SSD it will compile even faster.

It is possible that GCC generates somewhat faster code, but the difference is so small that it is negligible in practice, in my opinion GCC is rather cumbersome to use, especially on Windows, for development I would go for VS any day.
For my engine Jumbo GCC (even in older versions) has always created around 30-40% faster code than VS (even with VS2017 community). I talk about the 64-bit build of Jumbo's bitboard variant.
Well, that is amazing, I've never seen such big differences. Your engine must be very heavily optimized for use with GCC, or there is something else going on. Each compiler reacts differently to certain constructs, but the differences I usually see are in the order of at most 7%.

But I agree strange things can happen, when I run Perft with my engine the Intel compiler does this 30% faster than MSVC, the engine overall runs faster with MSVC. I think this is due to cache effects, maybe the code generated by MSVC is larger and doesn't fit in the cache that well, otherwise I can't explain this.
Sesse
Posts: 300
Joined: Mon Apr 30, 2018 11:51 pm

Re: what is the best free compiler to use?

Post by Sesse »

Joost Buijs wrote: Wed Oct 03, 2018 9:15 am I'm totally happy with VS, it compiles very fast especially when you enable MP compilation
Visual Studio is among the slowest C++ compilers still in actual use (and the /MP parallellization is super-primitive).

Case in point, at work we have a product where the Windows version can compile with both MSBuild + MSVC and Clang + Ninja (both through CMake). On the same machine, the latter is _four times as fast_ to compile (and the code is 3–5% faster, and the diagnostics are a mile more informative).
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: what is the best free compiler to use?

Post by Joost Buijs »

Sesse wrote: Wed Oct 03, 2018 9:11 pm
Joost Buijs wrote: Wed Oct 03, 2018 9:15 am I'm totally happy with VS, it compiles very fast especially when you enable MP compilation
Visual Studio is among the slowest C++ compilers still in actual use (and the /MP parallellization is super-primitive).

Case in point, at work we have a product where the Windows version can compile with both MSBuild + MSVC and Clang + Ninja (both through CMake). On the same machine, the latter is _four times as fast_ to compile (and the code is 3–5% faster, and the diagnostics are a mile more informative).
In that case it must be something else than GCC, on my machine GCC compiles slow like molasses. And the programming environment of VS is second to none, at least compared to these primitive environments on Linux systems.
Sesse
Posts: 300
Joined: Mon Apr 30, 2018 11:51 pm

Re: what is the best free compiler to use?

Post by Sesse »

Clang is a different compiler from GCC, indeed—they're entirely separate projects. But GCC is also usually somewhat faster than MSVC with comparable settings; MSVC is a very old compiler (its basic design harks back from the DOS era), and has to bend over backwards to deal with the more tricky C++ constructs. One potential pitfall when measuring is that MSBuild has horrible parallelization (it can parallelize on subproject-level only, and relies on the compiler to do the rest—with no jobserver control!), which is unlikely to play well with GCC.

As for the quality of the IDE, that is independent of the compiler (you can e.g. compile with Clang and use the Visual Studio IDE for editing). It is of course rather subjective what is a “primitive” environment or not; personally, I'm happy I don't have to work with the atrocious VS editor anymore! Or Windows, for that matter. :-)
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: what is the best free compiler to use?

Post by Joost Buijs »

Sesse wrote: Thu Oct 04, 2018 4:03 pm Clang is a different compiler from GCC, indeed—they're entirely separate projects. But GCC is also usually somewhat faster than MSVC with comparable settings; MSVC is a very old compiler (its basic design harks back from the DOS era), and has to bend over backwards to deal with the more tricky C++ constructs. One potential pitfall when measuring is that MSBuild has horrible parallelization (it can parallelize on subproject-level only, and relies on the compiler to do the rest—with no jobserver control!), which is unlikely to play well with GCC.

As for the quality of the IDE, that is independent of the compiler (you can e.g. compile with Clang and use the Visual Studio IDE for editing). It is of course rather subjective what is a “primitive” environment or not; personally, I'm happy I don't have to work with the atrocious VS editor anymore! Or Windows, for that matter. :-)
Since a year or two VS also integrates Clang with as backend the MSVC code generator and optimizer, and I have to agree that the diagnostics output is very informative, sometimes I use it as a static analysis tool. Unfortunately several important compiler intrinsics are missing from the MS Clang implementation and I never obtained the same performance (for my chess program) with it as with the other compilers. On other platforms it uses LLVM as backend, maybe that works better, I don't know.

I started programming in C back in 1981 and C++ around 1988 with Zortech C++, and used many different compilers since. I know the history of MSVC, the first version was based on Lattice C, later MS developed their own compiler, I started using it since v4.0. Since v14.0 most parts of the compiler were totally rewritten and it also got a modern optimizer, I think it is not as bad anymore as it used to be.
Dann Corbit
Posts: 12541
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: what is the best free compiler to use?

Post by Dann Corbit »

Joost Buijs wrote: Thu Oct 04, 2018 8:33 pm {snip}

I started programming in C back in 1981 and C++ around 1988 with Zortech C++, and used many different compilers since. I know the history of MSVC, the first version was based on Lattice C, later MS developed their own compiler, I started using it since v4.0. Since v14.0 most parts of the compiler were totally rewritten and it also got a modern optimizer, I think it is not as bad anymore as it used to be.
I programmed C in the "Wild, Wild, West" days of C also.
Back in those days, they had Manx C, Aztec C, Lattice C, etc.
Every compiler had a different set of header files because there was no C standard yet.
Sometimes, you had to link in a special object for some compilers in order to create a binary.
Code became a giant mess of
#ifdef
#else
#endif
because of all the compiler differences.

Nobody on earth was more relieved than I was when the C standard was introduced.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
Sesse
Posts: 300
Joined: Mon Apr 30, 2018 11:51 pm

Re: what is the best free compiler to use?

Post by Sesse »

Joost Buijs wrote: Thu Oct 04, 2018 8:33 pm Since a year or two VS also integrates Clang with as backend the MSVC code generator and optimizer, and I have to agree that the diagnostics output is very informative, sometimes I use it as a static analysis tool.
That would be Clang/C2, which is a different project from regular Windows Clang (as you say, different codegen, and they also don't follow the same release schedule etc.—not to mention that the former is not open source).

I'm not entirely sure why anyone would want to use Clang/C2 over just Clang with LLVM. The latter is certainly available on Windows, and it's what Chrome and Firefox are using.
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: what is the best free compiler to use?

Post by Joost Buijs »

Dann Corbit wrote: Thu Oct 04, 2018 8:51 pm
Joost Buijs wrote: Thu Oct 04, 2018 8:33 pm {snip}

I started programming in C back in 1981 and C++ around 1988 with Zortech C++, and used many different compilers since. I know the history of MSVC, the first version was based on Lattice C, later MS developed their own compiler, I started using it since v4.0. Since v14.0 most parts of the compiler were totally rewritten and it also got a modern optimizer, I think it is not as bad anymore as it used to be.
I programmed C in the "Wild, Wild, West" days of C also.
Back in those days, they had Manx C, Aztec C, Lattice C, etc.
Every compiler had a different set of header files because there was no C standard yet.
Sometimes, you had to link in a special object for some compilers in order to create a binary.
Code became a giant mess of
#ifdef
#else
#endif
because of all the compiler differences.

Nobody on earth was more relieved than I was when the C standard was introduced.
The good old days! I tried every C compiler that I could lay my hands on (in the hope that it would produce faster code). Most compilers back than were not even adhering K&R. I've also been playing around with Pascal, Turbo Pascal, Delphi, and later Lazarus with Free Pascal, sometimes I still use it, but I prefer C++.
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: what is the best free compiler to use?

Post by Joost Buijs »

Sesse wrote: Fri Oct 05, 2018 12:17 am
Joost Buijs wrote: Thu Oct 04, 2018 8:33 pm Since a year or two VS also integrates Clang with as backend the MSVC code generator and optimizer, and I have to agree that the diagnostics output is very informative, sometimes I use it as a static analysis tool.
That would be Clang/C2, which is a different project from regular Windows Clang (as you say, different codegen, and they also don't follow the same release schedule etc.—not to mention that the former is not open source).

I'm not entirely sure why anyone would want to use Clang/C2 over just Clang with LLVM. The latter is certainly available on Windows, and it's what Chrome and Firefox are using.
Out of curiosity I tried this morning to integrate LLVM 7.0 into MSVC, and after some initial issues with UTF-16 coded files (which Clang doesn't seem to understand) and missing bmi/bmi2 intrinsics (I had to enable this with -mbmi and -mbmi2), I finally got it working. It compiles rather slow, but indeed the output runs somewhat faster, for the new version of my engine I'm currently working on I see a difference of 4.7%, for my old engine the difference is smaller though (1 to 2%).