Matthies / RubiChess

Another chess engine
GNU General Public License v3.0
150 stars 16 forks source link

C++20? (Not an issue but a question) #453

Open achimste opened 5 months ago

achimste commented 5 months ago

Hi!

Sorry, this is not an issue but a suggestion and I just would like to hear your opinion.

In my chess engines, I replaced all that CPU-specialised code (popcount, msb, lsb, etc) with C++20 std commands, where the compiler automatically uses the corresponding intrinsics or other codes depending on the code generation flags.

So my question is: Would you like to switch to C++20 or remain at a lower version? At least with C++20 your code would simplify (a lot?).

I downloaded your latest code and I am indeed replacing your CPU specific code with std-lib commands. I am compiling for Windows only.

Regards Achim

Matthies commented 5 months ago

Not sure if it is worth to switch to C++20 but I will give it a try. First step (and not last hopefully) will be to check if all platforms that I want to support allow switching to new standard.

Matthies commented 5 months ago

Speed comparison of master vs. 0935b7ae19ed0282925456cb2568875910b9ffce of branch c++20 on BMI2 Intel CPU running Linux.

Every version was measured three times using Stockfish perf test: sudo perf stat -r 5 -a -B -e cycles:u,instructions:u ./RubiChess bench > /dev/null

Version GCC-11.4 Clang-14.0 ICX-2023.0.0
Master 4.85s / 4.85s / 4.86s 4.84s / 4.86s / 4.86s 4.62s / 4.62s / 4.62s
c++20 4.87s / 4.88s / 4.87s 4.92s / 4.93s / 4.92s 4.66s / 4.66s / 4.67s

Seems that the compilers are not as smart as expected. Or my generic pullXsb implementation can be improved.

Matthies commented 5 months ago

After fixing pullLsb in bc22873a0d484a4adbe8773490abebacfb18f3ad this looks better now. Well, not for Clang. This testing is on AVX2 AMD Ryzen 3700x running Linux and using more recent comnpilers.

Version GCC-13.2 Clang-16.0 ICX-2023.2.0
Master 3.33s / 3.36s / 3.33s 3.36s / 3.36s / 3.35s 3.35s / 3.34s / 3.35s
c++20 3.32s / 3.32s / 3.33s 3.42s / 3.41s / 3.41s 3.33s / 3.33s / 3.34s
Matthies commented 4 months ago

456 shows the ongoing progress.