C++20 standard bit operations

Discussion of chess software programming and technical issues.

Moderators: Harvey Williamson, Dann Corbit, hgm

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
jdart
Posts: 4036
Joined: Fri Mar 10, 2006 4:23 am
Location: http://www.arasanchess.org

C++20 standard bit operations

Post by jdart » Sun Nov 15, 2020 6:21 pm

C++20 defines a standard header <bit> that contains bit primitives like popcount, leading zeros etc. (https://en.cppreference.com/w/cpp/header/bit).

This provides a way do to these things portably w/o relying on compiler intrinsics. I assume but have not verified that compilers will use hardware support for these if available.

There is also an <endian> header that detects endianness (but, as yet, provides no other related functions).

GCC-10 has support for these. Not sure about other compilers.

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

Re: C++20 standard bit operations

Post by Joost Buijs » Mon Nov 16, 2020 6:50 am

Visual Studio MSVC and CLang are having this too when using /std:c++latest. I didn't try with the Intel compiler yet.
The popcount, count and rotate instructions all seem to have hardware support, although I have the impression that there is some extra overhead.
A few months ago I replaced the bit intrinsics in my engine with std::bit and kept it in because it made the code somewhat cleaner.

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

Re: C++20 standard bit operations

Post by Joost Buijs » Mon Nov 16, 2020 8:31 am

Out of curiosity I tried with the Intel compiler, unfortunately the Visual Studio 16.8 update breaks the Intel compiler completely.

Each time it's the same sh*t with Intel, they want an arm and a leg for their software and it is never up to date. Their solution is to install a beta version of oneAPI with ICC 2021.1, but they don't tell you that it won't install without an Intel GPU.

jdart
Posts: 4036
Joined: Fri Mar 10, 2006 4:23 am
Location: http://www.arasanchess.org

Re: C++20 standard bit operations

Post by jdart » Mon Nov 16, 2020 2:21 pm

Joost Buijs wrote:
Mon Nov 16, 2020 8:31 am
Out of curiosity I tried with the Intel compiler, unfortunately the Visual Studio 16.8 update breaks the Intel compiler completely.

Each time it's the same sh*t with Intel, they want an arm and a leg for their software and it is never up to date. Their solution is to install a beta version of oneAPI with ICC 2021.1, but they don't tell you that it won't install without an Intel GPU.
I was able to install oneAPI on an HP workstation under Linux. I just got a warning about it not having graphics drivers.

--Jon

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

Re: C++20 standard bit operations

Post by Joost Buijs » Mon Nov 16, 2020 3:24 pm

jdart wrote:
Mon Nov 16, 2020 2:21 pm
Joost Buijs wrote:
Mon Nov 16, 2020 8:31 am
Out of curiosity I tried with the Intel compiler, unfortunately the Visual Studio 16.8 update breaks the Intel compiler completely.

Each time it's the same sh*t with Intel, they want an arm and a leg for their software and it is never up to date. Their solution is to install a beta version of oneAPI with ICC 2021.1, but they don't tell you that it won't install without an Intel GPU.
I was able to install oneAPI on an HP workstation under Linux. I just got a warning about it not having graphics drivers.

--Jon
Under Windows the installation refuses to continue when it does not see the Intel graphics drivers installed.
In this way they force you to buy an Intel CPU with embedded graphics or to buy one of these (non existent) Intel XE GPUs.

I removed the Intel compiler completely, performance wise CLang is just as good, the difference is very small.
Hopefully there will be a version next year that can be used without Intel graphics hardware.

Ras
Posts: 1620
Joined: Tue Aug 30, 2016 6:19 pm
Full name: Rasmus Althoff
Contact:

Re: C++20 standard bit operations

Post by Ras » Mon Nov 16, 2020 5:03 pm

Intel's compiler isn't trustworthy anyway. It used to insert slow code paths in application binaries that would be taken on an AMD CPU even when that had the necessary features.
Rasmus Althoff
https://www.ct800.net

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

Re: C++20 standard bit operations

Post by Joost Buijs » Mon Nov 16, 2020 6:25 pm

Ras wrote:
Mon Nov 16, 2020 5:03 pm
Intel's compiler isn't trustworthy anyway. It used to insert slow code paths in application binaries that would be taken on an AMD CPU even when that had the necessary features.
This is true but I didn't care since I never used AMD CPUs the last 10 years, for my i9-10980XE ICC is still the best compiler.

Recently I bought an AMD 3970X and Intel binaries now refuse to run if you add more optimization than the bare minimum. For the 3970X CLang is the best compiler with -mO3 and -march=native or -mavx2. I never tried GCC though.

For GCC I would need MinGW64 or MSYS2, Visual Studio is so advanced in comparison with Linux development tools that I don't feel the slightest need to take a look at these.

Post Reply