-gen clang

General FreeBASIC programming questions.
Arachnophilia
Posts: 25
Joined: Sep 04, 2015 13:33

Re: -gen clang

Post by Arachnophilia »

srvaldez wrote: Mar 17, 2024 15:48 for anyone on Windows wanting to try FB with clang, I suggest the following
download and extract FreeBASIC-1.10.1-winlibs-gcc-9.3.0.7z from viewtopic.php?t=32498
delete fbc32.exe and fbc64.exe
download the latest build of fbc windows from https://users.freebasic-portal.de/stw/builds/
extract fbc_win32_mingw into the FreeBASIC-1.10.1-winlibs-gcc-9.3.0 folder and rename fbc.exe to fbc32.exe
extract fbc_win64_mingw into the FreeBASIC-1.10.1-winlibs-gcc-9.3.0 folder and rename fbc.exe to fbc64.exe
download llvm-mingw-20240308-msvcrt-i686.zip and llvm-mingw-20240308-msvcrt-x86_64.zip from https://github.com/mstorsjo/llvm-mingw/releases
copy the folowing files from the llvm-mingw bin folder to the respective bin\winXX folder
clang-18.exe
clang.exe
libc++.dll
libclang-cpp.dll
libLLVM.dll
libunwind.dll

that's it
Hello srvaldez
thank you very much for your information and sharing your knowledge.
Following your instructions, I now have a working compiler environment where Clang works with existing source code. :D
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: -gen clang

Post by UEZ »

I'm getting always warnings when compiling with clang. Is it normal?

And yes, the code seems to be running faster than using the built-in compiler.
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -gen clang

Post by deltarho[1859] »

Using srvaldez's instructions, I did a gcc 8.1.0/clang. I always liked gcc 8.3.0.

Applying to various code, there was very little difference 8.1.0 vs 9.3.0 performance wise 32-bit or 64-bit.

The 9.3.0 binaries were significantly smaller, which surprised me.

9.3.0/clang seems to be the better, but it was worth looking at 8.1.0/clang; saved others looking at it if nothing else. :)
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -gen clang

Post by deltarho[1859] »

Some surprises here.

With my 500MiB hash program there was no appreciable difference performance wise between 32-bit and 64-bit using either gcc 9.3 clang or gcc 11.2 clang. clang was about 7% faster in all cases compared with gcc. However it is worth noting that we are using a Microsoft API.

With my plot program comparing PRNG's we have a different story. Opt -O2 used.

With 32-bit the gcc figures were mostly the same for 9.3 and 11.2. This has been my experience in the past - later gcc versions did nothing for performance. With clang 11.2 was faster than 11.2 gcc but not by much. clang 9.3 did poorly compared with gcc 9.3. It would seem that clang favours later versions of gcc whereas gcc does not, as far as fbc is concerned.

With 64-bit clang stomped all over gcc by a whopping 40% for 11.2 and 9.3 clang. 11.2 clang was faster than 9.3 clang.

So for the plot program, a 64-bit 11.2 clang turned out to be a scorcher. We have a gcc 11.2.0 here towards the bottom of the page.

I haven't done a lot of testing and the plot program may be a special case or rather PRNG's may be a special case. My Encrypternet application isn't benefitting from a clang build, but that is wall-to-wall Microsoft cryptographic APIs.

I double-checked the 64-bit 11.2 gcc and 11.2 gcc/clang figures because I couldn't believe what I was looking at.

A gcc 11.2.0 vs gcc 9.3.0 isn't worth looking at but a gcc 11.2.0/clang vs gcc 9.3.0 certainly is.

I have never been a 64-bit fan, but how do we ignore 40%.

Code: Select all

#define Clang ' For fbc 1.20.0 or later
#ifdef Clang
  #cmdline "-asm att -s console -w all -fpmode fast -fpu sse -arch native -gen clang -Wc -O2"
#else
  #cmdline "-s console -w all -fpmode fast -fpu sse -gen gcc -Wc -O2"
#endif
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -gen clang

Post by deltarho[1859] »

On further tests, a gcc 11.2/clang is not much faster than gcc 9.3/clang using 64-bit. It is worth it for 32-bit with gcc 11.2/clang being about 4% faster than gcc 11.2. 32-bit gcc 9.3/clang is deplorable compared with gcc 9.3. I have no idea why. That is with my plot program.

On balance, there is a good case for gcc 11.2/clang, but we should not treat that as a default. There will be many cases where gcc outperforms. On release, we will have to compare gcc with gcc/clang. Fortunately, there is not much effort to doing that.
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -gen clang

Post by deltarho[1859] »

This where I have ended up:

Code: Select all

            32-bit     64-bit
gcc          9.3        9.3
gcc/clang 11.2/clang 11.2/clang
It also keeps life simple by just having two toolchains.

Performance wise, it is anyone's guess who wins: gcc 9.3 or gcc 11.2/clang.

:)
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: -gen clang

Post by srvaldez »

hi deltarho[1859]
interesting results, I take it that you were able to compile Encrypternet with clang?
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -gen clang

Post by deltarho[1859] »

srvaldez wrote:I take it that you were able to compile Encrypternet with clang?
Three posts back: “My Encrypternet application isn't benefitting from a clang build, but that is wall-to-wall Microsoft cryptographic APIs.”

At over 140MiB per second, the only thing which can improve on that is a more powerful CPU. :)
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -gen clang

Post by deltarho[1859] »

Regarding srvaldez's instructions.

The llvm downloads are now 20240320 from 20240308 updated three days ago. The libLLVM.dll is now libLLVM-18.dll.

My HASH program is now 2% faster than the previous clang using gcc 11.2.0/clang so we are pulling away further from gcc 9.3.

My PRNG plot program looking at MsWsII and clang is also 2% faster than the previous clang..

2% is no big deal, but better than being slower. :)

We are now bang up to date with llvm and fbc 1.20.0 (no change there)

To save you the trouble, here is the updated toolchain (162MiB zipped).

I will leave it for a while unless llvm gets updated, or we get a fbc 1.20.0 release.

FreeBASIC-1.20.0-gcc-11.2.0cl
coderJeff
Site Admin
Posts: 4323
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: -gen clang

Post by coderJeff »

Thank you srvaldez & deltarho
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -gen clang

Post by deltarho[1859] »

:wink:
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -gen clang

Post by deltarho[1859] »

Unless I am mistaken, it looks like the compile time for the new gcc 11.2.0/clang is about half of what it was. It still takes longer than gcc, but for a lot of code published on the forum the difference may not be that noticeable. It is still worthwhile to develop in gas because that gives blisteringly fast compilations.

There are quite a few volunteer authors involved in LLVM.

The next release is due on 2 April 2024. Releases tend to be more frequent than gcc.
antarman
Posts: 81
Joined: Jun 12, 2006 9:27
Location: Russia, Krasnodar

Re: -gen clang

Post by antarman »

deltarho[1859] thanx you for work! my prog render ~5200 fps instead ~4500 fps. great work!
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -gen clang

Post by deltarho[1859] »

Blimey — feedback! I need a lie down. :D

Thank you, antarman.

srvaldez should get the credit. He supplied the engine — I just did the coachwork. :)
deltarho[1859]
Posts: 4305
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: -gen clang

Post by deltarho[1859] »

fbc 1.20.0 [2 April 2024] LLVM 18.1.3 [5 April 2024]

FreeBASIC-1.20.0-gcc-11.2.0cl (162MiB)

I have tried to find a 'changelog' for LLVM 18.1.3, but I cannot find one.
Post Reply